Unverified Commit cb78acb8 authored by zhenwei pi's avatar zhenwei pi Committed by GitHub
Browse files

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: default avatarzhenwei pi <pizhenwei@bytedance.com>
parent e775b34e
...@@ -114,14 +114,15 @@ typedef struct ConnectionType { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment