*/
-#include "silcincludes.h"
+#include "silc.h"
+
+/************************** Types and definitions ***************************/
#define SILC_IS_SOCKET_STREAM(s) (s->ops == &silc_socket_stream_ops)
unsigned int aborted : 1;
} *SilcSocketHostLookup;
+
+/************************ Static utility functions **************************/
+
/* The IO process callback that calls the notifier callback to upper
layer. */
stream = lookup->stream = NULL;
}
- /* Add the socket to scheduler */
- if (stream) {
- silc_schedule_task_add_fd(stream->schedule, stream->sock,
- silc_socket_stream_io, stream);
-
- /* Initially set socket for reading */
- silc_schedule_set_listen_fd(stream->schedule, stream->sock,
- SILC_TASK_READ, FALSE);
- }
-
/* Return the created socket stream to the caller */
if (lookup->callback)
lookup->callback(lookup->status, stream, lookup->context);
lookup->aborted = TRUE;
}
+
+/******************************* Public API *********************************/
+
/* Creates socket stream */
SilcAsyncOperation
/* Returns socket stream information */
SilcBool silc_socket_stream_get_info(SilcStream stream,
- int *sock, const char **hostname,
- const char **ip, SilcUInt16 *port)
+ int *sock, const char **hostname,
+ const char **ip, SilcUInt16 *port)
{
SilcSocketStream socket_stream = stream;
/* Set socket information */
SilcBool silc_socket_stream_set_info(SilcStream stream,
- const char *hostname,
- const char *ip, SilcUInt16 port)
+ const char *hostname,
+ const char *ip, SilcUInt16 port)
{
SilcSocketStream socket_stream = stream;
/* Set QoS for socket stream */
SilcBool silc_socket_stream_set_qos(SilcStream stream,
- SilcUInt32 read_rate,
- SilcUInt32 read_limit_bytes,
- SilcUInt32 limit_sec,
- SilcUInt32 limit_usec)
+ SilcUInt32 read_rate,
+ SilcUInt32 read_limit_bytes,
+ SilcUInt32 limit_sec,
+ SilcUInt32 limit_usec)
{
SilcSocketStream socket_stream = stream;
silc_socket_stream_close(socket_stream);
silc_free(socket_stream->ip);
silc_free(socket_stream->hostname);
+ silc_schedule_task_del_by_fd(socket_stream->schedule, socket_stream->sock);
if (socket_stream->qos) {
silc_schedule_task_del_by_context(socket_stream->schedule,
/* Sets stream notification callback for the stream */
void silc_socket_stream_notifier(SilcStream stream,
+ SilcSchedule schedule,
SilcStreamNotifier callback,
void *context)
{
socket_stream->notifier = callback;
socket_stream->notifier_context = context;
+ socket_stream->schedule = schedule;
+
+ if (socket_stream->notifier) {
+ /* Add the socket to scheduler. Safe to call if already added. */
+ silc_schedule_task_add_fd(socket_stream->schedule, socket_stream->sock,
+ silc_socket_stream_io, socket_stream);
+
+ /* Initially set socket for reading */
+ silc_schedule_set_listen_fd(socket_stream->schedule, socket_stream->sock,
+ SILC_TASK_READ, FALSE);
+ } else {
+ /* Unschedule the socket */
+ silc_schedule_unset_listen_fd(socket_stream->schedule,
+ socket_stream->sock);
+ silc_schedule_task_del_by_fd(socket_stream->schedule,
+ socket_stream->sock);
+ }
+}
+
+/* Return associated scheduler */
+
+SilcSchedule silc_socket_stream_get_schedule(SilcStream stream)
+{
+ SilcSocketStream socket_stream = stream;
+
+ if (!SILC_IS_SOCKET_STREAM(socket_stream))
+ return NULL;
+
+ return socket_stream->schedule;
}
/* SILC Socket Stream ops. Functions are implemented under the
silc_socket_stream_close,
silc_socket_stream_destroy,
silc_socket_stream_notifier,
+ silc_socket_stream_get_schedule,
};