Jump to content

  • Log In with Google      Sign In   
  • Create Account


Non Blocking with recvfrom


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 gimp   Members   -  Reputation: 142

Like
Likes
Like

Posted 10 May 2000 - 01:21 PM

I''v being pouring over MSDN for hours and can''t find any info on specifically HOW to create a ''recvfrom'' that just fails if there is no data in the buffer. Any pointers on this would be appreciated... thanks chris

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9497

Like
Likes
Like

Posted 10 May 2000 - 02:04 PM

When selecting on a socket with WSAAsyncSelect(), the socket should automatically be set to non-blocking operation.

If not using the asynchronous extensions ioctlsocket() should be used with the FIONBIO command to set non-blocking mode.

ex:

SOCKET some_socket = socket(blah, blah, blah);
// fill in blah''s with correct address family, type and protocol
long arg = 1;
int retVal = ioctlsocket(some_socket, FIONBIO, &arg);


#3 gimp   Members   -  Reputation: 142

Like
Likes
Like

Posted 10 May 2000 - 04:29 PM

Thanks a lot. I''m wondering however if I am even coding this up correctly.

My server is a message router only. It collects packets from players, collates them, compresses them, then sends them out to all the other players.

My server app works by polling the socket. When it''s got a message it addes it to a queue. When 100ms has passed the loop enters the sending phase where it packages all the client requests and send them out to everyone with sendto.

Should I be using the event driven api''s in another thread? It would be more efficient on the cpu at least. I''d have to lock the list or take a copy when sending to ensure that new elements arn''t added to the queue array during sending though.

Do I have to worry about recieving multiple datagrams from multiple clients at the same time (UDP) or is there a queue behind recvfrom and I can just keep calling it until I get all the packets?

Thanks

Chris

#4 SiCrane   Moderators   -  Reputation: 9497

Like
Likes
Like

Posted 11 May 2000 - 11:59 AM

Depending on the scale of your project I would probably use asynchronous event notification or blocking sockets in multiple threads instead of a polling method.

Also a single call of recvfrom() on a UDP packet will return at most a single datagram.

#5 gimp   Members   -  Reputation: 142

Like
Likes
Like

Posted 12 May 2000 - 02:09 PM

I''ve gone with threads, they were a lot easier to implement than I expected.. All I need to do now is read up on semaphores so I can ''lock'' arrays so I don''t start sending something that is only half written.

Since I have multiple threads I have modified the reader back to be blocking.

My only concern remaining from the last mail was that... what happens if more packets come in that I can read. Do that sit in a queue that recvfrom reads from or are they lost?

thanks

#6 SiCrane   Moderators   -  Reputation: 9497

Like
Likes
Like

Posted 12 May 2000 - 02:14 PM

If more packets arrive than the incoming buffer can hold, packets will get dropped. Usually the buffer is something reasonable, so that as long as the rate you can consume the data is greater than rate that data arrives then there will usually not be a buffer overflow.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS