Wait for an event on one of the sockets.
Definition at line 483 of file Channel.h. References HandleError(), HandleIdle(), ILOG_DEBUG, mCallbackOnIdle, mMsgSock, mMsgSockEvent, mPort, mSock, mSockConnected, and mSockEvent. Referenced by Serve(). 00484 { 00485 ILOG_DEBUG("Waiting for socket event"); 00486 int nRet; 00487 int i = 0; 00488 do 00489 { 00490 // Wait for readable state. After accept() this indicates that 00491 // data has been received, so recv() will succeed. 00492 fd_set readSet; 00493 FD_ZERO(&readSet); 00494 for (int s=0 ; s<mSock.size() ; s++) 00495 { 00496 if (mSockConnected[s]) 00497 { 00498 FD_SET(mMsgSock[s], &readSet); 00499 ILOG_DEBUG(" checking on " << mPort+s); 00500 } 00501 } 00502 // Wait for writable state. After listen() this indicates that 00503 // a connection is pending, so accept() will succeed. 00504 // Oops, on linux this doesn't work, so use readSet. 00505 //fd_set writeSet; 00506 //FD_ZERO(&writeSet); 00507 for (int s=0 ; s<mSock.size() ; s++) 00508 { 00509 if (!mSockConnected[s]) 00510 { 00511 //FD_SET(mSock[s], &writeSet); 00512 FD_SET(mSock[s], &readSet); 00513 ILOG_DEBUG(" checking on " << mPort+s); 00514 } 00515 } 00516 if (mCallbackOnIdle) 00517 { 00518 struct timeval timeOut; 00519 timeOut.tv_sec = 0; 00520 timeOut.tv_usec = 100000 * i; 00521 if (i < 9) 00522 i++; 00523 //nRet = select(FD_SETSIZE, &readSet, &writeSet, 0, &timeOut); 00524 nRet = select(FD_SETSIZE, &readSet, 0, 0, &timeOut); 00525 } 00526 else 00527 { 00528 //nRet = select(FD_SETSIZE, &readSet, &writeSet, 0, 0); 00529 nRet = select(FD_SETSIZE, &readSet, 0, 0, 0); 00530 } 00531 if (nRet == SOCKET_ERROR) 00532 { 00533 HandleError("WaitForSocketEvent: select", true); 00534 return -1; 00535 } 00536 if (nRet == 0) 00537 { 00538 if (mCallbackOnIdle) 00539 HandleIdle(); 00540 } 00541 else 00542 { 00543 ILOG_DEBUG(nRet << " socket event(s)"); 00544 // find readable/writable socket, there may be more than one 00545 for (int s=0 ; s<mSock.size() ; s++) 00546 { 00547 mSockEvent[s] = false; 00548 mMsgSockEvent[s] = false; 00549 if (!mSockConnected[s]) 00550 { 00551 //if (FD_ISSET(mSock[s], &writeSet)) 00552 if (FD_ISSET(mSock[s], &readSet)) 00553 mSockEvent[s] = true; 00554 } 00555 else 00556 { 00557 if (FD_ISSET(mMsgSock[s], &readSet)) 00558 mMsgSockEvent[s] = true; 00559 } 00560 } 00561 } 00562 } 00563 while (nRet == 0); 00564 return nRet; 00565 }
Here is the call graph for this function: ![]()
|