src, examples: Check return value

This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-07 00:26:00 +09:00
parent 40e8eaf5fd
commit 8bfd900be5
2 changed files with 12 additions and 5 deletions

View File

@ -152,7 +152,7 @@ static ssize_t send_callback(nghttp2_session *session _U_, const uint8_t *data,
connection->want_io = IO_NONE;
ERR_clear_error();
rv = SSL_write(connection->ssl, data, (int)length);
if (rv < 0) {
if (rv <= 0) {
int err = SSL_get_error(connection->ssl, rv);
if (err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) {
connection->want_io =
@ -529,8 +529,12 @@ static void fetch_uri(const struct URI *uri) {
connection.want_io = IO_NONE;
/* Send connection header in blocking I/O mode */
SSL_write(ssl, NGHTTP2_CLIENT_CONNECTION_PREFACE,
rv = SSL_write(ssl, NGHTTP2_CLIENT_CONNECTION_PREFACE,
NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN);
if (rv <= 0) {
dief("SSL_write failed: could not send connection preface",
ERR_error_string(ERR_get_error(), NULL));
}
/* Here make file descriptor non-block */
make_non_block(fd);

View File

@ -1470,7 +1470,7 @@ int start_listen(struct ev_loop *loop, Sessions *sessions,
close(fd);
continue;
}
util::make_socket_nonblocking(fd);
(void)util::make_socket_nonblocking(fd);
#ifdef IPV6_V6ONLY
if (rp->ai_family == AF_INET6) {
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &val,
@ -1547,7 +1547,10 @@ int HttpServer::run() {
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_AUTO_RETRY);
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_RELEASE_BUFFERS);
SSL_CTX_set_cipher_list(ssl_ctx, ssl::DEFAULT_CIPHER_LIST);
if (SSL_CTX_set_cipher_list(ssl_ctx, ssl::DEFAULT_CIPHER_LIST) == 0) {
std::cerr << ERR_error_string(ERR_get_error(), nullptr) << std::endl;
return -1;
}
const unsigned char sid_ctx[] = "nghttpd";
SSL_CTX_set_session_id_context(ssl_ctx, sid_ctx, sizeof(sid_ctx) - 1);