diff --git a/plugins/fastrouter/fastrouter.c b/plugins/fastrouter/fastrouter.c index 7e3ef916..cd2da482 100644 --- a/plugins/fastrouter/fastrouter.c +++ b/plugins/fastrouter/fastrouter.c @@ -582,6 +582,10 @@ void fastrouter_loop(int id) { break; } +#ifndef __linux__ + uwsgi_socket_b(new_connection); +#endif + ufr.fr_table[new_connection] = alloc_fr_session(); ufr.fr_table[new_connection]->fd = new_connection; ufr.fr_table[new_connection]->instance_fd = -1; diff --git a/plugins/http/http.c b/plugins/http/http.c index 082eaa9c..95e2d419 100644 --- a/plugins/http/http.c +++ b/plugins/http/http.c @@ -592,6 +592,9 @@ void http_loop(int id) { taken = 1; break; } +#ifndef __linux__ + uwsgi_socket_b(new_connection); +#endif uhttp_table[new_connection] = alloc_uhttp_session(); uhttp_table[new_connection]->fd = new_connection; @@ -892,10 +895,9 @@ void http_loop(int id) { break; } - len = send(uhttp_session->fd, bbuf, len, 0); - - if (len <= 0) { - if (len < 0) + ssize_t s_len = send(uhttp_session->fd, bbuf, len, 0); + if (s_len <= 0) { + if (s_len < 0) uwsgi_error("send()"); close(uhttp_session->fd); close(uhttp_session->instance_fd); diff --git a/socket.c b/socket.c index 523813c0..ae99dcb6 100644 --- a/socket.c +++ b/socket.c @@ -758,6 +758,7 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) { return serverfd; } +// set non-blocking socket void uwsgi_socket_nb(int fd) { int arg; @@ -774,6 +775,24 @@ void uwsgi_socket_nb(int fd) { } +// set blocking socket +void uwsgi_socket_b(int fd) { + int arg; + + arg = fcntl(fd, F_GETFL, NULL); + if (arg < 0) { + uwsgi_error("fcntl()"); + return; + } + arg &= (~O_NONBLOCK); + if (fcntl(fd, F_SETFL, arg) < 0) { + uwsgi_error("fcntl()"); + return; + } + +} + + int timed_connect(struct pollfd *fdpoll, const struct sockaddr *addr, int addr_size, int timeout, int async) { int arg, ret; diff --git a/uwsgi.h b/uwsgi.h index d90035a0..b59305ae 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2465,6 +2465,7 @@ void uwsgi_string_del_list(struct uwsgi_string_list **, struct uwsgi_string_list void uwsgi_init_all_apps(void); void uwsgi_socket_nb(int); +void uwsgi_socket_b(int); void uwsgi_destroy_request(struct wsgi_request *);