summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2022-07-27 09:30:38 +0800
committerzhenwei pi <pizhenwei@bytedance.com>2022-08-22 15:01:01 +0800
commitdca5c6ff114b69213ee3c14530e0ed20169d86b0 (patch)
tree2d7b41ddfb40c953f224ae08b763f13130ecf4df
parent22e74e4720f6f4629389d42fb344c876b73437bf (diff)
downloadredis-dca5c6ff114b69213ee3c14530e0ed20169d86b0.tar.gz
Move several conn functions to connection.h
These functions are really short enough and they are the connection functions, separate them from the socket source. Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
-rw-r--r--src/connection.h40
-rw-r--r--src/socket.c34
2 files changed, 34 insertions, 40 deletions
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=<fdnum>" 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=<fdnum>" 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;
-}
-