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;
|
struct timeval m_timeout;
|
||||||
|
|
||||||
wxSocketEventFlags m_detected;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxSocketImpl(wxSocketBase& wxsocket);
|
wxSocketImpl(wxSocketBase& wxsocket);
|
||||||
|
|
||||||
|
@@ -72,17 +72,13 @@ private:
|
|||||||
|
|
||||||
// enable or disable notifications for socket input/output events
|
// enable or disable notifications for socket input/output events
|
||||||
void EnableEvents() { DoEnableEvents(true); }
|
void EnableEvents() { DoEnableEvents(true); }
|
||||||
void DisableEvents() { DoEnableEvents(false);
|
void DisableEvents() { DoEnableEvents(false); }
|
||||||
}
|
|
||||||
|
|
||||||
// really enable or disable socket input/output events
|
// really enable or disable socket input/output events
|
||||||
void DoEnableEvents(bool enable);
|
void DoEnableEvents(bool enable);
|
||||||
|
|
||||||
|
|
||||||
// enable or disable events for the given event
|
// 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 EnableEvent(wxSocketNotify event);
|
||||||
void DisableEvent(wxSocketNotify event);
|
void DisableEvent(wxSocketNotify event);
|
||||||
|
|
||||||
@@ -99,9 +95,6 @@ protected:
|
|||||||
|
|
||||||
// the events which are currently enabled for this socket, combination of
|
// the events which are currently enabled for this socket, combination of
|
||||||
// wxFDIO_INPUT and wxFDIO_OUTPUT values
|
// 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;
|
int m_enabledCallbacks;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -154,7 +154,6 @@ wxSocketImpl::wxSocketImpl(wxSocketBase& wxsocket)
|
|||||||
: m_wxsocket(&wxsocket)
|
: m_wxsocket(&wxsocket)
|
||||||
{
|
{
|
||||||
m_fd = INVALID_SOCKET;
|
m_fd = INVALID_SOCKET;
|
||||||
m_detected = 0;
|
|
||||||
m_local = NULL;
|
m_local = NULL;
|
||||||
m_peer = NULL;
|
m_peer = NULL;
|
||||||
m_error = wxSOCKET_NOERROR;
|
m_error = wxSOCKET_NOERROR;
|
||||||
@@ -377,7 +376,7 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket)
|
|||||||
{
|
{
|
||||||
wxSockAddr from;
|
wxSockAddr from;
|
||||||
WX_SOCKLEN_T fromlen = sizeof(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 )
|
if ( fd == INVALID_SOCKET )
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -414,8 +413,6 @@ void wxSocketImpl::Shutdown()
|
|||||||
shutdown(m_fd, 1 /* SD_SEND */);
|
shutdown(m_fd, 1 /* SD_SEND */);
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_detected = wxSOCKET_LOST_FLAG;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1093,9 +1090,7 @@ wxSocketBase& wxSocketBase::Discard()
|
|||||||
wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags,
|
wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags,
|
||||||
const timeval *timeout)
|
const timeval *timeout)
|
||||||
{
|
{
|
||||||
wxSocketEventFlags result = 0;
|
if ( m_fd == INVALID_SOCKET )
|
||||||
|
|
||||||
if (m_fd == INVALID_SOCKET)
|
|
||||||
return (wxSOCKET_LOST_FLAG & flags);
|
return (wxSOCKET_LOST_FLAG & flags);
|
||||||
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
@@ -1104,89 +1099,72 @@ wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags,
|
|||||||
else
|
else
|
||||||
tv.tv_sec = tv.tv_usec = 0;
|
tv.tv_sec = tv.tv_usec = 0;
|
||||||
|
|
||||||
fd_set readfds;
|
// prepare the FD sets, passing NULL for the one(s) we don't use
|
||||||
fd_set writefds;
|
fd_set
|
||||||
fd_set exceptfds;
|
readfds, *preadfds = NULL,
|
||||||
wxFD_ZERO(&readfds);
|
writefds, *pwritefds = NULL,
|
||||||
wxFD_ZERO(&writefds);
|
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_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);
|
wxFD_SET(m_fd, &exceptfds);
|
||||||
|
|
||||||
/* Check 'sticky' CONNECTION flag first */
|
const int rc = select(m_fd + 1, preadfds, pwritefds, &exceptfds, &tv);
|
||||||
result |= wxSOCKET_CONNECTION_FLAG & m_detected;
|
|
||||||
|
|
||||||
/* If we have already detected a LOST event, then don't try
|
// check for errors first
|
||||||
* to do any further processing.
|
if ( rc == -1 || wxFD_ISSET(m_fd, &exceptfds) )
|
||||||
*/
|
|
||||||
if ((m_detected & wxSOCKET_LOST_FLAG) != 0)
|
|
||||||
{
|
{
|
||||||
m_establishing = false;
|
m_establishing = false;
|
||||||
return (wxSOCKET_LOST_FLAG & flags);
|
|
||||||
|
return wxSOCKET_LOST_FLAG & flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try select now */
|
if ( rc == 0 )
|
||||||
if (select(m_fd + 1, &readfds, &writefds, &exceptfds, &tv) < 0)
|
return 0;
|
||||||
{
|
|
||||||
/* What to do here? */
|
|
||||||
return (result & flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for exceptions and errors */
|
wxASSERT_MSG( rc == 1, "unexpected select() return value" );
|
||||||
if (wxFD_ISSET(m_fd, &exceptfds))
|
|
||||||
{
|
|
||||||
m_establishing = false;
|
|
||||||
m_detected = wxSOCKET_LOST_FLAG;
|
|
||||||
|
|
||||||
/* LOST event: Abort any further processing */
|
wxSocketEventFlags detected = 0;
|
||||||
return (wxSOCKET_LOST_FLAG & flags);
|
if ( preadfds && wxFD_ISSET(m_fd, preadfds) )
|
||||||
}
|
detected |= wxSOCKET_INPUT_FLAG;
|
||||||
|
|
||||||
/* Check for readability */
|
if ( pwritefds && wxFD_ISSET(m_fd, pwritefds) )
|
||||||
if (wxFD_ISSET(m_fd, &readfds))
|
|
||||||
{
|
{
|
||||||
result |= wxSOCKET_INPUT_FLAG;
|
// check for the case of non-blocking connect()
|
||||||
|
if ( m_establishing && !m_server )
|
||||||
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 (m_establishing && !m_server)
|
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
SOCKOPTLEN_T len = sizeof(error);
|
SOCKOPTLEN_T len = sizeof(error);
|
||||||
m_establishing = false;
|
m_establishing = false;
|
||||||
getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (char*)&error, &len);
|
getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (char*)&error, &len);
|
||||||
|
|
||||||
if (error)
|
if ( error )
|
||||||
{
|
detected = wxSOCKET_LOST_FLAG;
|
||||||
m_detected = wxSOCKET_LOST_FLAG;
|
|
||||||
|
|
||||||
/* LOST event: Abort any further processing */
|
|
||||||
return (wxSOCKET_LOST_FLAG & flags);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
detected |= wxSOCKET_CONNECTION_FLAG;
|
||||||
m_detected |= wxSOCKET_CONNECTION_FLAG;
|
|
||||||
}
|
}
|
||||||
}
|
else // not called to get non-blocking connect() status
|
||||||
else
|
|
||||||
{
|
{
|
||||||
result |= wxSOCKET_OUTPUT_FLAG;
|
detected |= wxSOCKET_OUTPUT_FLAG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (result | m_detected) & flags;
|
return detected & flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@@ -317,49 +317,49 @@ LRESULT CALLBACK wxSocket_Internal_WinProc(HWND hWnd,
|
|||||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||||
|
|
||||||
wxSocketImplMSW *socket;
|
wxSocketImplMSW *socket;
|
||||||
wxSocketNotify event;
|
wxSocketNotify event = (wxSocketNotify)-1;
|
||||||
{
|
{
|
||||||
wxCRIT_SECT_LOCKER(lock, gs_critical);
|
wxCRIT_SECT_LOCKER(lock, gs_critical);
|
||||||
|
|
||||||
socket = socketList[(uMsg - WM_USER)];
|
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)
|
switch WSAGETSELECTEVENT(lParam)
|
||||||
{
|
{
|
||||||
case FD_READ: event = wxSOCKET_INPUT; break;
|
case FD_READ:
|
||||||
case FD_WRITE: event = wxSOCKET_OUTPUT; break;
|
event = wxSOCKET_INPUT;
|
||||||
case FD_ACCEPT: event = wxSOCKET_CONNECTION; break;
|
break;
|
||||||
case FD_CONNECT:
|
|
||||||
{
|
case FD_WRITE:
|
||||||
if (WSAGETSELECTERROR(lParam) != 0)
|
event = wxSOCKET_OUTPUT;
|
||||||
event = wxSOCKET_LOST;
|
break;
|
||||||
else
|
|
||||||
|
case FD_ACCEPT:
|
||||||
event = wxSOCKET_CONNECTION;
|
event = wxSOCKET_CONNECTION;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case FD_CLOSE: event = wxSOCKET_LOST; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event != -1)
|
case FD_CONNECT:
|
||||||
{
|
event = WSAGETSELECTERROR(lParam) ? wxSOCKET_LOST
|
||||||
if (event == wxSOCKET_LOST)
|
: wxSOCKET_CONNECTION;
|
||||||
socket->m_detected = wxSOCKET_LOST_FLAG;
|
break;
|
||||||
else
|
|
||||||
socket->m_detected |= (1 << event);
|
case FD_CLOSE:
|
||||||
}
|
event = wxSOCKET_LOST;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
wxFAIL_MSG( "unexpected socket notification" );
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
} // unlock gs_critical
|
} // unlock gs_critical
|
||||||
|
|
||||||
if ( socket )
|
|
||||||
socket->NotifyOnStateChange(event);
|
socket->NotifyOnStateChange(event);
|
||||||
|
|
||||||
return (LRESULT) 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -473,9 +473,6 @@ int wxSocketImplMSW::Read(void *buffer, int size)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Reenable INPUT events */
|
|
||||||
m_detected &= ~wxSOCKET_INPUT_FLAG;
|
|
||||||
|
|
||||||
if (m_fd == INVALID_SOCKET || m_server)
|
if (m_fd == INVALID_SOCKET || m_server)
|
||||||
{
|
{
|
||||||
m_error = wxSOCKET_INVSOCK;
|
m_error = wxSOCKET_INVSOCK;
|
||||||
@@ -523,12 +520,6 @@ int wxSocketImplMSW::Write(const void *buffer, int size)
|
|||||||
else
|
else
|
||||||
m_error = wxSOCKET_WOULDBLOCK;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -513,9 +513,8 @@ int wxSocketImplUnix::Read(void *buffer, int size)
|
|||||||
*/
|
*/
|
||||||
if ((ret == 0) && m_stream)
|
if ((ret == 0) && m_stream)
|
||||||
{
|
{
|
||||||
/* Make sure wxSOCKET_LOST event gets sent and shut down the socket */
|
m_establishing = false;
|
||||||
m_detected = wxSOCKET_LOST_FLAG;
|
OnStateChange(wxSOCKET_LOST);
|
||||||
OnReadWaiting();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (ret == -1)
|
else if (ret == -1)
|
||||||
@@ -576,13 +575,11 @@ int wxSocketImplUnix::Write(const void *buffer, int size)
|
|||||||
|
|
||||||
void wxSocketImplUnix::EnableEvent(wxSocketNotify event)
|
void wxSocketImplUnix::EnableEvent(wxSocketNotify event)
|
||||||
{
|
{
|
||||||
m_detected &= ~(1 << event);
|
|
||||||
wxSocketManager::Get()->Install_Callback(this, event);
|
wxSocketManager::Get()->Install_Callback(this, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxSocketImplUnix::DisableEvent(wxSocketNotify event)
|
void wxSocketImplUnix::DisableEvent(wxSocketNotify event)
|
||||||
{
|
{
|
||||||
m_detected |= (1 << event);
|
|
||||||
wxSocketManager::Get()->Uninstall_Callback(this, event);
|
wxSocketManager::Get()->Uninstall_Callback(this, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,17 +706,6 @@ void wxSocketImplUnix::OnReadWaiting()
|
|||||||
return;
|
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);
|
int num = recv(m_fd, &c, 1, MSG_PEEK | GSOCKET_MSG_NOSIGNAL);
|
||||||
|
|
||||||
if (num > 0)
|
if (num > 0)
|
||||||
@@ -762,17 +748,6 @@ void wxSocketImplUnix::OnReadWaiting()
|
|||||||
|
|
||||||
void wxSocketImplUnix::OnWriteWaiting()
|
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)
|
if (m_establishing && !m_server)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
Reference in New Issue
Block a user