Mercurial > hg > nginx-quic
comparison src/os/win32/ngx_sendfile.c @ 59:e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 06 Feb 2003 17:21:13 +0000 |
parents | 708f8bb772ec |
children | 50186b49f2ad |
comparison
equal
deleted
inserted
replaced
58:6b13b1cadabe | 59:e8cdc2989cee |
---|---|
4 #include <ngx_types.h> | 4 #include <ngx_types.h> |
5 #include <ngx_files.h> | 5 #include <ngx_files.h> |
6 #include <ngx_socket.h> | 6 #include <ngx_socket.h> |
7 #include <ngx_errno.h> | 7 #include <ngx_errno.h> |
8 #include <ngx_log.h> | 8 #include <ngx_log.h> |
9 #include <ngx_connection.h> | |
9 #include <ngx_sendv.h> | 10 #include <ngx_sendv.h> |
10 #include <ngx_sendfile.h> | 11 #include <ngx_sendfile.h> |
11 | 12 |
12 /* | 13 /* |
13 TODO: | 14 TODO: |
15 TransmitPackets | 16 TransmitPackets |
16 */ | 17 */ |
17 | 18 |
18 #if (HAVE_WIN32_TRANSMITFILE) | 19 #if (HAVE_WIN32_TRANSMITFILE) |
19 | 20 |
20 int ngx_sendfile(ngx_socket_t s, | 21 int ngx_sendfile(ngx_connection_t *c, |
21 ngx_iovec_t *headers, int hdr_cnt, | 22 ngx_iovec_t *headers, int hdr_cnt, |
22 ngx_fd_t fd, off_t offset, size_t nbytes, | 23 ngx_fd_t fd, off_t offset, size_t nbytes, |
23 ngx_iovec_t *trailers, int trl_cnt, | 24 ngx_iovec_t *trailers, int trl_cnt, |
24 off_t *sent, | 25 off_t *sent, u_int flags) |
25 ngx_log_t *log) | |
26 { | 26 { |
27 int tfrc, rc; | 27 int tfrc, rc; |
28 ngx_err_t tf_err, err; | 28 ngx_err_t tf_err, err; |
29 OVERLAPPED olp; | 29 OVERLAPPED olp; |
30 TRANSMIT_FILE_BUFFERS tfb, *ptfb; | 30 TRANSMIT_FILE_BUFFERS tfb, *ptfb; |
31 | |
32 #if 0 | |
33 ev = c->write; | |
34 | |
35 if (ev->timedout) { | |
36 ngx_set_socket_errno(NGX_ETIMEDOUT); | |
37 ngx_log_error(NGX_LOG_ERR, ev->log, 0, "TransmitFile() timed out"); | |
38 | |
39 return NGX_ERROR; | |
40 } | |
41 | |
42 if (ev->ready) { | |
43 ev->ready = 0; | |
44 | |
45 #if (HAVE_IOCP_EVENT) /* iocp */ | |
46 | |
47 if (ngx_event_flags & NGX_HAVE_IOCP_EVENT) { | |
48 if (ev->ovlp.error) { | |
49 ngx_log_error(NGX_LOG_ERR, ev->log, 0, "TransmitFile() failed"); | |
50 return NGX_ERROR; | |
51 } | |
52 | |
53 return ev->available; | |
54 } | |
55 } | |
56 | |
57 #endif | |
58 | |
59 /* TODO: WSAGetOverlappedResult stuff */ | |
60 | |
61 } | |
62 | |
63 #endif | |
64 | |
31 | 65 |
32 tf_err = 0; | 66 tf_err = 0; |
33 err = 0; | 67 err = 0; |
34 | 68 |
35 olp.Internal = 0; | 69 olp.Internal = 0; |
47 | 81 |
48 } else { | 82 } else { |
49 ptfb = NULL; | 83 ptfb = NULL; |
50 } | 84 } |
51 | 85 |
52 #if 1 | 86 #if 0 |
53 tfrc = TransmitFile(s, fd, nbytes, 0, &olp, ptfb, 0); | 87 flags = TF_DISCONNECT|TF_REUSE_SOCKET; |
54 #else | |
55 tfrc = TransmitFile(s, fd, nbytes, 0, NULL, ptfb, 0); | |
56 #endif | 88 #endif |
57 | 89 |
58 if (tfrc == 0) | 90 tfrc = TransmitFile(c->fd, fd, nbytes, 0, &olp, ptfb, flags); |
91 | |
92 #if 0 | |
93 #if 1 | |
94 tfrc = TransmitFile(c->fd, fd, nbytes, 0, &olp, ptfb, 0); | |
95 #else | |
96 tfrc = TransmitFile(c->fd, fd, nbytes, 0, NULL, ptfb, 0); | |
97 #endif | |
98 #endif | |
99 | |
100 if (tfrc == 0) { | |
59 tf_err = ngx_socket_errno; | 101 tf_err = ngx_socket_errno; |
102 ngx_log_error(NGX_LOG_NOTICE, c->log, tf_err, | |
103 "ngx_sendfile: TransmitFile failed"); | |
104 if (tf_err == WSA_IO_PENDING) { | |
105 return NGX_AGAIN; | |
106 } | |
107 } | |
60 | 108 |
61 /* set sent */ | 109 /* set sent */ |
62 #if 0 | 110 #if 0 |
63 rc = WSAGetOverlappedResult(s, &olp, (unsigned long *) sent, 0, NULL); | 111 rc = WSAGetOverlappedResult(c->fd, &olp, (unsigned long *) sent, 0, NULL); |
64 #else | 112 #else |
65 *sent = olp.InternalHigh; | 113 *sent = olp.InternalHigh; |
66 rc = 1; | 114 rc = 1; |
67 #endif | 115 #endif |
68 | 116 |
69 ngx_log_debug(log, "ngx_sendfile: %d, @%I64d %I64d:%d" _ | 117 ngx_log_debug(c->log, "TransmitFile: %d, @%I64d %I64d:%d" _ |
70 tfrc _ offset _ *sent _ nbytes); | 118 tfrc _ offset _ *sent _ nbytes); |
71 | 119 |
72 if (rc == 0) { | 120 if (rc == 0) { |
73 err = ngx_socket_errno; | 121 err = ngx_socket_errno; |
74 ngx_log_error(NGX_LOG_ERR, log, err, | 122 ngx_log_error(NGX_LOG_ERR, c->log, err, |
75 "ngx_sendfile: WSAGetOverlappedResult failed"); | 123 "ngx_sendfile: WSAGetOverlappedResult failed"); |
76 } | 124 } |
77 | 125 |
78 if (tfrc == 0) { | 126 if (tfrc == 0) { |
79 if (tf_err != NGX_EAGAIN) { | 127 if (tf_err != NGX_EAGAIN) { |
80 ngx_log_error(NGX_LOG_ERR, log, tf_err, | 128 ngx_log_error(NGX_LOG_ERR, c->log, tf_err, |
81 "ngx_sendfile: TransmitFile failed"); | 129 "ngx_sendfile: TransmitFile failed"); |
82 return NGX_ERROR; | 130 return NGX_ERROR; |
83 } | 131 } |
84 | 132 |
85 ngx_log_error(NGX_LOG_INFO, log, tf_err, | 133 ngx_log_error(NGX_LOG_INFO, c->log, tf_err, |
86 "ngx_sendfile: TransmitFile sent only %I64d bytes", | 134 "ngx_sendfile: TransmitFile sent only %I64d bytes", |
87 *sent); | 135 *sent); |
88 } | 136 } |
89 | 137 |
90 if (rc == 0) | 138 if (rc == 0) |