libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 58b30e7e5e90ff87ef932ea4e47efe16e2609188
parent 07b65da99f9ff0e6335bb573f5e915ed39d8ae25
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun,  2 Aug 2015 17:11:48 +0000

fix #3926: ignore close() errors other than EBADF

Diffstat:
MChangeLog | 4++++
Msrc/examples/demo.c | 2+-
Msrc/examples/mhd2spdy_spdy.c | 200++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/include/microhttpd.h | 2+-
Msrc/include/platform_interface.h | 22++++++++++++++++------
Msrc/microspdy/daemon.c | 92++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/microspdy/internal.h | 5+++--
Msrc/microspdy/session.c | 4++--
Msrc/testcurl/https/test_https_time_out.c | 12++++++------
Msrc/testcurl/https/test_tls_extensions.c | 6+++---
Msrc/testspdy/test_new_connection.c | 13++++++++-----
Msrc/testspdy/test_notls.c | 4++--
Msrc/testspdy/test_request_response.c | 6+++---
13 files changed, 195 insertions(+), 177 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +Sun Aug 2 19:08:20 CEST 2015 + Ignore close() errors on sockets except for EBADF, + fixes #3926. -CG + Sat Jun 27 22:16:27 CEST 2015 Make sure to decrement connection counter before calling connection notifier so that diff --git a/src/examples/demo.c b/src/examples/demo.c @@ -574,7 +574,7 @@ process_upload_data (void *cls, uc->filename, strerror (errno)); uc->response = internal_error_response; - close (uc->fd); + (void) close (uc->fd); uc->fd = -1; if (NULL != uc->filename) { diff --git a/src/examples/mhd2spdy_spdy.c b/src/examples/mhd2spdy_spdy.c @@ -69,20 +69,20 @@ spdy_cb_data_source_read(spdylay_session *session, int32_t stream_id, uint8_t *b (void)session; (void)stream_id; (void)user_data; - + ssize_t ret; assert(NULL != source); assert(NULL != source->ptr); struct Proxy *proxy = (struct Proxy *)(source->ptr); void *newbody; - - + + if(length < 1) { PRINT_INFO("spdy_cb_data_source_read: length is 0"); return 0; } - + if(!proxy->received_body_size)//nothing to write now { if(proxy->receiving_done) @@ -93,7 +93,7 @@ spdy_cb_data_source_read(spdylay_session *session, int32_t stream_id, uint8_t *b PRINT_INFO("POST SPDYLAY_ERR_DEFERRED"); return SPDYLAY_ERR_DEFERRED;//TODO SPDYLAY_ERR_DEFERRED should be used } - + if(length >= proxy->received_body_size) { ret = proxy->received_body_size; @@ -113,15 +113,15 @@ spdy_cb_data_source_read(spdylay_session *session, int32_t stream_id, uint8_t *b free(proxy->received_body); proxy->received_body = newbody; proxy->received_body_size -= ret; - + if(0 == proxy->received_body_size && proxy->receiving_done) { PRINT_INFO("POST spdy EOF"); *eof = 1; } - + PRINT_INFO2("given POST bytes to spdylay: %zd", ret); - + return ret; } @@ -141,13 +141,13 @@ spdy_cb_send(spdylay_session *session, { (void)session; (void)flags; - + //PRINT_INFO("spdy_cb_send called"); struct SPDY_Connection *connection; ssize_t rv; connection = (struct SPDY_Connection*)user_data; connection->want_io = IO_NONE; - + if(glob_opt.ignore_rst_stream && 16 == length && 0x80 == data[0] @@ -160,7 +160,7 @@ spdy_cb_send(spdylay_session *session, return 16; } glob_opt.ignore_rst_stream = false; - + if(connection->is_tls) { ERR_clear_error(); @@ -178,14 +178,14 @@ spdy_cb_send(spdylay_session *session, } else { - rv = write(connection->fd, + rv = write(connection->fd, data, length); - + if (rv < 0) { switch(errno) - { + { case EAGAIN: #if EAGAIN != EWOULDBLOCK case EWOULDBLOCK: @@ -193,18 +193,18 @@ spdy_cb_send(spdylay_session *session, connection->want_io |= WANT_WRITE; rv = SPDYLAY_ERR_WOULDBLOCK; break; - + default: rv = SPDYLAY_ERR_CALLBACK_FAILURE; } } } - + PRINT_INFO2("%zd bytes written by spdy", rv); - + if(rv > 0) UPDATE_STAT(glob_stat.spdy_bytes_sent, rv); - + return rv; } @@ -218,16 +218,16 @@ spdy_cb_send(spdylay_session *session, static ssize_t spdy_cb_recv(spdylay_session *session, uint8_t *buf, - size_t length, + size_t length, int flags, void *user_data) { (void)session; (void)flags; - + struct SPDY_Connection *connection; ssize_t rv; - + connection = (struct SPDY_Connection*)user_data; //prevent monopolizing everything if(!(++connection->counter % 10)) return SPDYLAY_ERR_WOULDBLOCK; @@ -251,14 +251,14 @@ spdy_cb_recv(spdylay_session *session, } else { - rv = read(connection->fd, + rv = read(connection->fd, buf, length); - + if (rv < 0) { switch(errno) - { + { case EAGAIN: #if EAGAIN != EWOULDBLOCK case EWOULDBLOCK: @@ -266,7 +266,7 @@ spdy_cb_recv(spdylay_session *session, connection->want_io |= WANT_READ; rv = SPDYLAY_ERR_WOULDBLOCK; break; - + default: rv = SPDYLAY_ERR_CALLBACK_FAILURE; } @@ -274,10 +274,10 @@ spdy_cb_recv(spdylay_session *session, else if(rv == 0) rv = SPDYLAY_ERR_EOF; } - + if(rv > 0) UPDATE_STAT(glob_stat.spdy_bytes_received, rv); - + return rv; } @@ -289,10 +289,10 @@ spdy_cb_before_ctrl_send(spdylay_session *session, void *user_data) { (void)user_data; - + int32_t stream_id; struct Proxy *proxy; - + switch(type) { case SPDYLAY_SYN_STREAM: stream_id = frame->syn_stream.stream_id; @@ -324,7 +324,7 @@ spdy_cb_on_ctrl_recv(spdylay_session *session, void *user_data) { (void)user_data; - + char **nv; int32_t stream_id; struct Proxy * proxy; @@ -371,7 +371,7 @@ spdy_cb_on_ctrl_recv(spdylay_session *session, return; break; } - + glob_opt.spdy_data_received = true; } @@ -390,16 +390,16 @@ spdy_cb_on_stream_close(spdylay_session *session, { (void)status_code; (void)user_data; - + struct Proxy * proxy = spdylay_session_get_stream_user_data(session, stream_id); - + assert(NULL != proxy); - + --glob_opt.streams_opened; --proxy->spdy_connection->streams_opened; PRINT_INFO2("closing stream: str opened %i; remove proxy %i", glob_opt.streams_opened, proxy->id); - - DLL_remove(proxy->spdy_connection->proxies_head, proxy->spdy_connection->proxies_tail, proxy); + + DLL_remove(proxy->spdy_connection->proxies_head, proxy->spdy_connection->proxies_tail, proxy); if(proxy->http_active) { proxy->spdy_active = false; @@ -425,16 +425,16 @@ spdy_cb_on_data_chunk_recv(spdylay_session *session, { (void)flags; (void)user_data; - + struct Proxy *proxy; proxy = spdylay_session_get_stream_user_data(session, stream_id); - + if(NULL == proxy) { PRINT_INFO("proxy in spdy_cb_on_data_chunk_recv is NULL)"); return; } - + if(!copy_buffer(data, len, &proxy->http_body, &proxy->http_body_size)) { //TODO handle it better? @@ -469,7 +469,7 @@ spdy_cb_on_data_recv(spdylay_session *session, { (void)length; (void)user_data; - + if(flags & SPDYLAY_DATA_FLAG_FIN) { struct Proxy *proxy; @@ -514,10 +514,10 @@ spdy_cb_ssl_select_next_proto(SSL* ssl, void *arg) { (void)ssl; - + int rv; uint16_t *spdy_proto_version; - + /* spdylay_select_next_protocol() selects SPDY protocol version the Spdylay library supports. */ rv = spdylay_select_next_protocol(out, outlen, in, inlen); @@ -554,7 +554,7 @@ spdy_ssl_handshake(SSL *ssl, int fd) { int rv; - + if(SSL_set_fd(ssl, fd) == 0) spdy_dief("SSL_set_fd", ERR_error_string(ERR_get_error(), NULL)); @@ -562,7 +562,7 @@ spdy_ssl_handshake(SSL *ssl, rv = SSL_connect(ssl); if(rv <= 0) PRINT_INFO2("SSL_connect %s", ERR_error_string(ERR_get_error(), NULL)); - + return rv; } @@ -580,7 +580,7 @@ spdy_socket_connect_to(const char *host, int rv; char service[NI_MAXSERV]; struct addrinfo *res, *rp; - + //TODO checks snprintf(service, sizeof(service), "%u", port); memset(&hints, 0, sizeof(struct addrinfo)); @@ -601,11 +601,11 @@ spdy_socket_connect_to(const char *host, errno == EINTR); if(rv == 0) break; - close(fd); + MHD_socket_close_ (fd); fd = -1; } freeaddrinfo(res); - + return fd; } @@ -615,14 +615,14 @@ spdy_socket_make_non_block(int fd) { int flags; int rv; - + while((flags = fcntl(fd, F_GETFL, 0)) == -1 && errno == EINTR); - + if(flags == -1) spdy_dief("fcntl", strerror(errno)); - + while((rv = fcntl(fd, F_SETFL, flags | O_NONBLOCK)) == -1 && errno == EINTR); - + if(rv == -1) spdy_dief("fcntl", strerror(errno)); } @@ -636,7 +636,7 @@ spdy_socket_set_tcp_nodelay(int fd) { int val = 1; int rv; - + rv = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, (socklen_t)sizeof(val)); if(rv == -1) spdy_dief("setsockopt", strerror(errno)); @@ -669,14 +669,14 @@ spdy_ctl_poll(struct pollfd *pollfd, */ bool spdy_ctl_select(fd_set * read_fd_set, - fd_set * write_fd_set, + fd_set * write_fd_set, fd_set * except_fd_set, struct SPDY_Connection *connection) { (void)except_fd_set; - + bool ret = false; - + if(spdylay_session_want_read(connection->session) || connection->want_io & WANT_READ) { @@ -689,7 +689,7 @@ spdy_ctl_select(fd_set * read_fd_set, FD_SET(connection->fd, write_fd_set); ret = true; } - + return ret; } @@ -701,7 +701,7 @@ int spdy_exec_io(struct SPDY_Connection *connection) { int rv; - + rv = spdylay_session_recv(connection->session); if(rv != 0) { @@ -711,7 +711,7 @@ spdy_exec_io(struct SPDY_Connection *connection) rv = spdylay_session_send(connection->session); if(rv != 0) PRINT_INFO2("spdylay_session_send %i", rv); - + return rv; } @@ -740,14 +740,14 @@ spdy_connect(const struct URI *uri, PRINT_INFO("Could not open file descriptor"); return NULL; } - + if(is_tls) { ssl = SSL_new(glob_opt.ssl_ctx); if(ssl == NULL) { spdy_dief("SSL_new", ERR_error_string(ERR_get_error(), NULL)); } - + //TODO non-blocking /* To simplify the program, we perform SSL/TLS handshake in blocking I/O. */ @@ -767,7 +767,7 @@ spdy_connect(const struct URI *uri, if(NULL == (connection = au_malloc(sizeof(struct SPDY_Connection)))) goto free_and_fail; - + connection->is_tls = is_tls; connection->ssl = ssl; connection->want_io = IO_NONE; @@ -784,11 +784,11 @@ spdy_connect(const struct URI *uri, if(rv != 0) { spdy_diec("spdylay_session_client_new", rv); } - + connection->fd = fd; return connection; - + //for GOTO free_and_fail: if(NULL != connection) @@ -796,15 +796,15 @@ spdy_connect(const struct URI *uri, free(connection->host); free(connection); } - + if(is_tls) SSL_shutdown(ssl); - - close(fd); - + + MHD_socket_close_ (fd); + if(is_tls) SSL_free(ssl); - + return NULL; } @@ -814,7 +814,7 @@ spdy_free_connection(struct SPDY_Connection * connection) { struct Proxy *proxy; struct Proxy *proxy_next; - + if(NULL != connection) { for(proxy = connection->proxies_head; NULL != proxy; proxy=proxy_next) @@ -847,7 +847,7 @@ spdy_request(const char **nv, uint16_t port; struct SPDY_Connection *connection; spdylay_data_provider post_data; - + if(glob_opt.only_proxy) { connection = glob_opt.spdy_connection; @@ -861,7 +861,7 @@ spdy_request(const char **nv, break; connection = connection->next; } - + if(NULL == connection) { //connect to host @@ -877,13 +877,13 @@ spdy_request(const char **nv, connection = glob_opt.spdy_connection; } } - + if(NULL == connection) { PRINT_INFO("there is no proxy!"); return -1; } - + proxy->spdy_connection = connection; if(with_body) { @@ -893,7 +893,7 @@ spdy_request(const char **nv, } else ret = spdylay_submit_request(connection->session, 0, nv, NULL, proxy); - + if(ret != 0) { spdy_diec("spdylay_spdy_submit_request", ret); } @@ -901,7 +901,7 @@ spdy_request(const char **nv, if(NULL != connection->proxies_head) PRINT_INFO2("before proxy %i", connection->proxies_head->id); DLL_insert(connection->proxies_head, connection->proxies_tail, proxy); - + return ret; } @@ -914,11 +914,11 @@ spdy_get_pollfdset(struct pollfd fds[], { struct SPDY_Connection *connection; struct Proxy *proxy; - + *real_size = 0; if(max_size<1) return; - + if(NULL != glob_opt.spdy_connection) { spdy_ctl_poll(&(fds[*real_size]), glob_opt.spdy_connection); @@ -926,7 +926,7 @@ spdy_get_pollfdset(struct pollfd fds[], { //PRINT_INFO("TODO drop connection"); glob_opt.streams_opened -= glob_opt.spdy_connection->streams_opened; - + for(proxy = glob_opt.spdy_connection->proxies_head; NULL != proxy; proxy=proxy->next) { abort(); @@ -943,9 +943,9 @@ spdy_get_pollfdset(struct pollfd fds[], ++(*real_size); } } - + connection = glob_opt.spdy_connections_head; - + while(NULL != connection && *real_size < max_size) { assert(!glob_opt.only_proxy); @@ -956,7 +956,7 @@ spdy_get_pollfdset(struct pollfd fds[], glob_opt.streams_opened -= connection->streams_opened; DLL_remove(glob_opt.spdy_connections_head, glob_opt.spdy_connections_tail, connection); glob_opt.total_spdy_connections--; - + for(proxy = connection->proxies_head; NULL != proxy; proxy=proxy->next) { abort(); @@ -973,7 +973,7 @@ spdy_get_pollfdset(struct pollfd fds[], } connection = connection->next; } - + //, "TODO max num of conn reached; close something" assert(NULL == connection); } @@ -981,7 +981,7 @@ spdy_get_pollfdset(struct pollfd fds[], int spdy_get_selectfdset(fd_set * read_fd_set, - fd_set * write_fd_set, + fd_set * write_fd_set, fd_set * except_fd_set, struct SPDY_Connection *connections[], unsigned int max_size, @@ -991,20 +991,20 @@ spdy_get_selectfdset(fd_set * read_fd_set, struct SPDY_Connection *next_connection; bool ret; int maxfd = 0; - + *real_size = 0; if(max_size<1) return 0; - + if(NULL != glob_opt.spdy_connection) { ret = spdy_ctl_select(read_fd_set, - write_fd_set, + write_fd_set, except_fd_set, glob_opt.spdy_connection); if(!ret) { glob_opt.streams_opened -= glob_opt.spdy_connection->streams_opened; - + PRINT_INFO("spdy_free_connection in spdy_get_selectfdset"); spdy_free_connection(glob_opt.spdy_connection); glob_opt.spdy_connection = NULL; @@ -1016,23 +1016,23 @@ spdy_get_selectfdset(fd_set * read_fd_set, if(maxfd < glob_opt.spdy_connection->fd) maxfd = glob_opt.spdy_connection->fd; } } - + connection = glob_opt.spdy_connections_head; - + while(NULL != connection && *real_size < max_size) { assert(!glob_opt.only_proxy); ret = spdy_ctl_select(read_fd_set, - write_fd_set, + write_fd_set, except_fd_set, connection); - + next_connection = connection->next; if(!ret) { glob_opt.streams_opened -= connection->streams_opened; DLL_remove(glob_opt.spdy_connections_head, glob_opt.spdy_connections_tail, connection); glob_opt.total_spdy_connections--; - + PRINT_INFO("spdy_free_connection in spdy_get_selectfdset"); spdy_free_connection(connection); } @@ -1044,10 +1044,10 @@ spdy_get_selectfdset(fd_set * read_fd_set, } connection = next_connection; } - + //, "TODO max num of conn reached; close something" assert(NULL == connection); - + return maxfd; } @@ -1060,7 +1060,7 @@ spdy_run(struct pollfd fds[], int i; int ret; struct Proxy *proxy; - + for(i=0; i<size; ++i) { // PRINT_INFO2("exec about to be called for %s", connections[i]->host); @@ -1070,10 +1070,10 @@ spdy_run(struct pollfd fds[], //PRINT_INFO2("%i",ret); //if((spdy_pollfds[i].revents & POLLHUP) || (spdy_pollfds[0].revents & POLLERR)) // PRINT_INFO("SPDY SPDY_Connection error"); - + //TODO POLLRDHUP // always close on ret != 0? - + if(0 != ret) { glob_opt.streams_opened -= connections[i]->streams_opened; @@ -1106,14 +1106,14 @@ spdy_run(struct pollfd fds[], void spdy_run_select(fd_set * read_fd_set, - fd_set * write_fd_set, + fd_set * write_fd_set, fd_set * except_fd_set, struct SPDY_Connection *connections[], int size) { int i; int ret; - + for(i=0; i<size; ++i) { // PRINT_INFO2("exec about to be called for %s", connections[i]->host); @@ -1121,7 +1121,7 @@ spdy_run_select(fd_set * read_fd_set, { //raise(SIGINT); ret = spdy_exec_io(connections[i]); - + if(0 != ret) { glob_opt.streams_opened -= connections[i]->streams_opened; diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -130,7 +130,7 @@ typedef intptr_t ssize_t; * Current version of the library. * 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00094206 +#define MHD_VERSION 0x00094207 /** * MHD-internal return code for "YES". diff --git a/src/include/platform_interface.h b/src/include/platform_interface.h @@ -31,8 +31,8 @@ #include "w32functions.h" #endif -/* ***************************** - General function mapping +/* ***************************** + General function mapping *****************************/ #if !defined(_WIN32) || defined(__CYGWIN__) /** @@ -80,15 +80,25 @@ #endif - -/* MHD_socket_close_(fd) close any FDs (non-W32) / close only socket FDs (W32) */ +/** + * MHD_socket_close_(fd) close any FDs (non-W32) / close only socket + * FDs (W32). Note that on HP-UNIX, this function may leak the FD if + * errno is set to EINTR. Do not use HP-UNIX. + * + * @param fd descriptor to close + * @return 0 on success (error codes like EINTR and EIO are counted as success, + * only EBADF counts as an error!) + */ #if !defined(MHD_WINSOCK_SOCKETS) -#define MHD_socket_close_(fd) close((fd)) +#define MHD_socket_close_(fd) (((0 != close(fd)) && (EBADF == errno)) ? -1 : 0) #else #define MHD_socket_close_(fd) closesocket((fd)) #endif -/* MHD_socket_errno_ is errno of last function (non-W32) / errno of last socket function (W32) */ +/** + * MHD_socket_errno_ is errno of last function (non-W32) / errno of + * last socket function (W32) + */ #if !defined(MHD_WINSOCK_SOCKETS) #define MHD_socket_errno_ errno #else diff --git a/src/microspdy/daemon.c b/src/microspdy/daemon.c @@ -21,7 +21,7 @@ * @brief daemon functionality * @author Andrey Uzunov */ - + #include "platform.h" #include "structures.h" #include "internal.h" @@ -38,7 +38,7 @@ * @param line line number with the problem * @param reason error message with details */ -static void +static void spdyf_panic_std (void *cls, const char *file, unsigned int line, @@ -74,13 +74,13 @@ static void spdyf_cleanup_sessions (struct SPDY_Daemon *daemon) { struct SPDY_Session *session; - + while (NULL != (session = daemon->cleanup_head)) { DLL_remove (daemon->cleanup_head, daemon->cleanup_tail, session); - + SPDYF_session_destroy(session); } } @@ -95,23 +95,23 @@ static void spdyf_close_all_sessions (struct SPDY_Daemon *daemon) { struct SPDY_Session *session; - + while (NULL != (session = daemon->sessions_head)) - { + { //prepare GOAWAY frame SPDYF_prepare_goaway(session, SPDY_GOAWAY_STATUS_OK, true); //try to send the frame (it is best effort, so it will maybe sent) SPDYF_session_write(session,true); SPDYF_session_close(session); } - + spdyf_cleanup_sessions(daemon); } /** * Parse a list of options given as varargs. - * + * * @param daemon the daemon to initialize * @param valist the options * @return SPDY_YES on success, SPDY_NO on error @@ -130,7 +130,7 @@ spdyf_parse_options_va (struct SPDY_Daemon *daemon, return SPDY_NO; } daemon->options |= opt; - + switch (opt) { case SPDY_DAEMON_OPTION_SESSION_TIMEOUT: @@ -157,7 +157,7 @@ spdyf_parse_options_va (struct SPDY_Daemon *daemon, } -void +void SPDY_set_panic_func (SPDY_PanicCallback cb, void *cls) { @@ -204,10 +204,10 @@ SPDYF_start_daemon_va (uint16_t port, SPDYF_DEBUG("parse"); goto free_and_fail; } - + if(0 == daemon->max_num_frames) daemon->max_num_frames = SPDYF_NUM_SENT_FRAMES_AT_ONCE; - + if(!port && NULL == daemon->address) { SPDYF_DEBUG("Port is 0"); @@ -215,10 +215,10 @@ SPDYF_start_daemon_va (uint16_t port, } if(0 == daemon->io_subsystem) daemon->io_subsystem = SPDY_IO_SUBSYSTEM_OPENSSL; - + if(SPDY_YES != SPDYF_io_set_daemon(daemon, daemon->io_subsystem)) goto free_and_fail; - + if(SPDY_IO_SUBSYSTEM_RAW != daemon->io_subsystem) { if (NULL == certfile @@ -234,7 +234,7 @@ SPDYF_start_daemon_va (uint16_t port, goto free_and_fail; } } - + daemon->new_session_cb = nscb; daemon->session_closed_cb = sccb; daemon->new_request_cb = nrcb; @@ -252,11 +252,11 @@ SPDYF_start_daemon_va (uint16_t port, SPDYF_DEBUG("SPDY_DAEMON_FLAG_ONLY_IPV6 set but IPv4 address provided"); goto free_and_fail; } - + addrlen = sizeof (struct sockaddr_in6); - + if(NULL == daemon->address) - { + { if (NULL == (servaddr6 = malloc (addrlen))) { SPDYF_DEBUG("malloc"); @@ -268,7 +268,7 @@ SPDYF_start_daemon_va (uint16_t port, servaddr6->sin6_port = htons (port); daemon->address = (struct sockaddr *) servaddr6; } - + if(AF_INET6 == daemon->address->sa_family) { afamily = PF_INET6; @@ -284,11 +284,11 @@ SPDYF_start_daemon_va (uint16_t port, SPDYF_DEBUG("SPDY_DAEMON_FLAG_ONLY_IPV6 set but no support"); goto free_and_fail; } - + addrlen = sizeof (struct sockaddr_in); - + if(NULL == daemon->address) - { + { if (NULL == (servaddr4 = malloc (addrlen))) { SPDYF_DEBUG("malloc"); @@ -300,9 +300,9 @@ SPDYF_start_daemon_va (uint16_t port, servaddr4->sin_port = htons (port); daemon->address = (struct sockaddr *) servaddr4; } - + afamily = PF_INET; -#endif +#endif daemon->socket_fd = socket (afamily, SOCK_STREAM, 0); if (-1 == daemon->socket_fd) @@ -317,7 +317,7 @@ SPDYF_start_daemon_va (uint16_t port, { SPDYF_DEBUG("WARNING: SO_REUSEADDR was not set for the server"); } - + #if HAVE_INET6 if(daemon->flags & SPDY_DAEMON_FLAG_ONLY_IPV6) { @@ -329,7 +329,7 @@ SPDYF_start_daemon_va (uint16_t port, } } #endif - + if (-1 == bind (daemon->socket_fd, daemon->address, addrlen)) { SPDYF_DEBUG("bind %i",errno); @@ -353,8 +353,8 @@ SPDYF_start_daemon_va (uint16_t port, //for GOTO free_and_fail: if(daemon->socket_fd > 0) - (void)close (daemon->socket_fd); - + (void)MHD_socket_close_ (daemon->socket_fd); + free(servaddr4); #if HAVE_INET6 free(servaddr6); @@ -364,39 +364,39 @@ SPDYF_start_daemon_va (uint16_t port, if(NULL != daemon->keyfile) free(daemon->keyfile); free (daemon); - + return NULL; } -void +void SPDYF_stop_daemon (struct SPDY_Daemon *daemon) { daemon->fio_deinit(daemon); - + shutdown (daemon->socket_fd, SHUT_RDWR); spdyf_close_all_sessions (daemon); - (void)close (daemon->socket_fd); - + (void)MHD_socket_close_ (daemon->socket_fd); + if(!(SPDY_DAEMON_OPTION_SOCK_ADDR & daemon->options)) free(daemon->address); - + free(daemon->certfile); free(daemon->keyfile); - + free(daemon); } int -SPDYF_get_timeout (struct SPDY_Daemon *daemon, +SPDYF_get_timeout (struct SPDY_Daemon *daemon, unsigned long long *timeout) { unsigned long long earliest_deadline = 0; unsigned long long now; struct SPDY_Session *pos; bool have_timeout; - + if(0 == daemon->session_timeout) return SPDY_NO; @@ -409,21 +409,21 @@ SPDYF_get_timeout (struct SPDY_Daemon *daemon, earliest_deadline = pos->last_activity + daemon->session_timeout; have_timeout = true; - + if (SPDY_YES == pos->fio_is_pending(pos)) { earliest_deadline = 0; break; } } - + if (!have_timeout) return SPDY_NO; if (earliest_deadline <= now) *timeout = 0; else *timeout = earliest_deadline - now; - + return SPDY_YES; } @@ -431,7 +431,7 @@ SPDYF_get_timeout (struct SPDY_Daemon *daemon, int SPDYF_get_fdset (struct SPDY_Daemon *daemon, fd_set *read_fd_set, - fd_set *write_fd_set, + fd_set *write_fd_set, fd_set *except_fd_set, bool all) { @@ -470,7 +470,7 @@ SPDYF_get_fdset (struct SPDY_Daemon *daemon, } -void +void SPDYF_run (struct SPDY_Daemon *daemon) { struct SPDY_Session *pos; @@ -512,14 +512,14 @@ SPDYF_run (struct SPDY_Daemon *daemon) if (FD_ISSET (ds, &rs) || pos->fio_is_pending(pos)){ SPDYF_session_read(pos); } - + //do something with the data in read buffer if(SPDY_NO == SPDYF_session_idle(pos)) { //the session was closed, cannot write anymore //continue; } - + //write whatever has been put to the response queue //during read or idle operation, something might be put //on the response queue, thus call write operation @@ -530,7 +530,7 @@ SPDYF_run (struct SPDY_Daemon *daemon) //continue; } } - + /* the response queue has been flushed for half closed * connections, so let close them */ /*if(pos->read_closed) @@ -539,6 +539,6 @@ SPDYF_run (struct SPDY_Daemon *daemon) }*/ } } - + spdyf_cleanup_sessions(daemon); } diff --git a/src/microspdy/internal.h b/src/microspdy/internal.h @@ -26,6 +26,7 @@ #define INTERNAL_H_H #include "platform.h" +#include "platform_interface.h" #include "microspdy.h" /** @@ -63,7 +64,7 @@ extern void *spdyf_panic_cls; /** * Trigger 'panic' action based on fatal errors. - * + * * @param msg error message (const char *) */ #define SPDYF_PANIC(msg) \ @@ -103,7 +104,7 @@ extern void *spdyf_panic_cls; * * @param n input value (int32_t) * @return converted value (uint32_t) - */ + */ #if HAVE_BIG_ENDIAN #define NTOH24(n) n #else diff --git a/src/microspdy/session.c b/src/microspdy/session.c @@ -1476,7 +1476,7 @@ SPDYF_session_accept(struct SPDY_Daemon *daemon) free_and_fail: /* something failed, so shutdown, close and free memory */ shutdown (new_socket_fd, SHUT_RDWR); - (void)close (new_socket_fd); + (void)MHD_socket_close_ (new_socket_fd); if(NULL != session) { @@ -1577,7 +1577,7 @@ SPDYF_session_destroy(struct SPDY_Session *session) struct SPDYF_Stream *stream; struct SPDYF_Response_Queue *response_queue; - (void)close (session->socket_fd); + (void)MHD_socket_close_ (session->socket_fd); SPDYF_zlib_deflate_end(&session->zlib_send_stream); SPDYF_zlib_inflate_end(&session->zlib_recv_stream); diff --git a/src/testcurl/https/test_https_time_out.c b/src/testcurl/https/test_https_time_out.c @@ -19,7 +19,7 @@ */ /** - * @file mhds_get_test.c + * @file test_https_time_out.c * @brief: daemon TLS alert response test-case * * @author Sagie Amir @@ -69,7 +69,7 @@ test_tls_session_time_out (gnutls_session_t session) if (ret < 0) { fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT); - close (sd); + MHD_socket_close_ (sd); return -1; } @@ -77,7 +77,7 @@ test_tls_session_time_out (gnutls_session_t session) if (ret < 0) { fprintf (stderr, "Handshake failed\n"); - close (sd); + MHD_socket_close_ (sd); return -1; } @@ -88,11 +88,11 @@ test_tls_session_time_out (gnutls_session_t session) if (send (sd, "", 1, 0) == 0) { fprintf (stderr, "Connection failed to time-out\n"); - close (sd); + MHD_socket_close_ (sd); return -1; } - close (sd); + MHD_socket_close_ (sd); return 0; } @@ -123,7 +123,7 @@ main (int argc, char *const *argv) MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, MHD_OPTION_END); - if (d == NULL) + if (NULL == d) { fprintf (stderr, MHD_E_SERVER_INIT); return -1; diff --git a/src/testcurl/https/test_tls_extensions.c b/src/testcurl/https/test_tls_extensions.c @@ -188,8 +188,8 @@ test_hello_extension (gnutls_session_t session, extensions_t exten_t, } cleanup: - if (sd != -1) - close (sd); + if (-1 != sd) + MHD_socket_close_ (sd); gnutls_free (cbc.buf); return ret; } @@ -206,7 +206,7 @@ main (int argc, char *const *argv) gnutls_datum_t cert; gnutls_certificate_credentials_t xcred; - const int ext_arr[] = { + const int ext_arr[] = { GNUTLS_EXTENSION_SERVER_NAME, -1 }; diff --git a/src/testspdy/test_new_connection.c b/src/testspdy/test_new_connection.c @@ -17,7 +17,7 @@ */ /** - * @file request_response.c + * @file test_new_connection.c * @brief tests new connection callback. spdycli.c * code is reused here * @author Andrey Uzunov @@ -537,7 +537,7 @@ static int connect_to(const char *host, uint16_t port) if(rv == 0) { break; } - close(fd); + MHD_socket_close_(fd); fd = -1; } freeaddrinfo(res); @@ -650,7 +650,8 @@ static void request_free(struct Request *req) /* * Fetches the resource denoted by |uri|. */ -static void fetch_uri(const struct URI *uri) +static void +fetch_uri(const struct URI *uri) { spdylay_session_callbacks callbacks; int fd; @@ -726,11 +727,13 @@ static void fetch_uri(const struct URI *uri) SSL_free(ssl); SSL_CTX_free(ssl_ctx); shutdown(fd, SHUT_WR); - close(fd); + MHD_socket_close_ (fd); request_free(&req); } -static int parse_uri(struct URI *res, const char *uri) + +static int +parse_uri(struct URI *res, const char *uri) { /* We only interested in https */ size_t len, i, offset; diff --git a/src/testspdy/test_notls.c b/src/testspdy/test_notls.c @@ -488,7 +488,7 @@ static int connect_to(const char *host, uint16_t port) if(rv == 0) { break; } - close(fd); + MHD_socket_close_(fd); fd = -1; dief("connect", strerror(errno)); } @@ -661,7 +661,7 @@ static void fetch_uri(const struct URI *uri) /* Resource cleanup */ spdylay_session_del(connection.session); shutdown(fd, SHUT_WR); - close(fd); + MHD_socket_close_(fd); request_free(&req); } diff --git a/src/testspdy/test_request_response.c b/src/testspdy/test_request_response.c @@ -17,7 +17,7 @@ */ /** - * @file request_response.c + * @file test_request_response.c * @brief tests receiving request and sending response. spdycli.c (spdylay) * code is reused here * @author Andrey Uzunov @@ -525,7 +525,7 @@ static int connect_to(const char *host, uint16_t port) if(rv == 0) { break; } - close(fd); + MHD_socket_close_(fd); fd = -1; } freeaddrinfo(res); @@ -714,7 +714,7 @@ static void fetch_uri(const struct URI *uri) SSL_free(ssl); SSL_CTX_free(ssl_ctx); shutdown(fd, SHUT_WR); - close(fd); + MHD_socket_close_(fd); request_free(&req); }