Commit dca5c6ff authored by zhenwei pi's avatar zhenwei pi
Browse files

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: default avatarzhenwei pi <pizhenwei@bytedance.com>
parent 22e74e47
...@@ -230,11 +230,40 @@ connection *connCreateAcceptedSocket(int fd); ...@@ -230,11 +230,40 @@ connection *connCreateAcceptedSocket(int fd);
connection *connCreateTLS(); connection *connCreateTLS();
connection *connCreateAcceptedTLS(int fd, int require_auth); connection *connCreateAcceptedTLS(int fd, int require_auth);
void connSetPrivateData(connection *conn, void *data); static inline int connGetState(connection *conn) {
void *connGetPrivateData(connection *conn); return conn->state;
int connGetState(connection *conn); }
int connHasWriteHandler(connection *conn);
int connHasReadHandler(connection *conn); /* 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); int connGetSocketError(connection *conn);
/* anet-style wrappers to conns */ /* anet-style wrappers to conns */
...@@ -248,7 +277,6 @@ int connRecvTimeout(connection *conn, long long ms); ...@@ -248,7 +277,6 @@ int connRecvTimeout(connection *conn, long long ms);
int connPeerToString(connection *conn, char *ip, size_t ip_len, int *port); 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 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); 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 */ /* Helpers for tls special considerations */
sds connTLSGetPeerCert(connection *conn); sds connTLSGetPeerCert(connection *conn);
......
...@@ -118,26 +118,6 @@ static int connSocketConnect(connection *conn, const char *addr, int port, const ...@@ -118,26 +118,6 @@ static int connSocketConnect(connection *conn, const char *addr, int port, const
return C_OK; 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 ------- */ /* ------ Pure socket connections ------- */
/* A very incomplete list of implementation-specific calls. Much of the above shall /* A very incomplete list of implementation-specific calls. Much of the above shall
...@@ -437,17 +417,3 @@ int connRecvTimeout(connection *conn, long long ms) { ...@@ -437,17 +417,3 @@ int connRecvTimeout(connection *conn, long long ms) {
return anetRecvTimeout(NULL, conn->fd, 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;
}
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