GetAddressFromName(const wxString& serverName, const wxString& host = _T(""))
{
// we always use INET sockets under non-Unix systems
-#ifdef __UNIX_LIKE__
+#if defined(__UNIX__) && !defined(__WXMAC__)
// 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 )
if ( ok )
{
unsigned char msg;
-
+
// Send topic name, and enquire whether this has succeeded
data_os->Write8(IPC_CONNECT);
data_os->WriteString(topic);
-
+
msg = data_is->Read8();
// OK! Confirmation.
{
// ensure that the file doesn't exist as otherwise calling socket() would
// fail
- int rc = remove(serverName);
+ int rc = remove(serverName.fn_str());
if ( rc < 0 && errno != ENOENT )
{
delete addr;
#ifdef __UNIX_LIKE__
if ( !m_filename.empty() )
{
- if ( !remove(m_filename) )
+ if ( remove(m_filename.fn_str()) != 0 )
{
wxLogDebug(_T("Stale AF_UNIX file '%s' left."), m_filename.c_str());
}
m_codeco = NULL;
}
-wxTCPConnection::wxTCPConnection(char * WXUNUSED(buffer), int WXUNUSED(size))
+wxTCPConnection::wxTCPConnection(wxChar *buffer, int size)
+ : wxConnectionBase(buffer, size)
{
+ m_sock = NULL;
+ m_sockstrm = NULL;
+ m_codeci = NULL;
+ m_codeco = NULL;
}
wxTCPConnection::~wxTCPConnection ()
{
+ Disconnect();
wxDELETE(m_codeci);
wxDELETE(m_codeco);
wxDELETE(m_sockstrm);
// Calls that CLIENT can make.
bool wxTCPConnection::Disconnect ()
{
+ if ( !GetConnected() )
+ return TRUE;
// Send the the disconnect message to the peer.
m_codeco->Write8(IPC_DISCONNECT);
m_sock->Notify(FALSE);
m_sock->Close();
+ SetConnected(false);
return TRUE;
}
else
{
size_t s;
- char *data = NULL;
s = m_codeci->Read32();
- data = new char[s];
+ wxChar *data = GetBufferAtLeast( s );
+ wxASSERT_MSG(data != NULL,
+ _T("Buffer too small in wxTCPConnection::Request") );
m_sockstrm->Read(data, s);
if (size)
int msg = 0;
wxDataInputStream *codeci;
- wxDataOutputStream *codeco;
+ wxDataOutputStream *codeco;
wxSocketStream *sockstrm;
wxString topic_name = connection->m_topic;
wxString item;
case IPC_EXECUTE:
{
char *data;
- size_t size;
+ size_t size;
wxIPCFormat format;
-
+
format = (wxIPCFormat)codeci->Read8();
size = codeci->Read32();
- data = new char[size];
+ data = connection->GetBufferAtLeast( size );
+ wxASSERT_MSG(data != NULL,
+ _T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size);
connection->OnExecute (topic_name, data, size, format);
- delete [] data;
break;
}
case IPC_ADVISE:
item = codeci->ReadString();
format = (wxIPCFormat)codeci->Read8();
size = codeci->Read32();
- data = new char[size];
+ data = connection->GetBufferAtLeast( size );
+ wxASSERT_MSG(data != NULL,
+ _T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size);
-
+
connection->OnAdvise (topic_name, item, data, size, format);
- delete [] data;
break;
}
case IPC_ADVISE_START:
item = codeci->ReadString();
format = (wxIPCFormat)codeci->Read8();
size = codeci->Read32();
- data = new wxChar[size];
+ data = connection->GetBufferAtLeast( size );
+ wxASSERT_MSG(data != NULL,
+ _T("Buffer too small in wxTCPEventHandler::Client_OnRequest") );
sockstrm->Read(data, size);
-
- connection->OnPoke (topic_name, item, data, size, format);
- delete [] data;
+ connection->OnPoke (topic_name, item, data, size, format);
break;
}
{
sock->Notify(FALSE);
sock->Close();
+ connection->SetConnected(false);
connection->OnDisconnect();
break;
}
// Acknowledge success
codeco->Write8(IPC_CONNECT);
new_connection->m_topic = topic_name;
- new_connection->m_sock = sock;
+ new_connection->m_sock = sock;
new_connection->m_sockstrm = stream;
new_connection->m_codeci = codeci;
new_connection->m_codeco = codeco;