Support maxiov per connection type (#12234)
Rather than a fixed iovcnt for connWritev, support maxiov per connection type instead. A minor change to reduce memory for struct connection. Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
This commit is contained in:
parent
e775b34e81
commit
cb78acb865
@ -114,14 +114,15 @@ typedef struct ConnectionType {
|
|||||||
struct connection {
|
struct connection {
|
||||||
ConnectionType *type;
|
ConnectionType *type;
|
||||||
ConnectionState state;
|
ConnectionState state;
|
||||||
|
int last_errno;
|
||||||
|
int fd;
|
||||||
short int flags;
|
short int flags;
|
||||||
short int refs;
|
short int refs;
|
||||||
int last_errno;
|
unsigned short int iovcnt;
|
||||||
void *private_data;
|
void *private_data;
|
||||||
ConnectionCallbackFunc conn_handler;
|
ConnectionCallbackFunc conn_handler;
|
||||||
ConnectionCallbackFunc write_handler;
|
ConnectionCallbackFunc write_handler;
|
||||||
ConnectionCallbackFunc read_handler;
|
ConnectionCallbackFunc read_handler;
|
||||||
int fd;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CONFIG_BINDADDR_MAX 16
|
#define CONFIG_BINDADDR_MAX 16
|
||||||
|
@ -1787,8 +1787,9 @@ client *lookupClientByID(uint64_t id) {
|
|||||||
* and 'nwritten' is an output parameter, it means how many bytes server write
|
* and 'nwritten' is an output parameter, it means how many bytes server write
|
||||||
* to client. */
|
* to client. */
|
||||||
static int _writevToClient(client *c, ssize_t *nwritten) {
|
static int _writevToClient(client *c, ssize_t *nwritten) {
|
||||||
struct iovec iov[IOV_MAX];
|
|
||||||
int iovcnt = 0;
|
int iovcnt = 0;
|
||||||
|
int iovmax = min(IOV_MAX, c->conn->iovcnt);
|
||||||
|
struct iovec iov[iovmax];
|
||||||
size_t iov_bytes_len = 0;
|
size_t iov_bytes_len = 0;
|
||||||
/* If the static reply buffer is not empty,
|
/* If the static reply buffer is not empty,
|
||||||
* add it to the iov array for writev() as well. */
|
* add it to the iov array for writev() as well. */
|
||||||
@ -1804,7 +1805,7 @@ static int _writevToClient(client *c, ssize_t *nwritten) {
|
|||||||
listNode *next;
|
listNode *next;
|
||||||
clientReplyBlock *o;
|
clientReplyBlock *o;
|
||||||
listRewind(c->reply, &iter);
|
listRewind(c->reply, &iter);
|
||||||
while ((next = listNext(&iter)) && iovcnt < IOV_MAX && iov_bytes_len < NET_MAX_WRITES_PER_EVENT) {
|
while ((next = listNext(&iter)) && iovcnt < iovmax && iov_bytes_len < NET_MAX_WRITES_PER_EVENT) {
|
||||||
o = listNodeValue(next);
|
o = listNodeValue(next);
|
||||||
if (o->used == 0) { /* empty node, just release it and skip. */
|
if (o->used == 0) { /* empty node, just release it and skip. */
|
||||||
c->reply_bytes -= o->size;
|
c->reply_bytes -= o->size;
|
||||||
|
@ -78,6 +78,7 @@ static connection *connCreateSocket(void) {
|
|||||||
connection *conn = zcalloc(sizeof(connection));
|
connection *conn = zcalloc(sizeof(connection));
|
||||||
conn->type = &CT_Socket;
|
conn->type = &CT_Socket;
|
||||||
conn->fd = -1;
|
conn->fd = -1;
|
||||||
|
conn->iovcnt = IOV_MAX;
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
@ -462,6 +462,7 @@ static connection *createTLSConnection(int client_side) {
|
|||||||
tls_connection *conn = zcalloc(sizeof(tls_connection));
|
tls_connection *conn = zcalloc(sizeof(tls_connection));
|
||||||
conn->c.type = &CT_TLS;
|
conn->c.type = &CT_TLS;
|
||||||
conn->c.fd = -1;
|
conn->c.fd = -1;
|
||||||
|
conn->c.iovcnt = IOV_MAX;
|
||||||
conn->ssl = SSL_new(ctx);
|
conn->ssl = SSL_new(ctx);
|
||||||
return (connection *) conn;
|
return (connection *) conn;
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ static connection *connCreateUnix(void) {
|
|||||||
connection *conn = zcalloc(sizeof(connection));
|
connection *conn = zcalloc(sizeof(connection));
|
||||||
conn->type = &CT_Unix;
|
conn->type = &CT_Unix;
|
||||||
conn->fd = -1;
|
conn->fd = -1;
|
||||||
|
conn->iovcnt = IOV_MAX;
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user