only call GSocket_Init() when needed and do call it before using GAddress_XXX
functions (fixes bug 510722) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14387 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -42,11 +42,14 @@ public:
|
|||||||
void SetAddress(GAddress *address);
|
void SetAddress(GAddress *address);
|
||||||
|
|
||||||
// we need to be able to create copies of the addresses polymorphically (i.e.
|
// we need to be able to create copies of the addresses polymorphically (i.e.
|
||||||
// wihtout knowing the exact address class)
|
// without knowing the exact address class)
|
||||||
virtual wxSockAddress *Clone() const = 0;
|
virtual wxSockAddress *Clone() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GAddress *m_address;
|
GAddress *m_address;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Init();
|
||||||
};
|
};
|
||||||
|
|
||||||
class WXDLLEXPORT wxIPV4address : public wxSockAddress {
|
class WXDLLEXPORT wxIPV4address : public wxSockAddress {
|
||||||
|
@@ -185,6 +185,11 @@ public:
|
|||||||
void SetNotify(wxSocketEventFlags flags);
|
void SetNotify(wxSocketEventFlags flags);
|
||||||
void Notify(bool notify);
|
void Notify(bool notify);
|
||||||
|
|
||||||
|
// initialize/shutdown the sockets (usually called automatically)
|
||||||
|
static bool IsInitialized();
|
||||||
|
static bool Initialize();
|
||||||
|
static void Shutdown();
|
||||||
|
|
||||||
// callbacks are deprecated, use events instead
|
// callbacks are deprecated, use events instead
|
||||||
#if WXWIN_COMPATIBILITY
|
#if WXWIN_COMPATIBILITY
|
||||||
wxSockCbk Callback(wxSockCbk cbk_);
|
wxSockCbk Callback(wxSockCbk cbk_);
|
||||||
@@ -247,6 +252,9 @@ private:
|
|||||||
bool m_notify; // notify events to users?
|
bool m_notify; // notify events to users?
|
||||||
wxSocketEventFlags m_eventmask; // which events to notify?
|
wxSocketEventFlags m_eventmask; // which events to notify?
|
||||||
|
|
||||||
|
// the initialization count, GSocket is initialized if > 0
|
||||||
|
static size_t m_countInit;
|
||||||
|
|
||||||
// callbacks are deprecated, use events instead
|
// callbacks are deprecated, use events instead
|
||||||
#if WXWIN_COMPATIBILITY
|
#if WXWIN_COMPATIBILITY
|
||||||
wxSockCbk m_cbk; // callback
|
wxSockCbk m_cbk; // callback
|
||||||
|
@@ -22,19 +22,23 @@
|
|||||||
|
|
||||||
#if wxUSE_SOCKETS
|
#if wxUSE_SOCKETS
|
||||||
|
|
||||||
#include <stdio.h>
|
#ifndef WX_PRECOMP
|
||||||
#include <stdlib.h>
|
#include "wx/defs.h"
|
||||||
#include <ctype.h>
|
#include "wx/object.h"
|
||||||
|
#include "wx/log.h"
|
||||||
|
#include "wx/intl.h"
|
||||||
|
|
||||||
#if !defined(__MWERKS__) && !defined(__SALFORDC__)
|
#include <stdio.h>
|
||||||
#include <memory.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#if !defined(__MWERKS__) && !defined(__SALFORDC__)
|
||||||
|
#include <memory.h>
|
||||||
|
#endif
|
||||||
|
#endif // !WX_PRECOMP
|
||||||
|
|
||||||
#include "wx/defs.h"
|
|
||||||
#include "wx/object.h"
|
|
||||||
#include "wx/log.h"
|
|
||||||
#include "wx/intl.h"
|
|
||||||
#include "wx/gsocket.h"
|
#include "wx/gsocket.h"
|
||||||
|
#include "wx/socket.h"
|
||||||
#include "wx/sckaddr.h"
|
#include "wx/sckaddr.h"
|
||||||
|
|
||||||
IMPLEMENT_ABSTRACT_CLASS(wxSockAddress, wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxSockAddress, wxObject)
|
||||||
@@ -50,13 +54,26 @@ IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress, wxSockAddress)
|
|||||||
// wxIPV4address
|
// wxIPV4address
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void wxSockAddress::Init()
|
||||||
|
{
|
||||||
|
if ( !wxSocketBase::IsInitialized() )
|
||||||
|
{
|
||||||
|
// we must do it before using GAddress_XXX functions
|
||||||
|
(void)wxSocketBase::Initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wxSockAddress::wxSockAddress()
|
wxSockAddress::wxSockAddress()
|
||||||
{
|
{
|
||||||
m_address = GAddress_new();
|
Init();
|
||||||
|
|
||||||
|
m_address = GAddress_new();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSockAddress::wxSockAddress(const wxSockAddress& other)
|
wxSockAddress::wxSockAddress(const wxSockAddress& other)
|
||||||
{
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
m_address = GAddress_copy(other.m_address);
|
m_address = GAddress_copy(other.m_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -110,6 +110,44 @@ public:
|
|||||||
// wxSocketBase
|
// wxSocketBase
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
// Initialization and shutdown
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// FIXME-MT: all this is MT-unsafe, of course, we should protect all accesses
|
||||||
|
// to m_countInit with a crit section
|
||||||
|
size_t wxSocketBase::m_countInit = 0;
|
||||||
|
|
||||||
|
bool wxSocketBase::IsInitialized()
|
||||||
|
{
|
||||||
|
return m_countInit > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxSocketBase::Initialize()
|
||||||
|
{
|
||||||
|
if ( !m_countInit++ )
|
||||||
|
{
|
||||||
|
if ( !GSocket_Init() )
|
||||||
|
{
|
||||||
|
m_countInit--;
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxSocketBase::Shutdown()
|
||||||
|
{
|
||||||
|
// we should be initialized
|
||||||
|
wxASSERT_MSG( m_countInit, _T("extra call to Shutdown()") );
|
||||||
|
if ( !--m_countInit )
|
||||||
|
{
|
||||||
|
GSocket_Cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// Ctor and dtor
|
// Ctor and dtor
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@@ -145,6 +183,13 @@ void wxSocketBase::Init()
|
|||||||
m_cbk = NULL;
|
m_cbk = NULL;
|
||||||
m_cdata = NULL;
|
m_cdata = NULL;
|
||||||
#endif // WXWIN_COMPATIBILITY
|
#endif // WXWIN_COMPATIBILITY
|
||||||
|
|
||||||
|
if ( !IsInitialized() )
|
||||||
|
{
|
||||||
|
// this Initialize() will be undone by wxSocketModule::OnExit(), all the
|
||||||
|
// other calls to it should be matched by a call to Shutdown()
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSocketBase::wxSocketBase()
|
wxSocketBase::wxSocketBase()
|
||||||
@@ -1242,11 +1287,21 @@ wxDatagramSocket& wxDatagramSocket::SendTo( wxSockAddress& addr,
|
|||||||
|
|
||||||
class WXDLLEXPORT wxSocketModule : public wxModule
|
class WXDLLEXPORT wxSocketModule : public wxModule
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxSocketModule)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool OnInit() { return GSocket_Init() != 0; }
|
virtual bool OnInit()
|
||||||
void OnExit() { GSocket_Cleanup(); }
|
{
|
||||||
|
// wxSocketBase will call GSocket_Init() itself when/if needed
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void OnExit()
|
||||||
|
{
|
||||||
|
if ( wxSocketBase::IsInitialized() )
|
||||||
|
wxSocketBase::Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_DYNAMIC_CLASS(wxSocketModule)
|
||||||
};
|
};
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxSocketModule, wxModule)
|
IMPLEMENT_DYNAMIC_CLASS(wxSocketModule, wxModule)
|
||||||
|
Reference in New Issue
Block a user