X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/75ed1d15d0d866cac78f7c0da176db8dd5288bc8..e1ee679c2e3f48bc4f2607e35033ed5505ed6665:/src/common/sckipc.cpp diff --git a/src/common/sckipc.cpp b/src/common/sckipc.cpp index 718211b7dc..9034bc595b 100644 --- a/src/common/sckipc.cpp +++ b/src/common/sckipc.cpp @@ -20,6 +20,8 @@ #pragma hdrstop #endif +#if wxUSE_SOCKETS + #ifndef WX_PRECOMP #endif @@ -58,22 +60,22 @@ enum { #endif void Server_OnRequest(wxSocketServer& server, - wxSocketBase::wxRequestEvent evt, + wxSocketNotify evt, char *cdata); void Client_OnRequest(wxSocketBase& sock, - wxSocketBase::wxRequestEvent evt, + wxSocketNotify evt, char *cdata); // --------------------------------------------------------------------------- // wxTCPClient // --------------------------------------------------------------------------- -wxTCPClient::wxTCPClient (void) +wxTCPClient::wxTCPClient () : wxClientBase() { } -wxTCPClient::~wxTCPClient (void) +wxTCPClient::~wxTCPClient () { } @@ -89,13 +91,12 @@ wxConnectionBase *wxTCPClient::MakeConnection (const wxString& host, const wxString& topic) { wxIPV4address addr; - wxSocketHandler *hsock = &wxSocketHandler::Master(); - wxSocketClient *client = hsock->CreateClient(); + wxSocketClient *client = new wxSocketClient(); wxSocketStream *stream = new wxSocketStream(*client); wxDataInputStream data_is(*stream); wxDataOutputStream data_os(*stream); - client->SetNotify(wxSocketBase::REQ_READ | wxSocketBase::REQ_LOST); + client->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG); addr.Service(server_name); addr.Hostname(host); @@ -146,7 +147,7 @@ wxConnectionBase *wxTCPClient::OnMakeConnection() // wxTCPServer // --------------------------------------------------------------------------- -wxTCPServer::wxTCPServer (void) +wxTCPServer::wxTCPServer () : wxServerBase() { } @@ -154,22 +155,21 @@ wxTCPServer::wxTCPServer (void) bool wxTCPServer::Create(const wxString& server_name) { wxIPV4address addr; - wxSocketHandler *hsock = &wxSocketHandler::Master(); wxSocketServer *server; addr.Service(server_name); // Create a socket listening on specified port - server = hsock->CreateServer(addr); + server = new wxSocketServer(addr); server->Callback((wxSocketBase::wxSockCbk)Server_OnRequest); - server->SetNotify(wxSocketBase::REQ_ACCEPT); + server->SetNotify(wxSOCKET_CONNECTION_FLAG); server->CallbackData((char *)this); return TRUE; } -wxTCPServer::~wxTCPServer(void) +wxTCPServer::~wxTCPServer() { } @@ -182,13 +182,17 @@ wxConnectionBase *wxTCPServer::OnAcceptConnection( const wxString& WXUNUSED(topi // wxTCPConnection // --------------------------------------------------------------------------- -wxTCPConnection::wxTCPConnection (void) +wxTCPConnection::wxTCPConnection () : wxConnectionBase(), m_sock(NULL), m_sockstrm(NULL), m_codeci(NULL), m_codeco(NULL) { } -wxTCPConnection::~wxTCPConnection (void) +wxTCPConnection::wxTCPConnection(char * WXUNUSED(buffer), int WXUNUSED(size)) +{ +} + +wxTCPConnection::~wxTCPConnection () { wxDELETE(m_sock); wxDELETE(m_codeci); @@ -202,7 +206,7 @@ void wxTCPConnection::Compress(bool WXUNUSED(on)) } // Calls that CLIENT can make. -bool wxTCPConnection::Disconnect (void) +bool wxTCPConnection::Disconnect () { // Send the the disconnect message to the peer. m_codeco->Write8(IPC_DISCONNECT); @@ -211,7 +215,7 @@ bool wxTCPConnection::Disconnect (void) return TRUE; } -bool wxTCPConnection::Execute (char *data, int size, wxDataFormat format) +bool wxTCPConnection::Execute (const wxChar *data, int size, wxIPCFormat format) { if (!m_sock->IsConnected()) return FALSE; @@ -223,13 +227,13 @@ bool wxTCPConnection::Execute (char *data, int size, wxDataFormat format) m_codeco->WriteString(data); else { m_codeco->Write32(size); - m_codeco->Write(data, size); + m_sockstrm->Write(data, size); } return TRUE; } -char *wxTCPConnection::Request (const wxString& item, int *size, wxDataFormat format) +char *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat format) { if (!m_sock->IsConnected()) return NULL; @@ -250,7 +254,7 @@ char *wxTCPConnection::Request (const wxString& item, int *size, wxDataFormat fo s = m_codeci->Read32(); data = new char[s]; - m_codeci->Read(data, s); + m_sockstrm->Read(data, s); if (size) *size = s; @@ -258,7 +262,7 @@ char *wxTCPConnection::Request (const wxString& item, int *size, wxDataFormat fo } } -bool wxTCPConnection::Poke (const wxString& item, char *data, int size, wxDataFormat format) +bool wxTCPConnection::Poke (const wxString& item, wxChar *data, int size, wxIPCFormat format) { if (!m_sock->IsConnected()) return FALSE; @@ -270,7 +274,7 @@ bool wxTCPConnection::Poke (const wxString& item, char *data, int size, wxDataFo m_codeco->WriteString(data); else { m_codeco->Write32(size); - m_codeco->Write(data, size); + m_sockstrm->Write(data, size); } return TRUE; @@ -314,7 +318,7 @@ bool wxTCPConnection::StopAdvise (const wxString& item) // Calls that SERVER can make bool wxTCPConnection::Advise (const wxString& item, - char *data, int size, wxDataFormat format) + wxChar *data, int size, wxIPCFormat format) { if (!m_sock->IsConnected()) return FALSE; @@ -326,24 +330,25 @@ bool wxTCPConnection::Advise (const wxString& item, m_codeco->WriteString(data); else { m_codeco->Write32(size); - m_codeco->Write(data, size); + m_sockstrm->Write(data, size); } return TRUE; } -void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt, +void Client_OnRequest(wxSocketBase& sock, wxSocketNotify evt, char *cdata) { int msg = 0; wxTCPConnection *connection = (wxTCPConnection *)cdata; wxDataInputStream *codeci; wxDataOutputStream *codeco; + wxSocketStream *sockstrm; wxString topic_name = connection->m_topic; wxString item; // The socket handler signals us that we lost the connection: destroy all. - if (evt == wxSocketBase::EVT_LOST) { + if (evt == wxSOCKET_LOST) { sock.Close(); connection->OnDisconnect(); return; @@ -352,18 +357,19 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt, // Receive message number. codeci = connection->m_codeci; codeco = connection->m_codeco; + sockstrm = connection->m_sockstrm; msg = codeci->Read8(); switch (msg) { case IPC_EXECUTE: { char *data; size_t size; - wxDataFormat format; + wxIPCFormat format; - format = (wxDataFormat)codeci->Read8(); + format = (wxIPCFormat)codeci->Read8(); size = codeci->Read32(); data = new char[size]; - codeci->Read(data, size); + sockstrm->Read(data, size); connection->OnExecute (topic_name, data, size, format); @@ -373,13 +379,13 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt, case IPC_ADVISE: { char *data; size_t size; - wxDataFormat format; + wxIPCFormat format; item = codeci->ReadString(); - format = (wxDataFormat)codeci->Read8(); + format = (wxIPCFormat)codeci->Read8(); size = codeci->Read32(); data = new char[size]; - codeci->Read(data, size); + sockstrm->Read(data, size); connection->OnAdvise (topic_name, item, data, size, format); @@ -409,15 +415,15 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt, break; } case IPC_POKE: { - wxDataFormat format; + wxIPCFormat format; size_t size; - char *data; + wxChar *data; item = codeci->ReadString(); - format = (wxDataFormat)codeci->Read8(); + format = (wxIPCFormat)codeci->Read8(); size = codeci->Read32(); - data = new char[size]; - codeci->Read(data, size); + data = new wxChar[size]; + sockstrm->Read(data, size); connection->OnPoke (topic_name, item, data, size, format); @@ -426,10 +432,10 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt, break; } case IPC_REQUEST: { - wxDataFormat format; + wxIPCFormat format; item = codeci->ReadString(); - format = (wxDataFormat)codeci->Read8(); + format = (wxIPCFormat)codeci->Read8(); int user_size = -1; char *user_data = connection->OnRequest (topic_name, item, &user_size, format); @@ -438,7 +444,7 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt, codeco->Write8(IPC_REQUEST_REPLY); if (user_size != -1) { codeco->Write32(user_size); - codeco->Write(user_data, user_size); + sockstrm->Write(user_data, user_size); } else codeco->WriteString(user_data); } else @@ -458,20 +464,20 @@ void Client_OnRequest(wxSocketBase& sock, wxSocketBase::wxRequestEvent evt, } void Server_OnRequest(wxSocketServer& server, - wxSocketBase::wxRequestEvent evt, char *cdata) + wxSocketNotify evt, char *cdata) { wxTCPServer *ipcserv = (wxTCPServer *)cdata; wxSocketStream *stream; wxDataInputStream *codeci; wxDataOutputStream *codeco; - if (evt != wxSocketBase::EVT_ACCEPT) + if (evt != wxSOCKET_CONNECTION) return; /* Accept the connection, getting a new socket */ wxSocketBase *sock = server.Accept(); sock->Notify(FALSE); - sock->SetNotify(wxSocketBase::REQ_READ | wxSocketBase::REQ_LOST); + sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG); stream = new wxSocketStream(*sock); codeci = new wxDataInputStream(*stream); @@ -512,3 +518,6 @@ void Server_OnRequest(wxSocketServer& server, } } } + +#endif + // wxUSE_SOCKETS