diff options
author | Kenny Levinsen <kl@kl.wtf> | 2020-08-01 23:09:35 +0200 |
---|---|---|
committer | Kenny Levinsen <kl@kl.wtf> | 2020-08-01 23:13:44 +0200 |
commit | 2be0826959c68aa0dd756ee4437db1883887d8ce (patch) | |
tree | 4c9b89c122ff2a7e7168d81ab5f2ddca2b7e2cdb | |
parent | 7252558689827a095aa70ee6f30175e2e73eb36b (diff) |
connection: Shrink buffers from 1KB to 256B each
-rw-r--r-- | common/connection.c | 12 | ||||
-rw-r--r-- | include/connection.h | 4 |
2 files changed, 7 insertions, 9 deletions
diff --git a/common/connection.c b/common/connection.c index 2545e5d..0c2a0b6 100644 --- a/common/connection.c +++ b/common/connection.c @@ -9,8 +9,6 @@ #include "compiler.h" #include "connection.h" -#define CLEN (CMSG_LEN(MAX_FDS_OUT * sizeof(int))) - ALWAYS_INLINE static uint32_t connection_buffer_mask(const uint32_t idx) { return idx & (CONNECTION_BUFFER_SIZE - 1); } @@ -134,8 +132,8 @@ static void connection_buffer_close_fds(struct connection_buffer *buffer) { */ static void build_cmsg(struct connection_buffer *buffer, char *data, int *clen) { size_t size = connection_buffer_size(buffer); - if (size > MAX_FDS_OUT * sizeof(int)) { - size = MAX_FDS_OUT * sizeof(int); + if (size > MAX_FDS * sizeof(int)) { + size = MAX_FDS * sizeof(int); } if (size <= 0) { @@ -189,7 +187,7 @@ int connection_read(struct connection *connection) { struct iovec iov[2]; connection_buffer_put_iov(&connection->in, iov, &count); - char cmsg[CLEN]; + char cmsg[CMSG_LEN(CONNECTION_BUFFER_SIZE)]; struct msghdr msg = { .msg_name = NULL, .msg_namelen = 0, @@ -227,7 +225,7 @@ int connection_flush(struct connection *connection) { connection_buffer_get_iov(&connection->out, iov, &count); int clen; - char cmsg[CLEN]; + char cmsg[CMSG_LEN(CONNECTION_BUFFER_SIZE)]; build_cmsg(&connection->fds_out, cmsg, &clen); struct msghdr msg = { .msg_name = NULL, @@ -269,7 +267,7 @@ int connection_put(struct connection *connection, const void *data, size_t count } int connection_put_fd(struct connection *connection, int fd) { - if (connection_buffer_size(&connection->fds_out) == MAX_FDS_OUT * sizeof fd) { + if (connection_buffer_size(&connection->fds_out) == MAX_FDS * sizeof fd) { errno = EOVERFLOW; return -1; } diff --git a/include/connection.h b/include/connection.h index 6c57901..3e15403 100644 --- a/include/connection.h +++ b/include/connection.h @@ -4,9 +4,9 @@ #include <stddef.h> #include <stdint.h> -#define CONNECTION_BUFFER_SIZE 1024 +#define CONNECTION_BUFFER_SIZE 256 -#define MAX_FDS_OUT 8 +#define MAX_FDS (CONNECTION_BUFFER_SIZE / sizeof(int)) struct connection_buffer { uint32_t head, tail; |