// Copyright: (c) Julian Smart 1993
// (c) Guilhem Lavaux 1997, 1998
// (c) 2000 Guillermo Rodriguez <guille@iies.es>
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ==========================================================================
GetAddressFromName(const wxString& serverName, const wxString& host = _T(""))
{
// we always use INET sockets under non-Unix systems
-#if defined(__UNIX__) && !defined(__WXMAC__)
+#if defined(__UNIX__) && !defined(__WXMAC__) && !defined(__WINE__)
// 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 )
{
// 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;
}
return TRUE;
}
-char *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat format)
+wxChar *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat format)
{
if (!m_sock->IsConnected())
return NULL;
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)
{
case IPC_EXECUTE:
{
- char *data;
+ wxChar *data;
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:
{
- char *data;
+ wxChar *data;
size_t size;
wxIPCFormat format;
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;
-
break;
}
case IPC_REQUEST:
format = (wxIPCFormat)codeci->Read8();
int user_size = -1;
- char *user_data = connection->OnRequest (topic_name, item, &user_size, format);
+ wxChar *user_data = connection->OnRequest (topic_name, item, &user_size, format);
if (user_data)
{
codeco->Write8(IPC_REQUEST_REPLY);
if (user_size == -1)
- user_size = strlen(user_data) + 1; // includes final NUL
+ user_size = wxStrlen(user_data) + 1; // includes final NUL
codeco->Write32(user_size);
sockstrm->Write(user_data, user_size);
{
sock->Notify(FALSE);
sock->Close();
+ connection->SetConnected(FALSE);
connection->OnDisconnect();
break;
}