| | |
| | | * $sock: socket context pointer |
| | | * return value: 1: connected 0:disconnected |
| | | */ |
| | | int socket_connected(socket_t *sock) |
| | | int socket_check(socket_t *sock) |
| | | { |
| | | struct tcp_info info; |
| | | int len=sizeof(info); |
| | |
| | | if( !sock ) |
| | | return -1; |
| | | |
| | | /* close and clear previous socket */ |
| | | socket_term(sock); |
| | | |
| | | /*+--------------------------------------------------+ |
| | |
| | | /* If $host is a valid IP address, then don't use name resolution */ |
| | | if( inet_aton(sock->host, &inaddr) ) |
| | | { |
| | | //log_info("%s is a valid IP address, don't use domain name resolution.\n", sock->host); |
| | | //log_info("Hostname %s is an IP address, so domain resolution can be skipped.\n", sock->host); |
| | | hints.ai_flags |= AI_NUMERICHOST; |
| | | } |
| | | |
| | |
| | | if( 0 == rv ) |
| | | { |
| | | sock->fd = sockfd; |
| | | sock->connected = 1; |
| | | socket_set_keepalive(sockfd, 10, 3); |
| | | log_info("Connect to server[%s:%d] on fd[%d] successfully!\n", sock->host, sock->port, sockfd); |
| | | break; |
| | | } |
| | |
| | | return -2; |
| | | } |
| | | |
| | | /* If keepintvl and keepcnt are both 0, the system default configuration will be used. */ |
| | | if(keepintvl || keepcnt) |
| | | { |
| | | /* |