// Purpose: Interprocess communication implementation (wxSocket version)
// Author: Julian Smart
// Modified by: Guilhem Lavaux (big rewrite) May 1997, 1998
// Purpose: Interprocess communication implementation (wxSocket version)
// Author: Julian Smart
// Modified by: Guilhem Lavaux (big rewrite) May 1997, 1998
GetAddressFromName(const wxString& serverName, const wxString& host = wxEmptyString)
{
// we always use INET sockets under non-Unix systems
GetAddressFromName(const wxString& serverName, const wxString& host = wxEmptyString)
{
// we always use INET sockets under non-Unix systems
// under Unix, if the server name looks like a path, create a AF_UNIX
// socket instead of AF_INET one
if ( serverName.Find(_T('/')) != wxNOT_FOUND )
// under Unix, if the server name looks like a path, create a AF_UNIX
// socket instead of AF_INET one
if ( serverName.Find(_T('/')) != wxNOT_FOUND )
wxSocketClient *client = new wxSocketClient(SCKIPC_FLAGS);
wxSocketStream *stream = new wxSocketStream(*client);
wxDataInputStream *data_is = new wxDataInputStream(*stream);
wxDataOutputStream *data_os = new wxDataOutputStream(*stream);
wxSocketClient *client = new wxSocketClient(SCKIPC_FLAGS);
wxSocketStream *stream = new wxSocketStream(*client);
wxDataInputStream *data_is = new wxDataInputStream(*stream);
wxDataOutputStream *data_os = new wxDataOutputStream(*stream);
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPConnection::Request") );
m_sockstrm->Read(data, s);
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPConnection::Request") );
m_sockstrm->Read(data, s);
-bool wxTCPConnection::Poke (const wxString& item, wxChar *data, int size, wxIPCFormat format)
+bool wxTCPConnection::DoPoke (const wxString& item, const void *data, size_t size, wxIPCFormat format)
-bool wxTCPConnection::Advise (const wxString& item,
- wxChar *data, int size, wxIPCFormat format)
+bool wxTCPConnection::DoAdvise (const wxString& item,
+ const void *data, size_t size, wxIPCFormat format)
void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
{
wxSocketBase *sock = event.GetSocket();
void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
{
wxSocketBase *sock = event.GetSocket();
wxSocketNotify evt = event.GetSocketEvent();
wxTCPConnection *connection = (wxTCPConnection *)(sock->GetClientData());
wxSocketNotify evt = event.GetSocketEvent();
wxTCPConnection *connection = (wxTCPConnection *)(sock->GetClientData());
data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
- format = (wxIPCFormat)codeci->Read8();
- size = codeci->Read32();
- data = connection->GetBufferAtLeast( size );
+ wxIPCFormat format = (wxIPCFormat)codeci->Read8();
+ size_t size = codeci->Read32();
+ void *data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size);
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size);
- format = (wxIPCFormat)codeci->Read8();
- size = codeci->Read32();
- data = connection->GetBufferAtLeast( size );
+ wxIPCFormat format = (wxIPCFormat)codeci->Read8();
+ size_t size = codeci->Read32();
+ void *data = connection->GetBufferAtLeast( size );
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size);
wxASSERT_MSG(data != NULL,
_T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size);
- int user_size = -1;
- wxChar *user_data = connection->OnRequest (topic_name, item, &user_size, format);
+ size_t user_size = wxNO_LEN;
+ const void *user_data = connection->OnRequest (topic_name, item, &user_size, format);
- if (user_size == -1)
- user_size = (wxStrlen(user_data) + 1) * sizeof(wxChar); // includes final NUL
+ if (user_size == wxNO_LEN)
+ {
+ switch (format)
+ {
+ case wxIPC_TEXT:
+ case wxIPC_UTF8TEXT:
+ user_size = strlen((const char *)user_data) + 1; // includes final NUL
+ break;
+ case wxIPC_UNICODETEXT:
+ user_size = (wcslen((const wchar_t *)user_data) + 1) * sizeof(wchar_t); // includes final NUL
+ break;
+ default:
+ user_size = 0;
+ }
+ }
codeco->Write32(user_size);
sockstrm->Write(user_data, user_size);
codeco->Write32(user_size);
sockstrm->Write(user_data, user_size);
void wxTCPEventHandler::Server_OnRequest(wxSocketEvent &event)
{
wxSocketServer *server = (wxSocketServer *) event.GetSocket();
void wxTCPEventHandler::Server_OnRequest(wxSocketEvent &event)
{
wxSocketServer *server = (wxSocketServer *) event.GetSocket();
wxTCPServer *ipcserv = (wxTCPServer *) server->GetClientData();
// This socket is being deleted; skip this event
wxTCPServer *ipcserv = (wxTCPServer *) server->GetClientData();
// This socket is being deleted; skip this event
// Accept the connection, getting a new socket
wxSocketBase *sock = server->Accept();
// Accept the connection, getting a new socket
wxSocketBase *sock = server->Accept();