diff --git a/src/connection.h b/src/connection.h index dad2e2fd6..6e07f5c28 100644 --- a/src/connection.h +++ b/src/connection.h @@ -230,11 +230,40 @@ connection *connCreateAcceptedSocket(int fd); connection *connCreateTLS(); connection *connCreateAcceptedTLS(int fd, int require_auth); -void connSetPrivateData(connection *conn, void *data); -void *connGetPrivateData(connection *conn); -int connGetState(connection *conn); -int connHasWriteHandler(connection *conn); -int connHasReadHandler(connection *conn); +static inline int connGetState(connection *conn) { + return conn->state; +} + +/* Returns true if a write handler is registered */ +static inline int connHasWriteHandler(connection *conn) { + return conn->write_handler != NULL; +} + +/* Returns true if a read handler is registered */ +static inline int connHasReadHandler(connection *conn) { + return conn->read_handler != NULL; +} + +/* Associate a private data pointer with the connection */ +static inline void connSetPrivateData(connection *conn, void *data) { + conn->private_data = data; +} + +/* Get the associated private data pointer */ +static inline void *connGetPrivateData(connection *conn) { + return conn->private_data; +} + +/* Return a text that describes the connection, suitable for inclusion + * in CLIENT LIST and similar outputs. + * + * For sockets, we always return "fd=" to maintain compatibility. + */ +static inline const char *connGetInfo(connection *conn, char *buf, size_t buf_len) { + snprintf(buf, buf_len-1, "fd=%i", conn == NULL ? -1 : conn->fd); + return buf; +} + int connGetSocketError(connection *conn); /* anet-style wrappers to conns */ @@ -248,7 +277,6 @@ int connRecvTimeout(connection *conn, long long ms); int connPeerToString(connection *conn, char *ip, size_t ip_len, int *port); int connFormatFdAddr(connection *conn, char *buf, size_t buf_len, int fd_to_str_type); int connSockName(connection *conn, char *ip, size_t ip_len, int *port); -const char *connGetInfo(connection *conn, char *buf, size_t buf_len); /* Helpers for tls special considerations */ sds connTLSGetPeerCert(connection *conn); diff --git a/src/socket.c b/src/socket.c index f61ed2404..5372510d0 100644 --- a/src/socket.c +++ b/src/socket.c @@ -118,26 +118,6 @@ static int connSocketConnect(connection *conn, const char *addr, int port, const return C_OK; } -/* Returns true if a write handler is registered */ -int connHasWriteHandler(connection *conn) { - return conn->write_handler != NULL; -} - -/* Returns true if a read handler is registered */ -int connHasReadHandler(connection *conn) { - return conn->read_handler != NULL; -} - -/* Associate a private data pointer with the connection */ -void connSetPrivateData(connection *conn, void *data) { - conn->private_data = data; -} - -/* Get the associated private data pointer */ -void *connGetPrivateData(connection *conn) { - return conn->private_data; -} - /* ------ Pure socket connections ------- */ /* A very incomplete list of implementation-specific calls. Much of the above shall @@ -437,17 +417,3 @@ int connRecvTimeout(connection *conn, long long ms) { return anetRecvTimeout(NULL, conn->fd, ms); } -int connGetState(connection *conn) { - return conn->state; -} - -/* Return a text that describes the connection, suitable for inclusion - * in CLIENT LIST and similar outputs. - * - * For sockets, we always return "fd=" to maintain compatibility. - */ -const char *connGetInfo(connection *conn, char *buf, size_t buf_len) { - snprintf(buf, buf_len-1, "fd=%i", conn == NULL ? -1 : conn->fd); - return buf; -} -