ssize_t
-ngx_ssl_recv_chain(ngx_connection_t *c, ngx_chain_t *cl)
+ngx_ssl_recv_chain(ngx_connection_t *c, ngx_chain_t *cl, off_t limit)
{
u_char *last;
- ssize_t n, bytes;
+ ssize_t n, bytes, size;
ngx_buf_t *b;
bytes = 0;
last = b->last;
for ( ;; ) {
+ size = b->end - last;
- n = ngx_ssl_recv(c, last, b->end - last);
+ if (limit) {
+ if (bytes >= limit) {
+ return bytes;
+ }
+
+ if (bytes + size > limit) {
+ size = (ssize_t) (limit - bytes);
+ }
+ }
+
+ n = ngx_ssl_recv(c, last, size);
if (n > 0) {
last += n;
ngx_int_t ngx_ssl_handshake(ngx_connection_t *c);
ssize_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size);
ssize_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size);
-ssize_t ngx_ssl_recv_chain(ngx_connection_t *c, ngx_chain_t *cl);
+ssize_t ngx_ssl_recv_chain(ngx_connection_t *c, ngx_chain_t *cl, off_t limit);
ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
off_t limit);
void ngx_ssl_free_buffer(ngx_connection_t *c);
break;
}
- n = p->upstream->recv_chain(p->upstream, chain);
+ n = p->upstream->recv_chain(p->upstream, chain, 0);
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
"pipe recv chain: %z", n);
ssize_t
-ngx_aio_read_chain(ngx_connection_t *c, ngx_chain_t *cl)
+ngx_aio_read_chain(ngx_connection_t *c, ngx_chain_t *cl, off_t limit)
{
int n;
u_char *buf, *prev;
typedef ssize_t (*ngx_recv_pt)(ngx_connection_t *c, u_char *buf, size_t size);
-typedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in);
+typedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in,
+ off_t limit);
typedef ssize_t (*ngx_send_pt)(ngx_connection_t *c, u_char *buf, size_t size);
typedef ngx_chain_t *(*ngx_send_chain_pt)(ngx_connection_t *c, ngx_chain_t *in,
off_t limit);
ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size);
-ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *entry);
+ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *entry, off_t limit);
ssize_t ngx_udp_unix_recv(ngx_connection_t *c, u_char *buf, size_t size);
ssize_t ngx_unix_send(ngx_connection_t *c, u_char *buf, size_t size);
ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in,
#if (NGX_HAVE_AIO)
ssize_t ngx_aio_read(ngx_connection_t *c, u_char *buf, size_t size);
-ssize_t ngx_aio_read_chain(ngx_connection_t *c, ngx_chain_t *cl);
+ssize_t ngx_aio_read_chain(ngx_connection_t *c, ngx_chain_t *cl, off_t limit);
ssize_t ngx_aio_write(ngx_connection_t *c, u_char *buf, size_t size);
ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in,
off_t limit);
ssize_t
-ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
+ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit)
{
u_char *prev;
ssize_t n, size;
/* coalesce the neighbouring bufs */
while (chain) {
+ n = chain->buf->end - chain->buf->last;
+
+ if (limit) {
+ if (size >= limit) {
+ break;
+ }
+
+ if (size + n > limit) {
+ n = (ssize_t) (limit - size);
+ }
+ }
+
if (prev == chain->buf->last) {
- iov->iov_len += chain->buf->end - chain->buf->last;
+ iov->iov_len += n;
} else {
if (vec.nelts >= IOV_MAX) {
}
iov->iov_base = (void *) chain->buf->last;
- iov->iov_len = chain->buf->end - chain->buf->last;
+ iov->iov_len = n;
}
- size += chain->buf->end - chain->buf->last;
+ size += n;
prev = chain->buf->end;
chain = chain->next;
}
typedef ssize_t (*ngx_recv_pt)(ngx_connection_t *c, u_char *buf, size_t size);
-typedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in);
+typedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in,
+ off_t limit);
typedef ssize_t (*ngx_send_pt)(ngx_connection_t *c, u_char *buf, size_t size);
typedef ngx_chain_t *(*ngx_send_chain_pt)(ngx_connection_t *c, ngx_chain_t *in,
off_t limit);
ssize_t ngx_udp_wsarecv(ngx_connection_t *c, u_char *buf, size_t size);
ssize_t ngx_udp_overlapped_wsarecv(ngx_connection_t *c, u_char *buf,
size_t size);
-ssize_t ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain);
+ssize_t ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit);
ssize_t ngx_wsasend(ngx_connection_t *c, u_char *buf, size_t size);
ssize_t ngx_overlapped_wsasend(ngx_connection_t *c, u_char *buf, size_t size);
ngx_chain_t *ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in,
ssize_t
-ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain)
+ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit)
{
int rc;
u_char *prev;
u_long bytes, flags;
- size_t size;
+ size_t n, size;
ngx_err_t err;
ngx_array_t vec;
ngx_event_t *rev;
/* coalesce the neighbouring bufs */
while (chain) {
+ n = chain->buf->end - chain->buf->last;
+
+ if (limit) {
+ if (size >= (size_t) limit) {
+ break;
+ }
+
+ if (size + n > (size_t) limit) {
+ n = (size_t) limit - size;
+ }
+ }
+
if (prev == chain->buf->last) {
- wsabuf->len += chain->buf->end - chain->buf->last;
+ wsabuf->len += n;
} else {
wsabuf = ngx_array_push(&vec);
}
wsabuf->buf = (char *) chain->buf->last;
- wsabuf->len = chain->buf->end - chain->buf->last;
+ wsabuf->len = n;
}
- size += chain->buf->end - chain->buf->last;
+ size += n;
prev = chain->buf->end;
chain = chain->next;
}