Skip to content

Commit

Permalink
Win32: use only preallocated memory in send/recv chain functions.
Browse files Browse the repository at this point in the history
The ngx_wsasend_chain() and ngx_wsarecv_chain() functions were
modified to use only preallocated memory, and the number of
preallocated wsabufs was increased to 64.
  • Loading branch information
mdocguard committed Jul 5, 2021
1 parent b20768e commit b445d18
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/os/win32/ngx_wsarecv_chain.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <ngx_event.h>


#define NGX_WSABUFS 8
#define NGX_WSABUFS 64


ssize_t
Expand Down Expand Up @@ -57,6 +57,10 @@ ngx_wsarecv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit)
wsabuf->len += n;

} else {
if (vec.nelts == vec.nalloc) {
break;
}

wsabuf = ngx_array_push(&vec);
if (wsabuf == NULL) {
return NGX_ERROR;
Expand Down
26 changes: 15 additions & 11 deletions src/os/win32/ngx_wsasend_chain.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <ngx_event.h>


#define NGX_WSABUFS 8
#define NGX_WSABUFS 64


ngx_chain_t *
Expand Down Expand Up @@ -47,7 +47,7 @@ ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)

vec.elts = wsabufs;
vec.size = sizeof(WSABUF);
vec.nalloc = NGX_WSABUFS;
vec.nalloc = ngx_min(NGX_WSABUFS, ngx_max_wsabufs);
vec.pool = c->pool;

for ( ;; ) {
Expand All @@ -59,10 +59,8 @@ ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)

/* create the WSABUF and coalesce the neighbouring bufs */

for (cl = in;
cl && vec.nelts < ngx_max_wsabufs && send < limit;
cl = cl->next)
{
for (cl = in; cl && send < limit; cl = cl->next) {

if (ngx_buf_special(cl->buf)) {
continue;
}
Expand All @@ -77,6 +75,10 @@ ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
wsabuf->len += cl->buf->last - cl->buf->pos;

} else {
if (vec.nelts == vec.nalloc) {
break;
}

wsabuf = ngx_array_push(&vec);
if (wsabuf == NULL) {
return NGX_CHAIN_ERROR;
Expand Down Expand Up @@ -169,7 +171,7 @@ ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
vec.elts = wsabufs;
vec.nelts = 0;
vec.size = sizeof(WSABUF);
vec.nalloc = NGX_WSABUFS;
vec.nalloc = ngx_min(NGX_WSABUFS, ngx_max_wsabufs);
vec.pool = c->pool;

send = 0;
Expand All @@ -178,10 +180,8 @@ ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)

/* create the WSABUF and coalesce the neighbouring bufs */

for (cl = in;
cl && vec.nelts < ngx_max_wsabufs && send < limit;
cl = cl->next)
{
for (cl = in; cl && send < limit; cl = cl->next) {

if (ngx_buf_special(cl->buf)) {
continue;
}
Expand All @@ -196,6 +196,10 @@ ngx_overlapped_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
wsabuf->len += cl->buf->last - cl->buf->pos;

} else {
if (vec.nelts == vec.nalloc) {
break;
}

wsabuf = ngx_array_push(&vec);
if (wsabuf == NULL) {
return NGX_CHAIN_ERROR;
Expand Down

0 comments on commit b445d18

Please sign in to comment.