log more info when socket bind fail

pull/37/head
YuQing 2019-09-29 14:53:25 +08:00
parent 28d175523d
commit 83f572820e
2 changed files with 8 additions and 2 deletions

View File

@ -114,6 +114,7 @@ int conn_pool_connect_server(ConnectionInfo *pConnection, \
return errno != 0 ? errno : EPERM; return errno != 0 ? errno : EPERM;
} }
SET_SOCKOPT_NOSIGPIPE(pConnection->sock);
if ((result=tcpsetnonblockopt(pConnection->sock)) != 0) if ((result=tcpsetnonblockopt(pConnection->sock)) != 0)
{ {
close(pConnection->sock); close(pConnection->sock);

View File

@ -648,6 +648,7 @@ int socketClientEx2(int af, const char *server_ip,
return -1; return -1;
} }
SET_SOCKOPT_NOSIGPIPE(sock);
if (flags != 0) if (flags != 0)
{ {
*err_no = fd_add_flags(sock, flags); *err_no = fd_add_flags(sock, flags);
@ -915,11 +916,13 @@ int nbaccept(int sock, const int timeout, int *err_no)
int socketBind2(int af, int sock, const char *bind_ipaddr, const int port) int socketBind2(int af, int sock, const char *bind_ipaddr, const int port)
{ {
sockaddr_convert_t convert; sockaddr_convert_t convert;
char bind_ip_prompt[256];
int result; int result;
convert.sa.addr.sa_family = af; convert.sa.addr.sa_family = af;
if (bind_ipaddr == NULL || *bind_ipaddr == '\0') if (bind_ipaddr == NULL || *bind_ipaddr == '\0')
{ {
*bind_ip_prompt = '\0';
if (af == AF_INET) if (af == AF_INET)
{ {
convert.len = sizeof(convert.sa.addr4); convert.len = sizeof(convert.sa.addr4);
@ -939,14 +942,16 @@ int socketBind2(int af, int sock, const char *bind_ipaddr, const int port)
{ {
return result; return result;
} }
sprintf(bind_ip_prompt, "bind ip %s, ", bind_ipaddr);
} }
if (bind(sock, &convert.sa.addr, convert.len) < 0) if (bind(sock, &convert.sa.addr, convert.len) < 0)
{ {
logError("file: "__FILE__", line: %d, " logError("file: "__FILE__", line: %d, "
"bind port %d failed, " "%sbind port %d failed, "
"errno: %d, error info: %s.", "errno: %d, error info: %s.",
__LINE__, port, errno, STRERROR(errno)); __LINE__, bind_ip_prompt, port,
errno, STRERROR(errno));
return errno != 0 ? errno : ENOMEM; return errno != 0 ? errno : ENOMEM;
} }