unsigned pipeline:1;
unsigned unexpected_eof:1;
unsigned tcp_nopush:1;
+ unsigned tcp_nopush_enabled:1;
};
ctx->action = "keepalive";
+ if (c->tcp_nopush) {
+ if (ngx_tcp_push(c->fd) == NGX_ERROR) {
+ ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
+ ngx_tcp_push_n " failed");
+ ngx_http_close_connection(c);
+ return;
+ }
+ c->tcp_nopush = 0;
+ }
+
if ((ngx_event_flags & NGX_HAVE_AIO_EVENT) || blocked) {
ngx_http_keepalive_handler(rev);
}
#include <ngx_http.h>
#include <nginx.h>
+/* STUB probably, needed for ngx_freebsd_tcp_nopush_flush */
+#ifdef __FreeBSD__
+#include <ngx_freebsd_init.h>
+#endif
+
+
static int ngx_http_header_filter_init(ngx_pool_t *pool);
static int ngx_http_header_filter(ngx_http_request_t *r);
ngx_chain_t *ch;
ngx_table_elt_t *header;
+#ifdef __FreeBSD__
+
+ if (r->keepalive) {
+ if (ngx_freebsd_tcp_nopush_flush) {
+ r->connection->tcp_nopush_enabled = 1;
+ }
+
+ } else {
+ r->connection->tcp_nopush_enabled = 1;
+ }
+
+#else
+
+ r->connection->tcp_nopush_enabled = 1;
+
+#endif
+
if (r->http_version < NGX_HTTP_VERSION_10) {
return NGX_OK;
}
len += 28;
}
- if (r->keepalive == 0) {
- /* "Connection: close\r\n" */
- len += 19;
- } else {
+ if (r->keepalive) {
/* "Connection: keep-alive\r\n" */
len += 24;
+ } else {
+ /* "Connection: close\r\n" */
+ len += 19;
}
header = (ngx_table_elt_t *) r->headers_out.headers->elts;
h->last = ngx_cpymem(h->last, "Transfer-Encoding: chunked" CRLF, 28);
}
- if (r->keepalive == 0) {
- h->last = ngx_cpymem(h->last, "Connection: close" CRLF, 19);
+ if (r->keepalive) {
+ h->last = ngx_cpymem(h->last, "Connection: keep-alive" CRLF, 24);
} else {
- h->last = ngx_cpymem(h->last, "Connection: keep-alive" CRLF, 24);
+ h->last = ngx_cpymem(h->last, "Connection: close" CRLF, 19);
}
for (i = 0; i < r->headers_out.headers->nelts; i++) {
#include <sys/uio.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
+#include <sys/sysctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h> /* TCP_NOPUSH */
#endif
+#ifndef HAVE_FIONBIO
+#define HAVE_FIONBIO 1
+#endif
+
+
#endif /* _NGX_FREEBSD_CONFIG_H_INCLUDED_ */
size_t size;
ngx_err_t err;
- size = 20;
+ size = sizeof(ngx_freebsd_kern_ostype);
if (sysctlbyname("kern.ostype",
ngx_freebsd_kern_ostype, &size, NULL, 0) == -1) {
ngx_log_error(NGX_LOG_ALERT, log, errno,
return NGX_ERROR;
}
- size = 20;
+ size = sizeof(ngx_freebsd_kern_osrelease);
if (sysctlbyname("kern.osrelease",
ngx_freebsd_kern_osrelease, &size, NULL, 0) == -1) {
ngx_log_error(NGX_LOG_ALERT, log, errno,
ngx_freebsd_kern_ostype, ngx_freebsd_kern_osrelease);
- size = 4;
+ size = sizeof(int);
if (sysctlbyname("kern.osreldate",
&ngx_freebsd_kern_osreldate, &size, NULL, 0) == -1) {
ngx_log_error(NGX_LOG_ALERT, log, errno,
#include <ngx_config.h>
#include <ngx_core.h>
-#include <sys/sysctl.h>
/* STUB */
extern int ngx_freebsd_sendfile_nbytes_bug;
extern int ngx_freebsd_tcp_nopush_flush;
extern int ngx_freebsd_kern_ipc_zero_copy_send;
+extern int ngx_freebsd_tcp_nopush_flush;
#endif /* _NGX_FREEBSD_INIT_H_INCLUDED_ */
if (file) {
- if (!c->tcp_nopush && ngx_freebsd_tcp_nopush_flush) {
+ if (!c->tcp_nopush && c->tcp_nopush_enabled) {
c->tcp_nopush = 1;
tcp_nopush = 1;
- if (setsockopt(c->fd, IPPROTO_TCP, TCP_NOPUSH,
- (const void *) &tcp_nopush,
- sizeof(int)) == -1)
- {
- ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno,
- "setsockopt(TCP_NOPUSH) failed");
+ if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
+ ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
+ ngx_tcp_nopush_n " failed");
return NGX_CHAIN_ERROR;
}
+ngx_log_debug(c->log, "NOPUSH");
}
hdtr.headers = (struct iovec *) header.elts;
} while ((tail && tail == ce) || eintr);
- /* STUB: should be in app code, no need to clear TCP_NOPUSH
- if the conneciton close()d or shutdown()ed */
-
- if (c->tcp_nopush) {
- c->tcp_nopush = 0;
- tcp_nopush = 0;
- if (setsockopt(c->fd, IPPROTO_TCP, TCP_NOPUSH,
- (const void *) &tcp_nopush,
- sizeof(int)) == -1)
- {
- ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno,
- "setsockopt(!TCP_NOPUSH) failed");
- return NGX_CHAIN_ERROR;
- }
- }
-
return ce;
}
#define _NGX_LINUX_CONFIG_H_INCLUDED_
-#define _XOPEN_SOURCE 500
+#define _FILE_OFFSET_BITS 64
+#define _LARGEFILE_SOURCE
+#define _XOPEN_SOURCE 500 /* pread, pwrite */
#include <unistd.h>
+#undef _XOPEN_SOURCE 500
+
#include <stddef.h> /* offsetof */
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
-#define __USE_BSD
+#define __USE_BSD /* bzero */
#include <string.h>
#undef __USE_BSD
#include <sys/uio.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
+#include <sys/sysctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
-typedef unsigned int u_int;
-typedef unsigned char u_char;
+typedef unsigned int u_int;
+typedef unsigned short u_short;
+typedef unsigned char u_char;
#ifndef HAVE_SELECT
#endif
+#ifndef HAVE_FIONBIO
+#define HAVE_FIONBIO 1
+#endif
+
+
#endif /* _NGX_LINUX_CONFIG_H_INCLUDED_ */
--- /dev/null
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+/* STUB */
+ssize_t ngx_unix_recv(ngx_connection_t *c, char *buf, size_t size);
+ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in);
+int ngx_posix_init(ngx_log_t *log);
+
+
+char ngx_linux_kern_ostype[50];
+char ngx_linux_kern_osrelease[20];
+
+
+ngx_os_io_t ngx_os_io = {
+ ngx_unix_recv,
+ NULL,
+ NULL,
+ ngx_writev_chain,
+ NGX_HAVE_ZEROCOPY
+};
+
+
+int ngx_os_init(ngx_log_t *log)
+{
+ int name[2], len;
+
+ name[0] = CTL_KERN;
+ name[1] = KERN_OSTYPE;
+ len = sizeof(ngx_linux_kern_ostype);
+ if (sysctl(name, sizeof(name), ngx_linux_kern_ostype, &len, NULL, 0)
+ == -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, errno, "sysctl(KERN_OSTYPE) failed");
+ return NGX_ERROR;
+ }
+
+ name[0] = CTL_KERN;
+ name[1] = KERN_OSRELEASE;
+ len = sizeof(ngx_linux_kern_osrelease);
+ if (sysctl(name, sizeof(name), ngx_linux_kern_osrelease, &len, NULL, 0)
+ == -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, errno,
+ "sysctl(KERN_OSRELEASE) failed");
+ return NGX_ERROR;
+ }
+
+ ngx_log_error(NGX_LOG_INFO, log, 0, "OS: %s %s",
+ ngx_linux_kern_ostype, ngx_linux_kern_osrelease);
+
+
+ return ngx_posix_init(log);
+}
-#include <ngx_socket.h>
+#include <ngx_config.h>
+#include <ngx_core.h>
/*
ioctl() and fcntl() are syscalls on FreeBSD, Solaris 7/8 and Linux
*/
-#if 1
+
+#if (HAVE_FIONBIO)
int ngx_nonblocking(ngx_socket_t s)
{
return ioctl(s, FIONBIO, &nb);
}
+
int ngx_blocking(ngx_socket_t s)
{
unsigned long nb = 0;
}
#endif
+
+
+#ifdef __FreeBSD__
+
+int ngx_tcp_nopush(ngx_socket_t s)
+{
+ int tcp_nopush;
+
+ tcp_nopush = 1;
+
+ return setsockopt(s, IPPROTO_TCP, TCP_NOPUSH,
+ (const void *) &tcp_nopush, sizeof(int));
+}
+
+
+int ngx_tcp_push(ngx_socket_t s)
+{
+ int tcp_nopush;
+
+ tcp_nopush = 0;
+
+ return setsockopt(s, IPPROTO_TCP, TCP_NOPUSH,
+ (const void *) &tcp_nopush, sizeof(int));
+}
+
+#else
+
+
+int ngx_tcp_nopush(ngx_socket_t s)
+{
+ return NGX_OK;
+}
+
+int ngx_tcp_push(ngx_socket_t s)
+{
+ return NGX_OK;
+}
+
+#endif
#define ngx_socket_n "socket()"
-#if 1
+#if (HAVE_FIONBIO)
int ngx_nonblocking(ngx_socket_t s);
int ngx_blocking(ngx_socket_t s);
#endif
+int ngx_tcp_nopush(ngx_socket_t s);
+#define ngx_tcp_nopush_n "setsockopt(TCP_NOPUSH)"
+
+int ngx_tcp_push(ngx_socket_t s);
+#define ngx_tcp_push_n "setsockopt(!TCP_NOPUSH)"
+
+
#define ngx_shutdown_socket shutdown
#define ngx_shutdown_socket_n "shutdown()"
#endif
+#ifndef HAVE_FIONBIO
+#define HAVE_FIONBIO 1
+#endif
+
+
#endif /* _NGX_SOLARIS_CONFIG_H_INCLUDED_ */