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
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
// specified events inside the currently running event loop (but notice
// that both BSD and Winsock implementations actually use socket->m_server
Base class for all socket implementations providing functionality common to
BSD and Winsock sockets.
- Objects of this class are not created directly but only via its static
- Create() method which is implemented in port-specific code.
+ Objects of this class are not created directly but only via the factory
+ function wxSocketManager::CreateSocket().
*/
class wxSocketImpl
{
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();
// set various socket properties: all of those can only be called before
virtual bool OnInit() { return true; }
virtual void OnExit() { }
+ virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket)
+ {
+ return new wxSocketImplUnix(wxsocket);
+ }
+
protected:
// identifies either input or output direction
//
if ( fd == INVALID_SOCKET )
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_peer = wxSockAddressImpl(from.addr, fromlen);
{
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)
{
m_establishing = false;
// 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 )
return false;
: wxSocketBase( flags, wxSOCKET_DATAGRAM )
{
// Create the socket
- m_impl = wxSocketImpl::Create(*this);
+ wxSocketManager * const manager = wxSocketManager::Get();
+ m_impl = manager ? manager->CreateSocket(*this) : NULL;
if (!m_impl)
return;
wxFORCE_LINK_MODULE( socketiohandler )
#endif
+// same for ManagerSetter in the MSW file
+#ifdef __WXMSW__
+ wxFORCE_LINK_MODULE( mswsocket )
+#endif
+
#endif // wxUSE_SOCKETS
#include "wx/apptrait.h"
#include "wx/thread.h"
#include "wx/dynlib.h"
+#include "wx/link.h"
#ifdef __WXWINCE__
/*
}
} gs_managerSetter;
+// see the relative linker macro in socket.cpp
+wxFORCE_LINK_THIS_MODULE( mswsocket );
+
// ============================================================================
// wxSocketImpl implementation
// ============================================================================
-/* static */
-wxSocketImpl *wxSocketImpl::Create(wxSocketBase& wxsocket)
-{
- return new wxSocketImplMSW(wxsocket);
-}
-
void wxSocketImplMSW::DoClose()
{
wxSocketManager::Get()->Uninstall_Callback(this);
// wxSocketImpl implementation
// ============================================================================
-/* static */
-wxSocketImpl *wxSocketImpl::Create(wxSocketBase& wxsocket)
-{
- return new wxSocketImplUnix(wxsocket);
-}
-
-
wxSocketError wxSocketImplUnix::GetLastError() const
{
switch ( errno )