Welcome! Log In Create A New Profile

Advanced

Non-Blocking Sockets?

Posted by scanff 
Non-Blocking Sockets?
January 19, 2009 12:32AM
Hello all,

I'm having issues setting my TCP and UDP sockets to non-blocking. Is this an issue in the current libraries, is there a work around or am I doing something wrong. Here's my code for the connection socket. I browsed around the forum and found another post from months ago that said non-blocking sockets did not work, but nobody commented.

int client_connect(char* ip,int protocol)
{
    c_protocol = protocol;

    net_init();

    client_connected = false;
    connection_socket = net_socket(AF_INET, protocol == TCP ? SOCK_STREAM : SOCK_DGRAM,IPPROTO_IP);
    if (connection_socket == 0) return 0;

    memset(&client,0, sizeof(client));

    client.sin_addr.s_addr = inet_addr(ip);

    client.sin_family = AF_INET;
    client.sin_port = htons(CON_PORT);

    if(protocol == TCP)
        if (net_connect(connection_socket,(struct sockaddr*)&client,sizeof(client)) != 0) return 0;


    unsigned long flag = O_NONBLOCK;
    net_ioctl(connection_socket, FIONBIO, &flag);

    client_connected = true;
    mode = CLIENT;

    return 1;
}
Re: Non-Blocking Sockets?
January 19, 2009 12:35AM
res = net_fcntl (s, F_GETFL, 0);
res = net_fcntl (s, F_SETFL, res | 4);
Re: Non-Blocking Sockets?
January 19, 2009 12:53AM
Thank you very much :)
Re: Non-Blocking Sockets?
January 19, 2009 01:28AM
Also thanks from here :)
Re: Non-Blocking Sockets?
January 19, 2009 01:36AM
my pleasure. i tried tons of things to get this working too :)
i guess nobody cares, but i'll mention it anyway:
i wanted non-blocking sockets for hbc, but bushing epicfailed on reversing the required magic bit for me, so i bruteforced it until EAGAIN finally popped up ;)
Re: Non-Blocking Sockets?
January 19, 2009 04:33AM
I was told in another thread that ftpii uses nonblocking sockets, so that might be a source of more help if you still need it.
Sorry, only registered users may post in this forum.

Click here to login