flush sockets after request end by setting TCP_NODELY temporarily

personal/stbuehler/wip
Stefan Bühler 9 years ago
parent 11b4bdd8c5
commit bf6470375a
  1. 2
      include/lighttpd/stream.h
  2. 1
      src/main/connection.c
  3. 16
      src/main/stream_simple_socket.c
  4. 1
      src/modules/mod_gnutls.c
  5. 1
      src/modules/mod_openssl.c

@ -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 */

@ -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);
}

@ -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));
}
}
}

@ -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);
}

@ -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);
}

Loading…
Cancel
Save