Jump to content

  • Log In with Google      Sign In   
  • Create Account


(non)blocking?


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
2 replies to this topic

#1 xSuiCidEx   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2000 - 04:15 AM

im setting up a dos program to be the server for a game im working on, and i want to use nonblocking mode and not use windows messages to notify me of writing/reading access to the sockets because i plan to port it to linux later down the road alright, so everything else works fine, but within the infinite while loop, i have: for(int i = 1; i <= 10; i++){ //do some code } and the for loop doesn''t execute the code at all....its like it''s ignoring every single for loop in the program, but doing evetything else fine....i was wondering if this is maybe because of nonblocking not being totally set up right? and its blocking and not causing my loops to execute? thats the only thing i can think of...heres how im setting nonblocking mode for my listen socket: unsigned long Options = 1; ioctlsocket(ListenSock, FIONBIO, &Options); this is called right after i create the socket using socket()....after them calls i then bind() and listen() and go through the infinite while loop and it works fine for accepting new connectionsthis is in the infinite loop btw) FD_SET(ListenSock, &RecvFDS); select(0, &RecvFDS, &SendFDS, &ErrorFDS, &TVal); if(FD_ISSET(ListenSock, &RecvFDS)){ OpenSock = GetOpenSock(); FD_CLR(Socks[OpenSock].Socket, &Socks[OpenSock].RecvFDS); FD_CLR(Socks[OpenSock].Socket, &Socks[OpenSock].SendFDS); Socks[OpenSock].SINLen = sizeof(sockaddr_in); Socks[OpenSock].Socket = accept(ListenSock, (struct sockaddr*)&Socks[OpenSock].SIN, &Socks[OpenSock].SINLen); ioctlsocket(Socks[OpenSock].Socket, FIONBIO, &Options); FD_SET(Socks[OpenSock].Socket, &Socks[OpenSock].RecvFDS); FD_SET(Socks[OpenSock].Socket, &Socks[OpenSock].SendFDS); Socks[OpenSock].Active = TRUE; printf("Accepted: %i\n", OpenSock); } then it loops through all the active sockets using a for loop, if they are active it checks them for data to write/read, but the loop isn''t being preformed...i use the same checking process for the listensock as all the other client sockets i hope this is enough information for someone to help me with...or maybe a few of u have had this same problem thanx

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 10 March 2000 - 01:15 PM

After looking at your code, it seems that your array ''Sock'' contains a class or struct that has two fd_sets (RecvFDS and SendFDS) in it, and that you''re adding that socket to it''s own set. This is not the way the fd_sets are supposed to be used at all.

You should have only one fd_set for Recv, Send, and possibly Exceptions. Use FD_ZERO to clear each set before a call to select(), and then loop over your array ''Sock'' and use FD_SET to add them to the Recv and Send sets. Then call select() with the sets. I believe you have to FD_ZERO and reset the fd_sets before every call to select(), because the function itself changes the data in the sets in such a way that they can''t be reused.

So:

fd_set recv, send, except;

FD_ZERO(&recv);
FD_ZERO(&send);
FD_ZERO(&except);

for(int i = 0; i < numSocks; i++) {
FD_SET(Sock.Socket, &recv);
FD_SET(Sock[i].Socket, &send);
FD_SET(Sock[i].Socket, &except);
}

FD_SET(ListenSock, &recv);

select(0, &recv, &send, &except, &tv);

if(FD_ISSET(ListenSock, &recv)) {
AcceptNewConenction();
}

for(int i = 0; i < numSocks; i++) {
if(FD_ISSET(Sock[i].Socket, &recv))
RecvData(Sock[i]);
if(FD_ISSET(Sock[i].Socket, &send))
SendData(Sock[i]);
if(FD_ISSET(Sock[i].Socket, &except))
HandleException(Sock[i]);
}

I hope to hell that looks right after I post...

- genovov


#3 genovov   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 March 2000 - 01:19 PM

Bah, that was me...




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