is there code for non blocking TCP recv call ?

ht_main1
Posts: 28
Joined: Sun Oct 06, 2019 6:08 pm

is there code for non blocking TCP recv call ?

Postby ht_main1 » Fri Nov 01, 2019 7:04 am

hi, i am using TCP socket for multiple connection,
i want to use non blocking recv call, i tried using

Code: Select all

fcntl(connect_socket, F_SETFL, O_NONBLOCK); /* Change the socket into non-blocking state	*/
function after

Code: Select all

connect_socket = accept(server_socket, (struct sockaddr *)&client_addr, &socklen);
but i dont see any change in recv call, it blocks the function and i receive both continuous data from 2 socket instance/client.
how to receive data from tcp socket without blocking the call ? incase i have multiple socket connection i need to be non blocking.

need help in this

regards
Sushant

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: is there code for non blocking TCP recv call ?

Postby ESP_Sprite » Fri Nov 01, 2019 9:05 am

Not an answer to your question, but the canonical way to handle multiple sockets is to use one select() call on all of them, then handle whichever becomes active.

ht_main1
Posts: 28
Joined: Sun Oct 06, 2019 6:08 pm

Re: is there code for non blocking TCP recv call ?

Postby ht_main1 » Sat Nov 02, 2019 11:23 am

ESP_Sprite wrote:
Fri Nov 01, 2019 9:05 am
Not an answer to your question, but the canonical way to handle multiple sockets is to use one select() call on all of them, then handle whichever becomes active.
thanks for your input i have read and tried implementing select ,
it works

Who is online

Users browsing this forum: No registered users and 131 guests