no real changes, just reformat before starting really modifying

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56538 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-10-28 00:02:38 +00:00
parent 438febca6e
commit 7e73fb9c99
2 changed files with 503 additions and 508 deletions

View File

@@ -55,14 +55,15 @@ class WXDLLIMPEXP_FWD_NET wxTCPClient;
class WXDLLIMPEXP_NET wxTCPConnection : public wxConnectionBase
{
public:
wxTCPConnection(void *buffer, size_t size);
wxTCPConnection();
wxTCPConnection() { Init(); }
wxTCPConnection(void *buffer, size_t size)
: wxConnectionBase(buffer, size)
{
Init();
}
virtual ~wxTCPConnection();
// To enable the compressor (NOTE: not implemented!)
void Compress(bool on);
// implement base class pure virtual methods
virtual const void *Request(const wxString& item,
size_t *size = NULL,
@@ -71,6 +72,11 @@ public:
virtual bool StopAdvise(const wxString& item);
virtual bool Disconnect(void);
// Will be used in the future to enable the compression but does nothing
// for now.
void Compress(bool on);
protected:
virtual bool DoExecute(const void *data, size_t size, wxIPCFormat format);
virtual bool DoPoke(const wxString& item, const void *data, size_t size,
@@ -85,6 +91,10 @@ protected:
wxDataOutputStream *m_codeco;
wxString m_topic;
private:
// common part of both ctors
void Init();
friend class wxTCPServer;
friend class wxTCPClient;
friend class wxTCPEventHandler;
@@ -104,8 +114,6 @@ public:
virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
wxTCPConnection *topLevelConnection;
protected:
wxSocketServer *m_server;
@@ -122,7 +130,6 @@ class WXDLLIMPEXP_NET wxTCPClient : public wxClientBase
{
public:
wxTCPClient();
virtual ~wxTCPClient();
virtual bool ValidHost(const wxString& host);

View File

@@ -49,8 +49,6 @@
// macros and constants
// --------------------------------------------------------------------------
// It seems to be already defined somewhere in the Xt includes.
#ifndef __XT__
// Message codes
enum
{
@@ -66,7 +64,6 @@ enum
IPC_CONNECT,
IPC_DISCONNECT
};
#endif
// All sockets will be created with the following flags
#define SCKIPC_FLAGS (wxSOCKET_WAITALL|wxSOCKET_REUSEADDR)
@@ -83,7 +80,8 @@ enum
// get the address object for the given server name, the caller must delete it
static wxSockAddress *
GetAddressFromName(const wxString& serverName, const wxString& host = wxEmptyString)
GetAddressFromName(const wxString& serverName,
const wxString& host = wxEmptyString)
{
// we always use INET sockets under non-Unix systems
#if defined(__UNIX__) && !defined(__WINDOWS__) && !defined(__WINE__)
@@ -145,11 +143,8 @@ IMPLEMENT_CLASS(wxTCPConnection, wxConnectionBase)
// wxTCPClient
// --------------------------------------------------------------------------
wxTCPClient::wxTCPClient () : wxClientBase()
{
}
wxTCPClient::~wxTCPClient ()
wxTCPClient::wxTCPClient()
: wxClientBase()
{
}
@@ -189,7 +184,8 @@ wxConnectionBase *wxTCPClient::MakeConnection (const wxString& host,
// OK! Confirmation.
if (msg == IPC_CONNECT)
{
wxTCPConnection *connection = (wxTCPConnection *)OnMakeConnection ();
wxTCPConnection *
connection = (wxTCPConnection *)OnMakeConnection ();
if (connection)
{
@@ -233,7 +229,8 @@ wxConnectionBase *wxTCPClient::OnMakeConnection()
// wxTCPServer
// --------------------------------------------------------------------------
wxTCPServer::wxTCPServer () : wxServerBase()
wxTCPServer::wxTCPServer()
: wxServerBase()
{
m_server = NULL;
}
@@ -256,8 +253,8 @@ bool wxTCPServer::Create(const wxString& serverName)
mode_t umaskOld;
if ( addr->Type() == wxSockAddress::UNIX )
{
// ensure that the file doesn't exist as otherwise calling socket() would
// fail
// ensure that the file doesn't exist as otherwise calling socket()
// would fail
int rc = remove(serverName.fn_str());
if ( rc < 0 && errno != ENOENT )
{
@@ -327,7 +324,8 @@ wxTCPServer::~wxTCPServer()
#endif // __UNIX_LIKE__
}
wxConnectionBase *wxTCPServer::OnAcceptConnection( const wxString& WXUNUSED(topic) )
wxConnectionBase *
wxTCPServer::OnAcceptConnection(const wxString& WXUNUSED(topic))
{
return new wxTCPConnection();
}
@@ -336,16 +334,7 @@ wxConnectionBase *wxTCPServer::OnAcceptConnection( const wxString& WXUNUSED(topi
// wxTCPConnection
// --------------------------------------------------------------------------
wxTCPConnection::wxTCPConnection () : wxConnectionBase()
{
m_sock = NULL;
m_sockstrm = NULL;
m_codeci = NULL;
m_codeco = NULL;
}
wxTCPConnection::wxTCPConnection(void *buffer, size_t size)
: wxConnectionBase(buffer, size)
void wxTCPConnection::Init()
{
m_sock = NULL;
m_sockstrm = NULL;
@@ -371,7 +360,7 @@ wxTCPConnection::~wxTCPConnection ()
void wxTCPConnection::Compress(bool WXUNUSED(on))
{
// Use wxLZWStream
// TODO
}
// Calls that CLIENT can make.
@@ -379,7 +368,8 @@ bool wxTCPConnection::Disconnect ()
{
if ( !GetConnected() )
return true;
// Send the the disconnect message to the peer.
// Send the disconnect message to the peer.
m_codeco->Write8(IPC_DISCONNECT);
if ( m_sock )
@@ -393,7 +383,9 @@ bool wxTCPConnection::Disconnect ()
return true;
}
bool wxTCPConnection::DoExecute(const void *data, size_t size, wxIPCFormat format)
bool wxTCPConnection::DoExecute(const void *data,
size_t size,
wxIPCFormat format)
{
if ( !m_sock->IsConnected() )
return false;
@@ -408,7 +400,9 @@ bool wxTCPConnection::DoExecute(const void *data, size_t size, wxIPCFormat forma
return true;
}
const void *wxTCPConnection::Request (const wxString& item, size_t *size, wxIPCFormat format)
const void *wxTCPConnection::Request(const wxString& item,
size_t *size,
wxIPCFormat format)
{
if ( !m_sock->IsConnected() )
return NULL;
@@ -417,14 +411,10 @@ const void *wxTCPConnection::Request (const wxString& item, size_t *size, wxIPCF
m_codeco->WriteString(item);
m_codeco->Write8(format);
// If Unpack doesn't initialize it.
int ret;
ret = m_codeci->Read8();
int ret = m_codeci->Read8();
if ( ret == IPC_FAIL )
return NULL;
else
{
size_t s = m_codeci->Read32();
void *data = GetBufferAtLeast( s );
@@ -436,9 +426,11 @@ const void *wxTCPConnection::Request (const wxString& item, size_t *size, wxIPCF
*size = s;
return data;
}
}
bool wxTCPConnection::DoPoke (const wxString& item, const void *data, size_t size, wxIPCFormat format)
bool wxTCPConnection::DoPoke(const wxString& item,
const void *data,
size_t size,
wxIPCFormat format)
{
if ( !m_sock->IsConnected() )
return false;
@@ -455,16 +447,13 @@ bool wxTCPConnection::DoPoke (const wxString& item, const void *data, size_t siz
bool wxTCPConnection::StartAdvise (const wxString& item)
{
int ret;
if ( !m_sock->IsConnected() )
return false;
m_codeco->Write8(IPC_ADVISE_START);
m_codeco->WriteString(item);
ret = m_codeci->Read8();
int ret = m_codeci->Read8();
if (ret != IPC_FAIL)
return true;
else
@@ -473,17 +462,15 @@ bool wxTCPConnection::StartAdvise (const wxString& item)
bool wxTCPConnection::StopAdvise (const wxString& item)
{
int msg;
if ( !m_sock->IsConnected() )
return false;
m_codeco->Write8(IPC_ADVISE_STOP);
m_codeco->WriteString(item);
msg = m_codeci->Read8();
int ret = m_codeci->Read8();
if (msg != IPC_FAIL)
if (ret != IPC_FAIL)
return true;
else
return false;
@@ -491,7 +478,9 @@ bool wxTCPConnection::StopAdvise (const wxString& item)
// Calls that SERVER can make
bool wxTCPConnection::DoAdvise(const wxString& item,
const void *data, size_t size, wxIPCFormat format)
const void *data,
size_t size,
wxIPCFormat format)
{
if ( !m_sock->IsConnected() )
return false;
@@ -518,9 +507,9 @@ END_EVENT_TABLE()
void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
{
wxSocketBase *sock = event.GetSocket();
if (!sock) { /* No socket, no glory */
if (!sock)
return ;
}
wxSocketNotify evt = event.GetSocketEvent();
wxTCPConnection *connection = (wxTCPConnection *)(sock->GetClientData());
@@ -562,7 +551,7 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
"Buffer too small in wxTCPEventHandler::Client_OnRequest" );
sockstrm->Read(data, size);
connection->OnExecute (topic_name, data, size, format);
@@ -576,7 +565,7 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
size_t size = codeci->Read32();
void *data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
"Buffer too small in wxTCPEventHandler::Client_OnRequest" );
sockstrm->Read(data, size);
connection->OnAdvise (topic_name, item, data, size, format);
@@ -614,7 +603,7 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
size_t size = codeci->Read32();
void *data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
"Buffer too small in wxTCPEventHandler::Client_OnRequest" );
sockstrm->Read(data, size);
connection->OnPoke (topic_name, item, data, size, format);
@@ -629,7 +618,10 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
format = (wxIPCFormat)codeci->Read8();
size_t user_size = wxNO_LEN;
const void *user_data = connection->OnRequest (topic_name, item, &user_size, format);
const void *user_data = connection->OnRequest(topic_name,
item,
&user_size,
format);
if (user_data)
{
@@ -676,9 +668,8 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
void wxTCPEventHandler::Server_OnRequest(wxSocketEvent &event)
{
wxSocketServer *server = (wxSocketServer *) event.GetSocket();
if (!server) { /* No server, Then exit */
if (!server)
return ;
}
wxTCPServer *ipcserv = (wxTCPServer *) server->GetClientData();
// This socket is being deleted; skip this event
@@ -690,9 +681,8 @@ void wxTCPEventHandler::Server_OnRequest(wxSocketEvent &event)
// Accept the connection, getting a new socket
wxSocketBase *sock = server->Accept();
if (!sock) { /* No socket, no glory */
if (!sock)
return ;
}
if (!sock->Ok())
{
sock->Destroy();
@@ -754,15 +744,13 @@ void wxTCPEventHandler::Server_OnRequest(wxSocketEvent &event)
class wxTCPEventHandlerModule: public wxModule
{
DECLARE_DYNAMIC_CLASS(wxTCPEventHandlerModule)
public:
bool OnInit() { gs_handler = new wxTCPEventHandler(); return true; }
void OnExit() { wxDELETE(gs_handler); }
virtual bool OnInit() { gs_handler = new wxTCPEventHandler; return true; }
virtual void OnExit() { wxDELETE(gs_handler); }
DECLARE_DYNAMIC_CLASS(wxTCPEventHandlerModule)
};
IMPLEMENT_DYNAMIC_CLASS(wxTCPEventHandlerModule, wxModule)
#endif
// wxUSE_SOCKETS && wxUSE_IPC && wxUSE_STREAMS
#endif // wxUSE_SOCKETS && wxUSE_IPC && wxUSE_STREAMS