Added method to check if a socket handle is valid for select()ing it.

git-svn-id: http://yate.null.ro/svn/yate/trunk@2057 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2008-07-10 17:47:49 +00:00
parent 108eeb4f15
commit fbd1c99baf
2 changed files with 30 additions and 1 deletions

View File

@ -1004,15 +1004,30 @@ int Socket::readData(void* buffer, int length)
#endif
}
bool Socket::canSelect(SOCKET handle)
{
if (handle == invalidHandle())
return false;
#ifdef FD_SETSIZE
#ifndef _WINDOWS
if (handle >= FD_SETSIZE)
return false;
#endif
#endif
return true;
}
bool Socket::select(bool* readok, bool* writeok, bool* except, struct timeval* timeout)
{
if (!valid())
return false;
#ifdef FD_SETSIZE
#ifndef _WINDOWS
static bool localFail = true;
if (m_handle >= FD_SETSIZE) {
if (localFail) {
localFail = false;
Debug(DebugFail,"Socket::select: handle %d larger than compiled in maximum %d",
Debug(DebugGoOn,"Socket::select: handle %d larger than compiled in maximum %d",
m_handle,FD_SETSIZE);
}
return false;

View File

@ -4411,6 +4411,20 @@ public:
*/
SOCKET acceptHandle(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
/**
* Check if a socket handle can be used in select
* @param handle The socket handle to check
* @return True if the socket handle can be safely used in select
*/
static bool canSelect(SOCKET handle);
/**
* Check if this socket object can be used in a select
* @return True if this socket can be safely used in select
*/
inline bool canSelect() const
{ return canSelect(handle()); }
/**
* Create a new socket by peeling off an association from a SCTP socket
* @param assoc Identifier of the association to peel off