- wxDataStream data_s(*stream);
-
- client->SetNotify(wxSocketBase::REQ_READ | wxSocketBase::REQ_LOST);
- addr.Service(server_name);
- addr.Hostname(host);
-
- if (!client->Connect(addr)) {
- delete client;
- return NULL;
- }
- client->Notify(FALSE);
-
- // Send topic name, and enquire whether this has succeeded
- unsigned char msg;
-
- data_s.Write8(IPC_CONNECT);
- data_s.WriteString(topic);
-
- msg = data_s.Read8();
-
- // OK! Confirmation.
- if (msg == IPC_CONNECT) {
- wxTCPConnection *connection = (wxTCPConnection *)OnMakeConnection ();
- if (connection) {
- if (!connection->IsKindOf(CLASSINFO(wxTCPConnection))) {
- delete connection;
- return NULL;
+ wxDataInputStream *data_is = new wxDataInputStream(*stream);
+ wxDataOutputStream *data_os = new wxDataOutputStream(*stream);
+
+ bool ok = client->Connect(*addr);
+ delete addr;
+
+ 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.
+ if (msg == IPC_CONNECT)
+ {
+ wxTCPConnection *connection = (wxTCPConnection *)OnMakeConnection ();
+
+ if (connection)
+ {
+ if (connection->IsKindOf(CLASSINFO(wxTCPConnection)))
+ {
+ connection->m_topic = topic;
+ connection->m_sock = client;
+ connection->m_sockstrm = stream;
+ connection->m_codeci = data_is;
+ connection->m_codeco = data_os;
+ client->SetEventHandler(*gs_handler, _CLIENT_ONREQUEST_ID);
+ client->SetClientData(connection);
+ client->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
+ client->Notify(true);
+ return connection;
+ }
+ else
+ {
+ delete connection;
+ // and fall through to delete everything else
+ }