Welcome! Log In Create A New Profile

Advanced

[nginx] Win32: use only preallocated memory in send/recv chain functions.

July 05, 2021 12:36PM
details: https://hg.nginx.org/nginx/rev/ecf2a9002b37
branches:
changeset: 7887:ecf2a9002b37
user: Ruslan Ermilov <ru@nginx.com>
date: Mon Jul 05 13:26:49 2021 +0300
description:
Win32: use only preallocated memory in send/recv chain functions.

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.

diffstat:

src/os/win32/ngx_wsarecv_chain.c | 6 +++++-
src/os/win32/ngx_wsasend_chain.c | 26 +++++++++++++++-----------
2 files changed, 20 insertions(+), 12 deletions(-)

diffs (101 lines):

diff -r 7f5e3595caff -r ecf2a9002b37 src/os/win32/ngx_wsarecv_chain.c
--- a/src/os/win32/ngx_wsarecv_chain.c Mon Jul 05 13:09:23 2021 +0300
+++ b/src/os/win32/ngx_wsarecv_chain.c Mon Jul 05 13:26:49 2021 +0300
@@ -10,7 +10,7 @@
#include <ngx_event.h>


-#define NGX_WSABUFS 8
+#define NGX_WSABUFS 64


ssize_t
@@ -57,6 +57,10 @@ ngx_wsarecv_chain(ngx_connection_t *c, n
wsabuf->len += n;

} else {
+ if (vec.nelts == vec.nalloc) {
+ break;
+ }
+
wsabuf = ngx_array_push(&vec);
if (wsabuf == NULL) {
return NGX_ERROR;
diff -r 7f5e3595caff -r ecf2a9002b37 src/os/win32/ngx_wsasend_chain.c
--- a/src/os/win32/ngx_wsasend_chain.c Mon Jul 05 13:09:23 2021 +0300
+++ b/src/os/win32/ngx_wsasend_chain.c Mon Jul 05 13:26:49 2021 +0300
@@ -10,7 +10,7 @@
#include <ngx_event.h>


-#define NGX_WSABUFS 8
+#define NGX_WSABUFS 64


ngx_chain_t *
@@ -47,7 +47,7 @@ ngx_wsasend_chain(ngx_connection_t *c, n

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 ( ;; ) {
@@ -59,10 +59,8 @@ ngx_wsasend_chain(ngx_connection_t *c, n

/* 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;
}
@@ -77,6 +75,10 @@ ngx_wsasend_chain(ngx_connection_t *c, n
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;
@@ -169,7 +171,7 @@ ngx_overlapped_wsasend_chain(ngx_connect
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;
@@ -178,10 +180,8 @@ ngx_overlapped_wsasend_chain(ngx_connect

/* 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;
}
@@ -196,6 +196,10 @@ ngx_overlapped_wsasend_chain(ngx_connect
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;
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Win32: use only preallocated memory in send/recv chain functions.

ru@nginx.com 588 July 05, 2021 12:36PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 170
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready