🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

FD_WRITE/READ

Started by
3 comments, last by Gaiiden 23 years, 7 months ago
OK, I''m confused on how you get an FD_WRITE and FD_READ message. I have a program to send a file over the net using Async sockets. I have the message handlers all set up. Now, when the client and the server connect, they transmit data - once. I beleive that is because of the FD_READ/WRITE messages created after the WSAAsyncSelect() function was called and then posted after the connection was established. I know data was sent successfully (I output some info that the server gets from the client). But after the first snd()/recv() - nothing else happens. I''m sending 500bytes each time around and I use send() and recv(), so the messages should be reenabled right? I read up on FD_WRITE and stuff and it says the FD_WRITE message is posted when there is info to send (by detecting a WSAEWOULDBLOCK). I think my FD_WRITE message isn''t reenabling, therefore there is no post for an FD_READ message on the server. Or something like that. I can t post the code to my FD_WRITE function if you want, it''s not that long. Thanks - I know you people are getting sick of hearing me gripe ============================== "Need more eeenput..." - #5, "Short Circuit" ==============================

Drew Sikora
Executive Producer
GameDev.net

Advertisement
Do you send data ONLY when you receive an FD_WRITE ?

FD_WRITE is sent once to tell that you can now send data on the socket. It is never sent again until a WSAWOULDBLOCK error occurs. If you get WSAWOULDBLOCK (meaning you can''t send anymore data on the socket), you will get an FD_WRITE message shortly after telling you the socket can send data again.

FD_READ doesn''t work that way tough.
Every time you receive something on the socket an FD_READ message is posted.

FD_READ/WRITE are made this way so you don''t have to poll the socket constantly to check if you can send or recv data.
so does that mean I should use a while() loop that keeps sending data in the FD_WRITE message handler until a WSAEWOULDBLOCK error is detected? Then it would break out and when the message is posted again, it would send as much as it can until another WSAEWOULDBLOCK error. Is that the best way to do it? (btw, I understand the FD_READ message now and know that its the WRITE not being called again that''s causing the problem)

==============================
"Need more eeenput..."

- #5, "Short Circuit"
==============================

Drew Sikora
Executive Producer
GameDev.net

yeah you just send data whenever you need to

make a packet queue and suck packets off, if you get a wouldblock, you need to back-pack the packet on top of the queue and probably set a bool to false; once you get the fd_write set the bool to true to turn on the packet sender again.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
OK, I got it now, thanks - took me a while I only sent data once per message call, I figured it would keep posting messages. I''ll just stick in that loop....

==============================
"Need more eeenput..."

- #5, "Short Circuit"
==============================

Drew Sikora
Executive Producer
GameDev.net

This topic is closed to new replies.

Advertisement