APUE course source code
guowenxue
3 hours ago 805b28fc2e633bcd9c823a4b23614378ebfd50a1
project/2.socketd/booster/socket.c
@@ -210,7 +210,7 @@
 *               $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);
@@ -270,6 +270,7 @@
    if( !sock )
        return -1;
    /* close and clear previous socket */
    socket_term(sock);
    /*+--------------------------------------------------+
@@ -284,7 +285,7 @@
    /* 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;
    }
@@ -326,6 +327,8 @@
        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;
        }
@@ -590,6 +593,7 @@
        return -2;
    }
    /* If keepintvl and keepcnt are both 0, the system default configuration will be used. */
    if(keepintvl || keepcnt)
    {
        /*