Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/os/unix
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-02-06 20:21:13 +0300
committerIgor Sysoev <igor@sysoev.ru>2003-02-06 20:21:13 +0300
commit7300977320e04280c13d4d89a279f75af9c5f893 (patch)
tree6c935b625eb2dbd83e71e5b2e23ac83bfd88aded /src/os/unix
parent2a2d2b5094ee88dba5984eddfc4135b66bb8007e (diff)
nginx-0.0.1-2003-02-06-20:21:13 import
Diffstat (limited to 'src/os/unix')
-rw-r--r--src/os/unix/freebsd/ngx_sendfile.c27
-rw-r--r--src/os/unix/ngx_errno.h1
-rw-r--r--src/os/unix/ngx_socket.c26
-rw-r--r--src/os/unix/ngx_socket.h19
-rw-r--r--src/os/unix/ngx_time.h2
5 files changed, 62 insertions, 13 deletions
diff --git a/src/os/unix/freebsd/ngx_sendfile.c b/src/os/unix/freebsd/ngx_sendfile.c
index dcbf68a3a..8de85f6f7 100644
--- a/src/os/unix/freebsd/ngx_sendfile.c
+++ b/src/os/unix/freebsd/ngx_sendfile.c
@@ -5,25 +5,25 @@
#include <ngx_core.h>
#include <ngx_types.h>
-#include <ngx_file.h>
#include <ngx_socket.h>
#include <ngx_errno.h>
#include <ngx_log.h>
+#include <ngx_connection.h>
#include <ngx_sendv.h>
#include <ngx_sendfile.h>
/*
CHECK:
check sent if errno == EINTR then should return right sent.
+ EINTR should not occur according to man.
*/
-int ngx_sendfile(ngx_socket_t s,
+int ngx_sendfile(ngx_connection_t *c,
ngx_iovec_t *headers, int hdr_cnt,
ngx_fd_t fd, off_t offset, size_t nbytes,
ngx_iovec_t *trailers, int trl_cnt,
- off_t *sent,
- ngx_log_t *log)
+ off_t *sent, u_int flags)
{
int rc, i;
ngx_err_t err;
@@ -35,26 +35,29 @@ int ngx_sendfile(ngx_socket_t s,
hdtr.trl_cnt = trl_cnt;
#if (HAVE_FREEBSD_SENDFILE_NBYTES_BUG)
- for (i = 0; i < hdr_cnt; i++)
+ for (i = 0; i < hdr_cnt; i++) {
nbytes += headers[i].iov_len;
+ }
#endif
- rc = sendfile(fd, s, offset, nbytes, &hdtr, sent, 0);
+ rc = sendfile(fd, c->fd, offset, nbytes, &hdtr, sent, flags);
if (rc == -1) {
- err = ngx_socket_errno;
+ err = ngx_errno;
if (err != NGX_EAGAIN && err != NGX_EINTR) {
- ngx_log_error(NGX_LOG_ERR, log, err,
- "ngx_sendfile: sendfile failed");
+ ngx_log_error(NGX_LOG_ERR, c->log, err, "sendfile failed");
+
return NGX_ERROR;
} else {
- ngx_log_error(NGX_LOG_INFO, log, err,
- "ngx_sendfile: sendfile sent only %qd bytes", *sent);
+ ngx_log_error(NGX_LOG_INFO, c->log, err,
+ "sendfile sent only %qd bytes", *sent);
+
+ return NGX_AGAIN;
}
}
- ngx_log_debug(log, "ngx_sendfile: %d, @%qd %qd:%d" _
+ ngx_log_debug(c->log, "sendfile: %d, @%qd %qd:%d" _
rc _ offset _ *sent _ nbytes);
return NGX_OK;
diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h
index 62e1b0703..a5fccab59 100644
--- a/src/os/unix/ngx_errno.h
+++ b/src/os/unix/ngx_errno.h
@@ -15,6 +15,7 @@ typedef int ngx_err_t;
#define NGX_EINPROGRESS EINPROGRESS
#define NGX_EADDRINUSE EADDRINUSE
#define NGX_ETIMEDOUT ETIMEDOUT
+#define NGX_ECANCELED ECANCELED
#define ngx_errno errno
#define ngx_socket_errno errno
diff --git a/src/os/unix/ngx_socket.c b/src/os/unix/ngx_socket.c
new file mode 100644
index 000000000..d213fa86f
--- /dev/null
+++ b/src/os/unix/ngx_socket.c
@@ -0,0 +1,26 @@
+
+#include <ngx_socket.h>
+
+
+/* ioctl(FIONBIO) set blocking mode with one syscall only while
+ fcntl(F_SETFL, ~O_NONBLOCK) need to know previous state
+ using fcntl(F_GETFL).
+ On FreeBSD both are syscall */
+
+#ifdef __FreeBSD__
+
+int ngx_nonblocking(ngx_socket_t s)
+{
+ unsigned long nb = 1;
+
+ return ioctl(s, FIONBIO, &nb);
+}
+
+int ngx_blocking(ngx_socket_t s)
+{
+ unsigned long nb = 0;
+
+ return ioctl(s, FIONBIO, &nb);
+}
+
+#endif
diff --git a/src/os/unix/ngx_socket.h b/src/os/unix/ngx_socket.h
index b4be76240..937c12d9a 100644
--- a/src/os/unix/ngx_socket.h
+++ b/src/os/unix/ngx_socket.h
@@ -4,6 +4,11 @@
#include <ngx_config.h>
+#ifdef __FreeBSD__
+#include <sys/ioctl.h>
+#endif
+
+
#define NGX_WRITE_SHUTDOWN SHUT_WR
typedef int ngx_socket_t;
@@ -11,9 +16,23 @@ typedef int ngx_socket_t;
#define ngx_socket(af, type, proto, flags) socket(af, type, proto)
#define ngx_socket_n "socket()"
+
+#ifdef __FreeBSD__
+
+int ngx_nonblocking(ngx_socket_t s);
+int ngx_blocking(ngx_socket_t s);
+
+#define ngx_nonblocking_n "ioctl(FIONBIO)"
+#define ngx_blocking_n "ioctl(!FIONBIO)"
+
+#else
+
#define ngx_nonblocking(s) fcntl(s, F_SETFL, O_NONBLOCK)
#define ngx_nonblocking_n "fcntl(O_NONBLOCK)"
+#endif
+
+
#define ngx_shutdown_socket shutdown
#define ngx_shutdown_socket_n "shutdown()"
diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h
index fac71adf4..5cd791d0e 100644
--- a/src/os/unix/ngx_time.h
+++ b/src/os/unix/ngx_time.h
@@ -5,7 +5,7 @@
#include <ngx_config.h>
typedef u_int ngx_msec_t;
-#define NGX_MAX_MSEC ~0
+#define NGX_MAX_MSEC (u_int) ~0
typedef struct tm ngx_tm_t;