remove the badle defined and apparently unnecessary wxSocketImpl::m_detected field
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57608 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -308,8 +308,6 @@ public:
|
||||
|
||||
struct timeval m_timeout;
|
||||
|
||||
wxSocketEventFlags m_detected;
|
||||
|
||||
protected:
|
||||
wxSocketImpl(wxSocketBase& wxsocket);
|
||||
|
||||
|
@@ -72,17 +72,13 @@ private:
|
||||
|
||||
// enable or disable notifications for socket input/output events
|
||||
void EnableEvents() { DoEnableEvents(true); }
|
||||
void DisableEvents() { DoEnableEvents(false);
|
||||
}
|
||||
void DisableEvents() { DoEnableEvents(false); }
|
||||
|
||||
// really enable or disable socket input/output events
|
||||
void DoEnableEvents(bool enable);
|
||||
|
||||
|
||||
// enable or disable events for the given event
|
||||
//
|
||||
// notice that these functions also update m_detected: EnableEvent() clears
|
||||
// the corresponding bit in it and DisableEvent() sets it
|
||||
void EnableEvent(wxSocketNotify event);
|
||||
void DisableEvent(wxSocketNotify event);
|
||||
|
||||
@@ -99,9 +95,6 @@ protected:
|
||||
|
||||
// the events which are currently enabled for this socket, combination of
|
||||
// wxFDIO_INPUT and wxFDIO_OUTPUT values
|
||||
//
|
||||
// TODO: this overlaps with m_detected but the semantics of the latter are
|
||||
// very unclear so I don't dare to remove it right now
|
||||
int m_enabledCallbacks;
|
||||
|
||||
private:
|
||||
|
@@ -154,7 +154,6 @@ wxSocketImpl::wxSocketImpl(wxSocketBase& wxsocket)
|
||||
: m_wxsocket(&wxsocket)
|
||||
{
|
||||
m_fd = INVALID_SOCKET;
|
||||
m_detected = 0;
|
||||
m_local = NULL;
|
||||
m_peer = NULL;
|
||||
m_error = wxSOCKET_NOERROR;
|
||||
@@ -377,7 +376,7 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket)
|
||||
{
|
||||
wxSockAddr from;
|
||||
WX_SOCKLEN_T fromlen = sizeof(from);
|
||||
const int fd = accept(m_fd, &from, &fromlen);
|
||||
const SOCKET fd = accept(m_fd, &from, &fromlen);
|
||||
|
||||
if ( fd == INVALID_SOCKET )
|
||||
return NULL;
|
||||
@@ -414,8 +413,6 @@ void wxSocketImpl::Shutdown()
|
||||
shutdown(m_fd, 1 /* SD_SEND */);
|
||||
Close();
|
||||
}
|
||||
|
||||
m_detected = wxSOCKET_LOST_FLAG;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1093,8 +1090,6 @@ wxSocketBase& wxSocketBase::Discard()
|
||||
wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags,
|
||||
const timeval *timeout)
|
||||
{
|
||||
wxSocketEventFlags result = 0;
|
||||
|
||||
if ( m_fd == INVALID_SOCKET )
|
||||
return (wxSOCKET_LOST_FLAG & flags);
|
||||
|
||||
@@ -1104,63 +1099,53 @@ wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags,
|
||||
else
|
||||
tv.tv_sec = tv.tv_usec = 0;
|
||||
|
||||
fd_set readfds;
|
||||
fd_set writefds;
|
||||
fd_set exceptfds;
|
||||
wxFD_ZERO(&readfds);
|
||||
wxFD_ZERO(&writefds);
|
||||
// prepare the FD sets, passing NULL for the one(s) we don't use
|
||||
fd_set
|
||||
readfds, *preadfds = NULL,
|
||||
writefds, *pwritefds = NULL,
|
||||
exceptfds; // always want to know about errors
|
||||
|
||||
if ( flags & wxSOCKET_INPUT_FLAG )
|
||||
{
|
||||
preadfds = &readfds;
|
||||
wxFD_ZERO(preadfds);
|
||||
wxFD_SET(m_fd, preadfds);
|
||||
}
|
||||
|
||||
// when using non-blocking connect() the socket becomes connected
|
||||
// (successfully or not) when it becomes writable
|
||||
if ( flags & (wxSOCKET_OUTPUT_FLAG | wxSOCKET_CONNECTION_FLAG) )
|
||||
{
|
||||
pwritefds = &writefds;
|
||||
wxFD_ZERO(pwritefds);
|
||||
wxFD_SET(m_fd, pwritefds);
|
||||
}
|
||||
|
||||
wxFD_ZERO(&exceptfds);
|
||||
wxFD_SET(m_fd, &readfds);
|
||||
if (flags & wxSOCKET_OUTPUT_FLAG || flags & wxSOCKET_CONNECTION_FLAG)
|
||||
wxFD_SET(m_fd, &writefds);
|
||||
wxFD_SET(m_fd, &exceptfds);
|
||||
|
||||
/* Check 'sticky' CONNECTION flag first */
|
||||
result |= wxSOCKET_CONNECTION_FLAG & m_detected;
|
||||
const int rc = select(m_fd + 1, preadfds, pwritefds, &exceptfds, &tv);
|
||||
|
||||
/* If we have already detected a LOST event, then don't try
|
||||
* to do any further processing.
|
||||
*/
|
||||
if ((m_detected & wxSOCKET_LOST_FLAG) != 0)
|
||||
// check for errors first
|
||||
if ( rc == -1 || wxFD_ISSET(m_fd, &exceptfds) )
|
||||
{
|
||||
m_establishing = false;
|
||||
return (wxSOCKET_LOST_FLAG & flags);
|
||||
|
||||
return wxSOCKET_LOST_FLAG & flags;
|
||||
}
|
||||
|
||||
/* Try select now */
|
||||
if (select(m_fd + 1, &readfds, &writefds, &exceptfds, &tv) < 0)
|
||||
{
|
||||
/* What to do here? */
|
||||
return (result & flags);
|
||||
}
|
||||
if ( rc == 0 )
|
||||
return 0;
|
||||
|
||||
/* Check for exceptions and errors */
|
||||
if (wxFD_ISSET(m_fd, &exceptfds))
|
||||
{
|
||||
m_establishing = false;
|
||||
m_detected = wxSOCKET_LOST_FLAG;
|
||||
wxASSERT_MSG( rc == 1, "unexpected select() return value" );
|
||||
|
||||
/* LOST event: Abort any further processing */
|
||||
return (wxSOCKET_LOST_FLAG & flags);
|
||||
}
|
||||
wxSocketEventFlags detected = 0;
|
||||
if ( preadfds && wxFD_ISSET(m_fd, preadfds) )
|
||||
detected |= wxSOCKET_INPUT_FLAG;
|
||||
|
||||
/* Check for readability */
|
||||
if (wxFD_ISSET(m_fd, &readfds))
|
||||
{
|
||||
result |= wxSOCKET_INPUT_FLAG;
|
||||
|
||||
if (m_server && m_stream)
|
||||
{
|
||||
/* This is a TCP server socket that detected a connection.
|
||||
While the INPUT_FLAG is also set, it doesn't matter on
|
||||
this kind of sockets, as we can only Accept() from them. */
|
||||
m_detected |= wxSOCKET_CONNECTION_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for writability */
|
||||
if (wxFD_ISSET(m_fd, &writefds))
|
||||
if ( pwritefds && wxFD_ISSET(m_fd, pwritefds) )
|
||||
{
|
||||
// check for the case of non-blocking connect()
|
||||
if ( m_establishing && !m_server )
|
||||
{
|
||||
int error;
|
||||
@@ -1169,24 +1154,17 @@ wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags,
|
||||
getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (char*)&error, &len);
|
||||
|
||||
if ( error )
|
||||
{
|
||||
m_detected = wxSOCKET_LOST_FLAG;
|
||||
|
||||
/* LOST event: Abort any further processing */
|
||||
return (wxSOCKET_LOST_FLAG & flags);
|
||||
}
|
||||
detected = wxSOCKET_LOST_FLAG;
|
||||
else
|
||||
{
|
||||
m_detected |= wxSOCKET_CONNECTION_FLAG;
|
||||
detected |= wxSOCKET_CONNECTION_FLAG;
|
||||
}
|
||||
}
|
||||
else
|
||||
else // not called to get non-blocking connect() status
|
||||
{
|
||||
result |= wxSOCKET_OUTPUT_FLAG;
|
||||
detected |= wxSOCKET_OUTPUT_FLAG;
|
||||
}
|
||||
}
|
||||
|
||||
return (result | m_detected) & flags;
|
||||
return detected & flags;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@@ -317,49 +317,49 @@ LRESULT CALLBACK wxSocket_Internal_WinProc(HWND hWnd,
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
|
||||
wxSocketImplMSW *socket;
|
||||
wxSocketNotify event;
|
||||
wxSocketNotify event = (wxSocketNotify)-1;
|
||||
{
|
||||
wxCRIT_SECT_LOCKER(lock, gs_critical);
|
||||
|
||||
socket = socketList[(uMsg - WM_USER)];
|
||||
event = (wxSocketNotify) -1;
|
||||
if ( !socket )
|
||||
return 0;
|
||||
|
||||
wxASSERT_MSG( socket->m_fd == (SOCKET)wParam,
|
||||
"mismatch between message and socket?" );
|
||||
|
||||
/* Check that the socket still exists (it has not been
|
||||
* destroyed) and for safety, check that the m_fd field
|
||||
* is what we expect it to be.
|
||||
*/
|
||||
if ((socket != NULL) && ((WPARAM)socket->m_fd == wParam))
|
||||
{
|
||||
switch WSAGETSELECTEVENT(lParam)
|
||||
{
|
||||
case FD_READ: event = wxSOCKET_INPUT; break;
|
||||
case FD_WRITE: event = wxSOCKET_OUTPUT; break;
|
||||
case FD_ACCEPT: event = wxSOCKET_CONNECTION; break;
|
||||
case FD_CONNECT:
|
||||
{
|
||||
if (WSAGETSELECTERROR(lParam) != 0)
|
||||
event = wxSOCKET_LOST;
|
||||
else
|
||||
case FD_READ:
|
||||
event = wxSOCKET_INPUT;
|
||||
break;
|
||||
|
||||
case FD_WRITE:
|
||||
event = wxSOCKET_OUTPUT;
|
||||
break;
|
||||
|
||||
case FD_ACCEPT:
|
||||
event = wxSOCKET_CONNECTION;
|
||||
break;
|
||||
}
|
||||
case FD_CLOSE: event = wxSOCKET_LOST; break;
|
||||
}
|
||||
|
||||
if (event != -1)
|
||||
{
|
||||
if (event == wxSOCKET_LOST)
|
||||
socket->m_detected = wxSOCKET_LOST_FLAG;
|
||||
else
|
||||
socket->m_detected |= (1 << event);
|
||||
}
|
||||
case FD_CONNECT:
|
||||
event = WSAGETSELECTERROR(lParam) ? wxSOCKET_LOST
|
||||
: wxSOCKET_CONNECTION;
|
||||
break;
|
||||
|
||||
case FD_CLOSE:
|
||||
event = wxSOCKET_LOST;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( "unexpected socket notification" );
|
||||
return 0;
|
||||
}
|
||||
} // unlock gs_critical
|
||||
|
||||
if ( socket )
|
||||
socket->NotifyOnStateChange(event);
|
||||
|
||||
return (LRESULT) 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -473,9 +473,6 @@ int wxSocketImplMSW::Read(void *buffer, int size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Reenable INPUT events */
|
||||
m_detected &= ~wxSOCKET_INPUT_FLAG;
|
||||
|
||||
if (m_fd == INVALID_SOCKET || m_server)
|
||||
{
|
||||
m_error = wxSOCKET_INVSOCK;
|
||||
@@ -523,12 +520,6 @@ int wxSocketImplMSW::Write(const void *buffer, int size)
|
||||
else
|
||||
m_error = wxSOCKET_WOULDBLOCK;
|
||||
|
||||
/* Only reenable OUTPUT events after an error (just like WSAAsyncSelect
|
||||
* does). Once the first OUTPUT event is received, users can assume
|
||||
* that the socket is writable until a read operation fails. Only then
|
||||
* will further OUTPUT events be posted.
|
||||
*/
|
||||
m_detected &= ~wxSOCKET_OUTPUT_FLAG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@@ -513,9 +513,8 @@ int wxSocketImplUnix::Read(void *buffer, int size)
|
||||
*/
|
||||
if ((ret == 0) && m_stream)
|
||||
{
|
||||
/* Make sure wxSOCKET_LOST event gets sent and shut down the socket */
|
||||
m_detected = wxSOCKET_LOST_FLAG;
|
||||
OnReadWaiting();
|
||||
m_establishing = false;
|
||||
OnStateChange(wxSOCKET_LOST);
|
||||
return 0;
|
||||
}
|
||||
else if (ret == -1)
|
||||
@@ -576,13 +575,11 @@ int wxSocketImplUnix::Write(const void *buffer, int size)
|
||||
|
||||
void wxSocketImplUnix::EnableEvent(wxSocketNotify event)
|
||||
{
|
||||
m_detected &= ~(1 << event);
|
||||
wxSocketManager::Get()->Install_Callback(this, event);
|
||||
}
|
||||
|
||||
void wxSocketImplUnix::DisableEvent(wxSocketNotify event)
|
||||
{
|
||||
m_detected |= (1 << event);
|
||||
wxSocketManager::Get()->Uninstall_Callback(this, event);
|
||||
}
|
||||
|
||||
@@ -709,17 +706,6 @@ void wxSocketImplUnix::OnReadWaiting()
|
||||
return;
|
||||
}
|
||||
|
||||
/* If we have already detected a LOST event, then don't try
|
||||
* to do any further processing.
|
||||
*/
|
||||
if ((m_detected & wxSOCKET_LOST_FLAG) != 0)
|
||||
{
|
||||
m_establishing = false;
|
||||
|
||||
OnStateChange(wxSOCKET_LOST);
|
||||
return;
|
||||
}
|
||||
|
||||
int num = recv(m_fd, &c, 1, MSG_PEEK | GSOCKET_MSG_NOSIGNAL);
|
||||
|
||||
if (num > 0)
|
||||
@@ -762,17 +748,6 @@ void wxSocketImplUnix::OnReadWaiting()
|
||||
|
||||
void wxSocketImplUnix::OnWriteWaiting()
|
||||
{
|
||||
/* If we have already detected a LOST event, then don't try
|
||||
* to do any further processing.
|
||||
*/
|
||||
if ((m_detected & wxSOCKET_LOST_FLAG) != 0)
|
||||
{
|
||||
m_establishing = false;
|
||||
|
||||
OnStateChange(wxSOCKET_LOST);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_establishing && !m_server)
|
||||
{
|
||||
int error;
|
||||
|
Reference in New Issue
Block a user