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