Move 'connGetSocketError' to 'anetGetError'
getsockopt is part of TCP, rename 'connGetSocketError' to 'anetGetError', and move it into anet.c. Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
This commit is contained in:
parent
dca5c6ff11
commit
8045e26efa
@ -62,6 +62,15 @@ static void anetSetError(char *err, const char *fmt, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
int anetGetError(int fd) {
|
||||
int sockerr = 0;
|
||||
socklen_t errlen = sizeof(sockerr);
|
||||
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &sockerr, &errlen) == -1)
|
||||
sockerr = errno;
|
||||
return sockerr;
|
||||
}
|
||||
|
||||
int anetSetBlock(char *err, int fd, int non_block) {
|
||||
int flags;
|
||||
|
||||
|
@ -74,5 +74,6 @@ int anetFormatAddr(char *fmt, size_t fmt_len, char *ip, int port);
|
||||
int anetFormatFdAddr(int fd, char *buf, size_t buf_len, int fd_to_str_type);
|
||||
int anetPipe(int fds[2], int read_flags, int write_flags);
|
||||
int anetSetSockMarkId(char *err, int fd, uint32_t id);
|
||||
int anetGetError(int fd);
|
||||
|
||||
#endif
|
||||
|
@ -264,8 +264,6 @@ static inline const char *connGetInfo(connection *conn, char *buf, size_t buf_le
|
||||
return buf;
|
||||
}
|
||||
|
||||
int connGetSocketError(connection *conn);
|
||||
|
||||
/* anet-style wrappers to conns */
|
||||
int connBlock(connection *conn);
|
||||
int connNonBlock(connection *conn);
|
||||
|
12
src/socket.c
12
src/socket.c
@ -255,7 +255,7 @@ static void connSocketEventHandler(struct aeEventLoop *el, int fd, void *clientD
|
||||
if (conn->state == CONN_STATE_CONNECTING &&
|
||||
(mask & AE_WRITABLE) && conn->conn_handler) {
|
||||
|
||||
int conn_error = connGetSocketError(conn);
|
||||
int conn_error = anetGetError(conn->fd);
|
||||
if (conn_error) {
|
||||
conn->last_errno = conn_error;
|
||||
conn->state = CONN_STATE_ERROR;
|
||||
@ -358,16 +358,6 @@ ConnectionType CT_Socket = {
|
||||
.get_type = connSocketGetType
|
||||
};
|
||||
|
||||
|
||||
int connGetSocketError(connection *conn) {
|
||||
int sockerr = 0;
|
||||
socklen_t errlen = sizeof(sockerr);
|
||||
|
||||
if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &sockerr, &errlen) == -1)
|
||||
sockerr = errno;
|
||||
return sockerr;
|
||||
}
|
||||
|
||||
int connPeerToString(connection *conn, char *ip, size_t ip_len, int *port) {
|
||||
if (anetFdToString(conn ? conn->fd : -1, ip, ip_len, port, FD_TO_PEER_NAME) == -1) {
|
||||
if (conn) conn->last_errno = errno;
|
||||
|
@ -595,7 +595,7 @@ static void tlsHandleEvent(tls_connection *conn, int mask) {
|
||||
|
||||
switch (conn->c.state) {
|
||||
case CONN_STATE_CONNECTING:
|
||||
conn_error = connGetSocketError((connection *) conn);
|
||||
conn_error = anetGetError(conn->c.fd);
|
||||
if (conn_error) {
|
||||
conn->c.last_errno = conn_error;
|
||||
conn->c.state = CONN_STATE_ERROR;
|
||||
|
Loading…
x
Reference in New Issue
Block a user