2
0
Fork 0

flush sockets after request end by setting TCP_NODELY temporarily

personal/stbuehler/wip
Stefan Bühler 2013-05-25 15:23:16 +02:00
parent 11b4bdd8c5
commit bf6470375a
5 changed files with 21 additions and 0 deletions

View File

@ -101,6 +101,8 @@ LI_API void li_iostream_attach(liIOStream *iostream, liWorker *wrk);
LI_API void li_stream_simple_socket_close(liIOStream *stream, gboolean aborted);
LI_API void li_stream_simple_socket_io_cb(liIOStream *stream, liIOStreamEvent event);
LI_API void li_stream_simple_socket_io_cb_with_context(liIOStream *stream, liIOStreamEvent event, gpointer *data);
/* tries to flush TCP sockets by disabling nagle */
LI_API void li_stream_simple_socket_flush(liIOStream *stream);
/* inline implementations */

View File

@ -76,6 +76,7 @@ static void simple_tcp_io_cb(liIOStream *stream, liIOStreamEvent event) {
if (NULL != data->con && data->con->out_has_all_data
&& (NULL == stream->stream_out.out || 0 == stream->stream_out.out->length)) {
li_stream_simple_socket_flush(stream);
li_connection_request_done(data->con);
}

View File

@ -2,6 +2,9 @@
#include <lighttpd/base.h>
#include <lighttpd/throttle.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
void li_stream_simple_socket_close(liIOStream *stream, gboolean aborted) {
int fd = li_event_io_fd(&stream->io_watcher);
@ -182,3 +185,16 @@ void li_stream_simple_socket_io_cb_with_context(liIOStream *stream, liIOStreamEv
break;
}
}
void li_stream_simple_socket_flush(liIOStream *stream) {
int val = 1;
int fd = fd = li_event_io_fd(&stream->io_watcher);
if (-1 != fd) {
/* setting TCP_NODELAY should flush the socket. if it fails it probably isn't a TCP socket,
* so no need to disable TCP_NODELAY */
if (-1 != setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val))) {
val = 0;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
}
}
}

View File

@ -105,6 +105,7 @@ static void tcp_io_cb(liIOStream *stream, liIOStreamEvent event) {
if (NULL != conctx->con && conctx->con->out_has_all_data
&& (NULL == stream->stream_out.out || 0 == stream->stream_out.out->length)
&& li_streams_empty(conctx->con->con_sock.raw_out, NULL)) {
li_stream_simple_socket_flush(stream);
li_connection_request_done(conctx->con);
}

View File

@ -88,6 +88,7 @@ static void tcp_io_cb(liIOStream *stream, liIOStreamEvent event) {
if (NULL != conctx->con && conctx->con->out_has_all_data
&& (NULL == stream->stream_out.out || 0 == stream->stream_out.out->length)
&& li_streams_empty(conctx->con->con_sock.raw_out, NULL)) {
li_stream_simple_socket_flush(stream);
li_connection_request_done(conctx->con);
}