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
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. */
typedef struct {
SilcSocketStream stream;
- SilcSocketStreamStatus status;
+ SilcResult status;
SilcSocketStreamCallback callback;
SilcAsyncOperation op;
void *context;
return;
}
- if (lookup->status != SILC_SOCKET_OK) {
- SILC_LOG_DEBUG(("Socket stream failed"));
+ if (lookup->status != SILC_OK) {
+ SILC_LOG_DEBUG(("Socket stream lookup failed"));
stream->schedule = NULL;
silc_socket_stream_destroy(stream);
stream = lookup->stream = NULL;
silc_net_check_host_by_sock(stream->sock, &stream->hostname, &stream->ip);
if (!stream->ip) {
- lookup->status = SILC_SOCKET_UNKNOWN_IP;
+ lookup->status = SILC_ERR_UNKNOWN_IP;
goto out;
}
if (!stream->hostname && lookup->require_fqdn) {
- lookup->status = SILC_SOCKET_UNKNOWN_HOST;
+ lookup->status = SILC_ERR_UNKNOWN_HOST;
goto out;
}
if (!stream->hostname) {
- stream->hostname = strdup(stream->ip);
+ stream->hostname = silc_strdup(stream->ip);
if (!stream->hostname) {
- lookup->status = SILC_SOCKET_NO_MEMORY;
+ lookup->status = SILC_ERR_OUT_OF_MEMORY;
goto out;
}
}
- lookup->status = SILC_SOCKET_OK;
+ lookup->status = SILC_OK;
out:
silc_schedule_task_add_timeout(schedule, silc_socket_host_lookup_finish,
SilcSocketStream stream;
SilcSocketHostLookup l;
+ if (!schedule) {
+ schedule = silc_schedule_get_global();
+ if (!schedule) {
+ silc_set_errno(SILC_ERR_INVALID_ARGUMENT);
+ if (callback)
+ callback(silc_errno, NULL, context);
+ return NULL;
+ }
+ }
+
if (!sock) {
+ silc_set_errno(SILC_ERR_INVALID_ARGUMENT);
if (callback)
- callback(SILC_SOCKET_ERROR, NULL, context);
+ callback(silc_errno, NULL, context);
return NULL;
}
stream = silc_calloc(1, sizeof(*stream));
if (!stream) {
if (callback)
- callback(SILC_SOCKET_NO_MEMORY, NULL, context);
+ callback(silc_errno, NULL, context);
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) {
silc_free(stream);
if (callback)
- callback(SILC_SOCKET_NO_MEMORY, NULL, context);
+ callback(silc_errno, NULL, context);
return NULL;
}
silc_free(stream);
silc_free(l);
if (callback)
- callback(SILC_SOCKET_ERROR, NULL, context);
+ callback(silc_errno, NULL, context);
return NULL;
}
return l->op;
} else {
/* No lookup */
- l->status = SILC_SOCKET_OK;
+ l->status = SILC_OK;
silc_socket_host_lookup_finish(schedule,
silc_schedule_get_context(schedule),
0, 0, l);
{
SilcSocketStream stream;
+ if (!schedule) {
+ schedule = silc_schedule_get_global();
+ if (!schedule) {
+ silc_set_errno(SILC_ERR_INVALID_ARGUMENT);
+ return NULL;
+ }
+ }
+
stream = silc_calloc(1, sizeof(*stream));
if (!stream)
return NULL;
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;
if (hostname) {
silc_free(socket_stream->hostname);
- socket_stream->hostname = strdup(hostname);
+ socket_stream->hostname = silc_strdup(hostname);
if (!socket_stream->hostname)
return FALSE;
}
if (ip) {
silc_free(socket_stream->ip);
- socket_stream->ip = strdup(ip);
+ socket_stream->ip = silc_strdup(ip);
if (!socket_stream->ip)
return FALSE;
if (!socket_stream->hostname) {
- socket_stream->hostname = strdup(ip);
+ socket_stream->hostname = silc_strdup(ip);
if (!socket_stream->hostname)
return FALSE;
}
return TRUE;
}
-/* Return socket errno */
-
-int silc_socket_stream_get_error(SilcStream stream)
-{
- SilcSocketStream socket_stream = stream;
-
- if (!SILC_IS_SOCKET_STREAM(socket_stream) &&
- !SILC_IS_SOCKET_STREAM_UDP(socket_stream))
- return 0;
-
- return socket_stream->sock_error;
-}
-
/* Set QoS for socket stream */
SilcBool silc_socket_stream_set_qos(SilcStream stream,