Virtualize wxSocketImpl creation by routing it via wxSocketManager.
This is necessary to create different kinds of sockets for the console and GUI applications under OS X: unlike Unix which use different socket managers for the console and GUI programs but still use the same data structures in both cases as X11 and derived toolkits APIs are very similar, Core Foundation sockets don't have anything in common with their console counterparts and so we need to use different wxSocketImpl versions too. A side effect of this commit is that now we need to force linking of src/msw/sockmsw.cpp when using sockets: this wasn't necessary before because it contained wxSocketImpl method definition but now that there are no more direct dependencies on it, MSVC linker simply discards the object file unless we force it to link with it. Notice that this commit doesn't change anything yet, it simply refactors the code to use wxSocketManager::CreateSocket() instead of wxSocketImpl::Create() in preparation for the next change. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61675 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -139,6 +139,9 @@ public:
|
|||||||
virtual void OnExit() = 0;
|
virtual void OnExit() = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// create the socket implementation object matching this manager
|
||||||
|
virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket) = 0;
|
||||||
|
|
||||||
// these functions enable or disable monitoring of the given socket for the
|
// these functions enable or disable monitoring of the given socket for the
|
||||||
// specified events inside the currently running event loop (but notice
|
// specified events inside the currently running event loop (but notice
|
||||||
// that both BSD and Winsock implementations actually use socket->m_server
|
// that both BSD and Winsock implementations actually use socket->m_server
|
||||||
@@ -167,16 +170,12 @@ private:
|
|||||||
Base class for all socket implementations providing functionality common to
|
Base class for all socket implementations providing functionality common to
|
||||||
BSD and Winsock sockets.
|
BSD and Winsock sockets.
|
||||||
|
|
||||||
Objects of this class are not created directly but only via its static
|
Objects of this class are not created directly but only via the factory
|
||||||
Create() method which is implemented in port-specific code.
|
function wxSocketManager::CreateSocket().
|
||||||
*/
|
*/
|
||||||
class wxSocketImpl
|
class wxSocketImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// static factory function: creates the low-level socket associated with
|
|
||||||
// the given wxSocket (and inherits its attributes such as timeout)
|
|
||||||
static wxSocketImpl *Create(wxSocketBase& wxsocket);
|
|
||||||
|
|
||||||
virtual ~wxSocketImpl();
|
virtual ~wxSocketImpl();
|
||||||
|
|
||||||
// set various socket properties: all of those can only be called before
|
// set various socket properties: all of those can only be called before
|
||||||
|
@@ -117,6 +117,11 @@ public:
|
|||||||
virtual bool OnInit() { return true; }
|
virtual bool OnInit() { return true; }
|
||||||
virtual void OnExit() { }
|
virtual void OnExit() { }
|
||||||
|
|
||||||
|
virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket)
|
||||||
|
{
|
||||||
|
return new wxSocketImplUnix(wxsocket);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// identifies either input or output direction
|
// identifies either input or output direction
|
||||||
//
|
//
|
||||||
|
@@ -533,7 +533,14 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket)
|
|||||||
if ( fd == INVALID_SOCKET )
|
if ( fd == INVALID_SOCKET )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
wxSocketImpl * const sock = Create(wxsocket);
|
wxSocketManager * const manager = wxSocketManager::Get();
|
||||||
|
if ( !manager )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
wxSocketImpl * const sock = manager->CreateSocket(wxsocket);
|
||||||
|
if ( !sock )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
sock->m_fd = fd;
|
sock->m_fd = fd;
|
||||||
sock->m_peer = wxSockAddressImpl(from.addr, fromlen);
|
sock->m_peer = wxSockAddressImpl(from.addr, fromlen);
|
||||||
|
|
||||||
@@ -1739,7 +1746,8 @@ wxSocketServer::wxSocketServer(const wxSockAddress& addr,
|
|||||||
{
|
{
|
||||||
wxLogTrace( wxTRACE_Socket, wxT("Opening wxSocketServer") );
|
wxLogTrace( wxTRACE_Socket, wxT("Opening wxSocketServer") );
|
||||||
|
|
||||||
m_impl = wxSocketImpl::Create(*this);
|
wxSocketManager * const manager = wxSocketManager::Get();
|
||||||
|
m_impl = manager ? manager->CreateSocket(*this) : NULL;
|
||||||
|
|
||||||
if (!m_impl)
|
if (!m_impl)
|
||||||
{
|
{
|
||||||
@@ -1897,7 +1905,8 @@ bool wxSocketClient::DoConnect(const wxSockAddress& remote,
|
|||||||
m_establishing = false;
|
m_establishing = false;
|
||||||
|
|
||||||
// Create and set up the new one
|
// Create and set up the new one
|
||||||
m_impl = wxSocketImpl::Create(*this);
|
wxSocketManager * const manager = wxSocketManager::Get();
|
||||||
|
m_impl = manager ? manager->CreateSocket(*this) : NULL;
|
||||||
if ( !m_impl )
|
if ( !m_impl )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -1979,7 +1988,8 @@ wxDatagramSocket::wxDatagramSocket( const wxSockAddress& addr,
|
|||||||
: wxSocketBase( flags, wxSOCKET_DATAGRAM )
|
: wxSocketBase( flags, wxSOCKET_DATAGRAM )
|
||||||
{
|
{
|
||||||
// Create the socket
|
// Create the socket
|
||||||
m_impl = wxSocketImpl::Create(*this);
|
wxSocketManager * const manager = wxSocketManager::Get();
|
||||||
|
m_impl = manager ? manager->CreateSocket(*this) : NULL;
|
||||||
|
|
||||||
if (!m_impl)
|
if (!m_impl)
|
||||||
return;
|
return;
|
||||||
@@ -2064,4 +2074,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxSocketModule, wxModule)
|
|||||||
wxFORCE_LINK_MODULE( socketiohandler )
|
wxFORCE_LINK_MODULE( socketiohandler )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// same for ManagerSetter in the MSW file
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
wxFORCE_LINK_MODULE( mswsocket )
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // wxUSE_SOCKETS
|
#endif // wxUSE_SOCKETS
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include "wx/apptrait.h"
|
#include "wx/apptrait.h"
|
||||||
#include "wx/thread.h"
|
#include "wx/thread.h"
|
||||||
#include "wx/dynlib.h"
|
#include "wx/dynlib.h"
|
||||||
|
#include "wx/link.h"
|
||||||
|
|
||||||
#ifdef __WXWINCE__
|
#ifdef __WXWINCE__
|
||||||
/*
|
/*
|
||||||
@@ -437,16 +438,13 @@ static struct ManagerSetter
|
|||||||
}
|
}
|
||||||
} gs_managerSetter;
|
} gs_managerSetter;
|
||||||
|
|
||||||
|
// see the relative linker macro in socket.cpp
|
||||||
|
wxFORCE_LINK_THIS_MODULE( mswsocket );
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxSocketImpl implementation
|
// wxSocketImpl implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
/* static */
|
|
||||||
wxSocketImpl *wxSocketImpl::Create(wxSocketBase& wxsocket)
|
|
||||||
{
|
|
||||||
return new wxSocketImplMSW(wxsocket);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxSocketImplMSW::DoClose()
|
void wxSocketImplMSW::DoClose()
|
||||||
{
|
{
|
||||||
wxSocketManager::Get()->Uninstall_Callback(this);
|
wxSocketManager::Get()->Uninstall_Callback(this);
|
||||||
|
@@ -66,13 +66,6 @@
|
|||||||
// wxSocketImpl implementation
|
// wxSocketImpl implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
/* static */
|
|
||||||
wxSocketImpl *wxSocketImpl::Create(wxSocketBase& wxsocket)
|
|
||||||
{
|
|
||||||
return new wxSocketImplUnix(wxsocket);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wxSocketError wxSocketImplUnix::GetLastError() const
|
wxSocketError wxSocketImplUnix::GetLastError() const
|
||||||
{
|
{
|
||||||
switch ( errno )
|
switch ( errno )
|
||||||
|
Reference in New Issue
Block a user