Added static method to check at runtime if Socket::select() is efficient.

Use select() on the MGCP reader socket if it worths.


git-svn-id: http://voip.null.ro/svn/yate@3798 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2010-11-05 16:08:11 +00:00
parent f359578193
commit 3853b37773
3 changed files with 20 additions and 0 deletions

View File

@ -1503,6 +1503,15 @@ int Socket::readData(void* buffer, int length)
#endif
}
bool Socket::efficientSelect()
{
#if defined(_WINDOWS) || defined(HAVE_POLL)
return true;
#else
return false;
#endif
}
bool Socket::canSelect(SOCKET handle)
{
if (handle == invalidHandle())

View File

@ -335,6 +335,11 @@ bool MGCPEngine::receive(unsigned char* buffer, SocketAddr& addr)
{
if (!m_socket.valid())
return false;
if (Socket::efficientSelect() && m_socket.canSelect()) {
bool canRead = false;
if (m_socket.select(&canRead,0,0,Thread::idleUsec()) && !canRead)
return false;
}
int len = maxRecvPacket();
int rd = m_socket.recvFrom(buffer,len,addr);
if (rd == Socket::socketError()) {

View File

@ -5771,6 +5771,12 @@ public:
*/
SOCKET acceptHandle(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
/**
* Check if select() is efficient on this platform and worth using frequently
* @return True if select() is efficiently implemented
*/
static bool efficientSelect();
/**
* Check if a socket handle can be used in select
* @param handle The socket handle to check