Changeset 14399 for titan/plugins


Ignore:
Timestamp:
03/03/12 16:07:38 (12 years ago)
Author:
nit
Message:

[titan] set 5 sek timeout for connect

File:
1 edited

Legend:

Unmodified
Added
Removed
  • titan/plugins/networkbrowser/netlib/smbinfo.c

    r14398 r14399  
    14881488int open_socket_out(struct in_addr *addr, int port )
    14891489{
     1490        struct timeval timeout;
    14901491  struct sockaddr_in sock_out;
    1491   int res;
     1492  int res, ret = 0;
    14921493
    14931494  /* create a socket to write to */
     
    15081509#if DEBUG
    15091510  printf("Connecting to %s at port %d\n",inet_ntoa(*addr),port);
    1510   #endif
     1511#endif
     1512
     1513        fcntl(res, F_SETFL, fcntl(res, F_GETFL) | O_NONBLOCK);
     1514        fd_set wfds;
     1515
    15111516  /* and connect it to the destination */
    1512   if (connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out))<0)
    1513         {
    1514 #if DEBUG
    1515                 printf("connect error: %s\n",strerror(errno));
    1516 #endif
    1517                 close(res);
    1518                 return -1;
     1517  ret = connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out));
     1518  if(ret < 0)
     1519        {
     1520                if(errno == EINTR || errno == EINPROGRESS)
     1521                {
     1522                        FD_ZERO(&wfds);
     1523                        FD_SET(res, &wfds);
     1524
     1525                        timeout.tv_sec = 5; // 5sek timeout
     1526                        timeout.tv_usec = 0;
     1527                       
     1528                        ret = TEMP_FAILURE_RETRY(select(res + 1, NULL, &wfds, NULL, &timeout));
     1529
     1530                        if(ret == 1 && FD_ISSET(res, &wfds))
     1531                        {
     1532                                /*
     1533                                ret = getsockopt(*fd, SOL_SOCKET, SO_ERROR, &optval, &optlen);
     1534                                if(ret == -1)   
     1535                                {
     1536                                        close(res);
     1537                                        return -1;
     1538                                }
     1539                                if(optval == 0) return 0;
     1540                                close(res);
     1541                                return -1;
     1542                                */
     1543                                fcntl(res, F_SETFL, fcntl(res, F_GETFL) & ~O_NONBLOCK);
     1544                                return res;
     1545                        }
     1546                }
     1547                       
     1548                if(ret <= 0)
     1549                {
     1550#if DEBUG
     1551                                printf("connect error: %s\n",strerror(errno));
     1552#endif
     1553                        close(res);
     1554                        return -1;
     1555                }
    15191556        }
    15201557
     1558        fcntl(res, F_SETFL, fcntl(res, F_GETFL) & ~O_NONBLOCK);
    15211559  return res;
    15221560}
Note: See TracChangeset for help on using the changeset viewer.