Mercurial > hg > nginx
comparison src/event/ngx_event_openssl.c @ 398:201b5f68b59f
nginx-0.0.7-2004-07-23-21:05:37 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 23 Jul 2004 17:05:37 +0000 |
parents | de797f3b4c27 |
children | 4e21d1291a14 |
comparison
equal
deleted
inserted
replaced
397:de797f3b4c27 | 398:201b5f68b59f |
---|---|
104 | 104 |
105 return NGX_ERROR; | 105 return NGX_ERROR; |
106 } | 106 } |
107 | 107 |
108 | 108 |
109 /* | |
110 * OpenSSL has no SSL_writev() so we copy several bufs into our 16K buffer | |
111 * before SSL_write() call to decrease a SSL overhead. | |
112 * | |
113 * Besides for protocols such as HTTP it is possible to always buffer | |
114 * the output to decrease a SSL overhead some more. | |
115 */ | |
116 | |
109 ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, | 117 ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, |
110 off_t limit) | 118 off_t limit) |
111 { | 119 { |
112 int n; | 120 int n; |
113 ngx_uint_t flush; | 121 ngx_uint_t flush, last; |
114 ssize_t send, size; | 122 ssize_t send, size; |
115 ngx_buf_t *buf; | 123 ngx_buf_t *buf; |
116 | 124 |
117 buf = c->ssl->buf; | 125 buf = c->ssl->buf; |
118 | 126 |
119 if (in && in->next == NULL && !c->ssl->buffer && buf->pos == buf->last) { | 127 if (in && in->next == NULL && buf->pos == buf->last && !c->ssl->buffer) { |
120 | 128 |
121 /* | 129 /* |
122 * the optimized path without a copy if there is the single incoming | 130 * we avoid a buffer copy if the incoming buf is a single, |
123 * buf, we do not need to buffer output and our buffer is empty | 131 * our buffer is empty, and we do not need to buffer the output |
124 */ | 132 */ |
125 | 133 |
126 n = ngx_ssl_write(c, in->buf->pos, in->buf->last - in->buf->pos); | 134 n = ngx_ssl_write(c, in->buf->pos, in->buf->last - in->buf->pos); |
127 | 135 |
136 if (n == NGX_ERROR) { | |
137 return NGX_CHAIN_ERROR; | |
138 } | |
139 | |
128 if (n < 0) { | 140 if (n < 0) { |
129 return (ngx_chain_t *) n; | 141 n = 0; |
130 } | 142 } |
131 | 143 |
132 in->buf->pos += n; | 144 in->buf->pos += n; |
133 | 145 |
134 return in; | 146 return in; |
135 } | 147 } |
136 | 148 |
137 send = 0; | 149 send = 0; |
138 flush = (in == NULL) ? 1 : 0; | 150 flush = (in == NULL) ? 1 : 0; |
151 last = (in == NULL) ? 1 : 0; | |
139 | 152 |
140 for ( ;; ) { | 153 for ( ;; ) { |
141 | 154 |
142 while (in && buf->last < buf->end) { | 155 while (in && buf->last < buf->end) { |
143 if (in->buf->last_buf) { | 156 if (in->buf->last_buf) { |
144 flush = 1; | 157 flush = 1; |
158 last = 1; | |
145 } | 159 } |
146 | 160 |
147 if (ngx_buf_special(in->buf)) { | 161 if (ngx_buf_special(in->buf)) { |
162 in = in->next; | |
148 continue; | 163 continue; |
149 } | 164 } |
150 | 165 |
151 size = in->buf->last - in->buf->pos; | 166 size = in->buf->last - in->buf->pos; |
152 | 167 |
154 size = buf->end - buf->last; | 169 size = buf->end - buf->last; |
155 } | 170 } |
156 | 171 |
157 /* | 172 /* |
158 * TODO: the taking in->buf->flush into account can be | 173 * TODO: the taking in->buf->flush into account can be |
159 * implemented using the limit | 174 * implemented using the limit on the higher level |
160 */ | 175 */ |
161 | 176 |
162 if (send + size > limit) { | 177 if (send + size > limit) { |
163 size = limit - send; | 178 size = limit - send; |
164 flush = 1; | 179 flush = 1; |
177 } | 192 } |
178 } | 193 } |
179 | 194 |
180 size = buf->last - buf->pos; | 195 size = buf->last - buf->pos; |
181 | 196 |
182 if (flush || buf->last == buf->end || !c->ssl->buffer) { | 197 if (!flush && buf->last < buf->end && c->ssl->buffer) { |
183 n = ngx_ssl_write(c, buf->pos, size); | 198 break; |
184 | 199 } |
185 } else { | 200 |
186 return NGX_CHAIN_AGAIN; | 201 n = ngx_ssl_write(c, buf->pos, size); |
202 | |
203 if (n == NGX_ERROR) { | |
204 return NGX_CHAIN_ERROR; | |
187 } | 205 } |
188 | 206 |
189 if (n < 0) { | 207 if (n < 0) { |
190 return (ngx_chain_t *) n; | 208 n = 0; |
191 } | 209 } |
192 | 210 |
193 buf->pos += n; | 211 buf->pos += n; |
194 send += n; | 212 send += n; |
195 c->sent += n; | 213 c->sent += n; |
210 | 228 |
211 if (in) { | 229 if (in) { |
212 return in; | 230 return in; |
213 } | 231 } |
214 | 232 |
215 if (buf->pos == buf->last) { | 233 if (buf->pos == buf->last || !last) { |
216 return NULL; | 234 return NULL; |
217 } | 235 } |
218 | 236 |
219 return NGX_CHAIN_AGAIN; | 237 return NGX_CHAIN_AGAIN; |
220 } | 238 } |
221 | 239 |
222 | 240 |
223 static ngx_int_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size) | 241 static ngx_int_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size) |
224 { | 242 { |