views:

42

answers:

0

Hello,

How to write code which specifies timeout to BSD sockets connect syscall ? I writing iPhone application and i need to wait long time to get response from connect syscall. Any Examples ? Thanks

Now i have something like this:

host_name = NULL ;
host_name = gethostbyname([[host_value hostname] UTF8String]) ; 
if (host_name != NULL)
{
    struct sockaddr_in sin;
    sock = socket(AF_INET, SOCK_STREAM, 0);
    sin.sin_family = AF_INET;
    sin.sin_port = htons([[host_value port_number] intValue]);
    memcpy((char *)&sin.sin_addr,(char*)host_name->h_addr,host_name->h_length);
    if (connect(sock, (struct sockaddr*)(&sin),sizeof(struct sockaddr_in)) != 0) 
    {
       /* code */
    }
}