Applied patch [ 864469 ] WaitForAccept(): 100% CPU Usage (NON-GUI application)
(Alex Thuering) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25119 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
7b519e5e0c
commit
b1a8a61082
@ -678,6 +678,10 @@ bool wxSocketBase::_Wait(long seconds,
|
|||||||
else
|
else
|
||||||
timeout = m_timeout * 1000;
|
timeout = m_timeout * 1000;
|
||||||
|
|
||||||
|
#if !defined(wxUSE_GUI) || !wxUSE_GUI
|
||||||
|
GSocket_SetTimeout(m_socket, timeout);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Wait in an active polling loop.
|
// Wait in an active polling loop.
|
||||||
//
|
//
|
||||||
// NOTE: We duplicate some of the code in OnRequest, but this doesn't
|
// NOTE: We duplicate some of the code in OnRequest, but this doesn't
|
||||||
|
@ -759,15 +759,15 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
|
|||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
fd_set writefds;
|
fd_set writefds;
|
||||||
fd_set exceptfds;
|
fd_set exceptfds;
|
||||||
static const struct timeval tv = { 0, 0 };
|
|
||||||
|
|
||||||
assert(socket != NULL);
|
assert(socket != NULL);
|
||||||
|
|
||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
FD_ZERO(&writefds);
|
FD_ZERO(&writefds);
|
||||||
FD_ZERO(&exceptfds);
|
FD_ZERO(&exceptfds);
|
||||||
FD_SET(socket->m_fd, &readfds);
|
FD_SET(socket->m_fd, &readfds);
|
||||||
FD_SET(socket->m_fd, &writefds);
|
if (flags & GSOCK_OUTPUT_FLAG)
|
||||||
|
FD_SET(socket->m_fd, &writefds);
|
||||||
FD_SET(socket->m_fd, &exceptfds);
|
FD_SET(socket->m_fd, &exceptfds);
|
||||||
|
|
||||||
/* Check 'sticky' CONNECTION flag first */
|
/* Check 'sticky' CONNECTION flag first */
|
||||||
@ -784,7 +784,8 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Try select now */
|
/* Try select now */
|
||||||
if (select(socket->m_fd + 1, &readfds, &writefds, &exceptfds, &tv) <= 0)
|
if (select(socket->m_fd + 1, &readfds, &writefds, &exceptfds,
|
||||||
|
&socket->m_timeout) <= 0)
|
||||||
{
|
{
|
||||||
/* What to do here? */
|
/* What to do here? */
|
||||||
return (result & flags);
|
return (result & flags);
|
||||||
@ -795,7 +796,7 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
|
|||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
if (recv(socket->m_fd, &c, 1, MSG_PEEK) > 0)
|
if (!socket->m_stream || recv(socket->m_fd, &c, 1, MSG_PEEK) > 0)
|
||||||
{
|
{
|
||||||
result |= GSOCK_INPUT_FLAG;
|
result |= GSOCK_INPUT_FLAG;
|
||||||
}
|
}
|
||||||
|
@ -914,8 +914,8 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
|
|||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
/* Do not use a static struct, Linux can garble it */
|
/* Do not use a static struct, Linux can garble it */
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = socket->m_timeout / 1000;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = (socket->m_timeout % 1000) / 1000;
|
||||||
|
|
||||||
assert(socket != NULL);
|
assert(socket != NULL);
|
||||||
|
|
||||||
@ -923,7 +923,8 @@ GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
|
|||||||
FD_ZERO(&writefds);
|
FD_ZERO(&writefds);
|
||||||
FD_ZERO(&exceptfds);
|
FD_ZERO(&exceptfds);
|
||||||
FD_SET(socket->m_fd, &readfds);
|
FD_SET(socket->m_fd, &readfds);
|
||||||
FD_SET(socket->m_fd, &writefds);
|
if (flags & GSOCK_OUTPUT_FLAG)
|
||||||
|
FD_SET(socket->m_fd, &writefds);
|
||||||
FD_SET(socket->m_fd, &exceptfds);
|
FD_SET(socket->m_fd, &exceptfds);
|
||||||
|
|
||||||
/* Check 'sticky' CONNECTION flag first */
|
/* Check 'sticky' CONNECTION flag first */
|
||||||
|
Loading…
Reference in New Issue
Block a user