summaryrefslogtreecommitdiff
path: root/src/unix.c
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2022-08-22 15:15:37 +0800
committerzhenwei pi <pizhenwei@bytedance.com>2022-08-22 15:15:37 +0800
commit45617385e72eb814c6548064835cf19cdf466a5b (patch)
tree26bc3790c2e8626e4c3c74a5aa3c214a389c4d92 /src/unix.c
parenteb94d6d36dec7323af5fb89a5899506d5c07adb1 (diff)
downloadredis-45617385e72eb814c6548064835cf19cdf466a5b.tar.gz
Use connection name of string
Suggested by Oran, use an array to store all the connection types instead of a linked list, and use connection name of string. The index of a connection is dynamically allocated. Currently we support max 8 connection types, include: - tcp - unix socket - tls and RDMA is in the plan, then we have another 4 types to support, it should be enough in a long time. Introduce 3 functions to get connection type by a fast path: - connectionTypeTcp() - connectionTypeTls() - connectionTypeUnix() Note that connectionByType() is designed to use only in unlikely code path. Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/unix.c')
-rw-r--r--src/unix.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/unix.c b/src/unix.c
index 924a9ddd2..97bef0db4 100644
--- a/src/unix.c
+++ b/src/unix.c
@@ -29,18 +29,18 @@
static ConnectionType CT_Unix;
-static int connUnixGetType(connection *conn) {
- (void) conn;
+static const char *connUnixGetType(connection *conn) {
+ UNUSED(conn);
return CONN_TYPE_UNIX;
}
static void connUnixEventHandler(struct aeEventLoop *el, int fd, void *clientData, int mask) {
- connectionByType(CONN_TYPE_SOCKET)->ae_handler(el, fd, clientData, mask);
+ connectionTypeTcp()->ae_handler(el, fd, clientData, mask);
}
static int connUnixAddr(connection *conn, char *ip, size_t ip_len, int *port, int remote) {
- return connectionByType(CONN_TYPE_SOCKET)->addr(conn, ip, ip_len, port, remote);
+ return connectionTypeTcp()->addr(conn, ip, ip_len, port, remote);
}
static connection *connCreateUnix(void) {
@@ -79,31 +79,31 @@ static void connUnixAcceptHandler(aeEventLoop *el, int fd, void *privdata, int m
}
static void connUnixClose(connection *conn) {
- connectionByType(CONN_TYPE_SOCKET)->close(conn);
+ connectionTypeTcp()->close(conn);
}
static int connUnixAccept(connection *conn, ConnectionCallbackFunc accept_handler) {
- return connectionByType(CONN_TYPE_SOCKET)->accept(conn, accept_handler);
+ return connectionTypeTcp()->accept(conn, accept_handler);
}
static int connUnixWrite(connection *conn, const void *data, size_t data_len) {
- return connectionByType(CONN_TYPE_SOCKET)->write(conn, data, data_len);
+ return connectionTypeTcp()->write(conn, data, data_len);
}
static int connUnixWritev(connection *conn, const struct iovec *iov, int iovcnt) {
- return connectionByType(CONN_TYPE_SOCKET)->writev(conn, iov, iovcnt);
+ return connectionTypeTcp()->writev(conn, iov, iovcnt);
}
static int connUnixRead(connection *conn, void *buf, size_t buf_len) {
- return connectionByType(CONN_TYPE_SOCKET)->read(conn, buf, buf_len);
+ return connectionTypeTcp()->read(conn, buf, buf_len);
}
static int connUnixSetWriteHandler(connection *conn, ConnectionCallbackFunc func, int barrier) {
- return connectionByType(CONN_TYPE_SOCKET)->set_write_handler(conn, func, barrier);
+ return connectionTypeTcp()->set_write_handler(conn, func, barrier);
}
static int connUnixSetReadHandler(connection *conn, ConnectionCallbackFunc func) {
- return connectionByType(CONN_TYPE_SOCKET)->set_read_handler(conn, func);
+ return connectionTypeTcp()->set_read_handler(conn, func);
}
static const char *connUnixGetLastError(connection *conn) {