Porting Toolkit to Symbian. It should work while some sporadic
[silc.git] / lib / silcutil / silcsocketstream.c
index c320644737440f01c2991fe79636de0fea0a493e..e4b59f5a601c6d0019632438514f780a48729507 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2005 - 2006 Pekka Riikonen
+  Copyright (C) 2005 - 2007 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -34,10 +34,10 @@ int silc_socket_udp_stream_write(SilcStream stream, const unsigned char *data,
                                 SilcUInt32 data_len);
 SilcBool silc_socket_stream_close(SilcStream stream);
 void silc_socket_stream_destroy(SilcStream stream);
-void silc_socket_stream_notifier(SilcStream stream,
-                                SilcSchedule schedule,
-                                SilcStreamNotifier callback,
-                                void *context);
+SilcBool silc_socket_stream_notifier(SilcStream stream,
+                                    SilcSchedule schedule,
+                                    SilcStreamNotifier callback,
+                                    void *context);
 SilcSchedule silc_socket_stream_get_schedule(SilcStream stream);
 
 /* Internal async host lookup context. */
@@ -72,7 +72,7 @@ SILC_TASK_CALLBACK(silc_socket_host_lookup_finish)
   }
 
   if (lookup->status != SILC_SOCKET_OK) {
-    SILC_LOG_DEBUG(("Socket stream failed"));
+    SILC_LOG_DEBUG(("Socket stream lookup failed"));
     stream->schedule = NULL;
     silc_socket_stream_destroy(stream);
     stream = lookup->stream = NULL;
@@ -152,7 +152,8 @@ silc_socket_tcp_stream_create(SilcSocket sock, SilcBool lookup,
   SilcSocketStream stream;
   SilcSocketHostLookup l;
 
-  if (!sock) {
+  if (!sock || !schedule) {
+    SILC_LOG_ERROR(("Missing arguments to silc_socket_tcp_stream_create"));
     if (callback)
       callback(SILC_SOCKET_ERROR, NULL, context);
     return NULL;
@@ -165,11 +166,12 @@ silc_socket_tcp_stream_create(SilcSocket sock, SilcBool lookup,
     return NULL;
   }
 
-  SILC_LOG_DEBUG(("Creating TCP socket stream %p", stream));
+  SILC_LOG_DEBUG(("Creating TCP socket stream %p, sock %lu", stream, sock));
 
   stream->ops = &silc_socket_stream_ops;
   stream->sock = sock;
   stream->schedule = schedule;
+  stream->connected = TRUE;
 
   l = silc_calloc(1, sizeof(*l));
   if (!l) {
@@ -261,20 +263,20 @@ SilcBool silc_socket_stream_get_info(SilcStream stream,
 
   if (sock)
     *sock = socket_stream->sock;
-  if (hostname) {
-    if (!socket_stream->hostname)
+  if (port) {
+    if (!socket_stream->port)
       return FALSE;
-    *hostname = socket_stream->hostname;
+    *port = socket_stream->port;
   }
   if (ip) {
     if (!socket_stream->ip)
       return FALSE;
     *ip = socket_stream->ip;
   }
-  if (port) {
-    if (!socket_stream->port)
+  if (hostname) {
+    if (!socket_stream->hostname)
       return FALSE;
-    *port = socket_stream->port;
+    *hostname = socket_stream->hostname;
   }
 
   return TRUE;