From 40729be849e8ca96bc129a35c1122286aa5f8705 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 3 Mar 2008 21:09:59 +0200 Subject: [PATCH] Changed SILC Stream API implementation static inline functions. --- lib/silcutil/Makefile.ad | 1 - lib/silcutil/silcstream.c | 63 --------------------------------------- lib/silcutil/silcstream.h | 47 +++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 70 deletions(-) delete mode 100644 lib/silcutil/silcstream.c diff --git a/lib/silcutil/Makefile.ad b/lib/silcutil/Makefile.ad index 60ca63fd..ef7efb9c 100644 --- a/lib/silcutil/Makefile.ad +++ b/lib/silcutil/Makefile.ad @@ -48,7 +48,6 @@ libsilcutil_la_SOURCES = \ silchashtable.c \ silcutf8.c \ silcstringprep.c \ - silcstream.c \ silcfdstream.c \ silcsocketstream.c \ silcfsm.c \ diff --git a/lib/silcutil/silcstream.c b/lib/silcutil/silcstream.c deleted file mode 100644 index 5e01ad39..00000000 --- a/lib/silcutil/silcstream.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - - silcstream.c - - Author: Pekka Riikonen - - Copyright (C) 2005 - 2008 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 - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -*/ - -#include "silcruntime.h" - -typedef struct { - SilcStreamOps *ops; -} *SilcStreamHeader; - -int silc_stream_read(SilcStream stream, unsigned char *buf, - SilcUInt32 buf_len) -{ - SilcStreamHeader h = stream; - return h->ops->read(stream, buf, buf_len); -} - -int silc_stream_write(SilcStream stream, const unsigned char *data, - SilcUInt32 data_len) -{ - SilcStreamHeader h = stream; - return h->ops->write(stream, data, data_len); -} - -SilcBool silc_stream_close(SilcStream stream) -{ - SilcStreamHeader h = stream; - return h->ops->close(stream); -} - -void silc_stream_destroy(SilcStream stream) -{ - SilcStreamHeader h = stream; - h->ops->destroy(stream); -} - -SilcBool silc_stream_set_notifier(SilcStream stream, SilcSchedule schedule, - SilcStreamNotifier notifier, void *context) -{ - SilcStreamHeader h = stream; - return h->ops->notifier(stream, schedule, notifier, context); -} - -SilcSchedule silc_stream_get_schedule(SilcStream stream) -{ - SilcStreamHeader h = stream; - return h->ops->get_schedule(stream); -} diff --git a/lib/silcutil/silcstream.h b/lib/silcutil/silcstream.h index 4440fa5d..b6d82d90 100644 --- a/lib/silcutil/silcstream.h +++ b/lib/silcutil/silcstream.h @@ -157,6 +157,11 @@ typedef struct { } SilcStreamOps; /***/ +/* Stream header */ +typedef struct SilcStreamHeaderObject { + SilcStreamOps *ops; +} *SilcStreamHeader, SilcStreamHeaderStruct; + /****f* silcutil/silc_stream_read * * SYNOPSIS @@ -176,8 +181,13 @@ typedef struct { * If error occurred the error code can be retrieved with silc_errno. * ***/ +static inline int silc_stream_read(SilcStream stream, unsigned char *buf, - SilcUInt32 buf_len); + SilcUInt32 buf_len) +{ + SilcStreamHeader h = stream; + return h->ops->read(stream, buf, buf_len); +} /****f* silcutil/silc_stream_write * @@ -198,8 +208,13 @@ int silc_stream_read(SilcStream stream, unsigned char *buf, * If error occurred the error code can be retrieved with silc_errno. * ***/ +static inline int silc_stream_write(SilcStream stream, const unsigned char *data, - SilcUInt32 data_len); + SilcUInt32 data_len) +{ + SilcStreamHeader h = stream; + return h->ops->write(stream, data, data_len); +} /****f* silcutil/silc_stream_close * @@ -215,7 +230,12 @@ int silc_stream_write(SilcStream stream, const unsigned char *data, * callback may be called with an error status. * ***/ -SilcBool silc_stream_close(SilcStream stream); +static inline +SilcBool silc_stream_close(SilcStream stream) +{ + SilcStreamHeader h = stream; + return h->ops->close(stream); +} /****f* silcutil/silc_stream_destroy * @@ -232,7 +252,12 @@ SilcBool silc_stream_close(SilcStream stream); * function will call it. * ***/ -void silc_stream_destroy(SilcStream stream); +static inline +void silc_stream_destroy(SilcStream stream) +{ + SilcStreamHeader h = stream; + h->ops->destroy(stream); +} /****f* silcutil/silc_stream_set_notifier * @@ -259,8 +284,13 @@ void silc_stream_destroy(SilcStream stream); * Returns TRUE on success. The `schedule' must always be non-NULL. * ***/ +static inline SilcBool silc_stream_set_notifier(SilcStream stream, SilcSchedule schedule, - SilcStreamNotifier notifier, void *context); + SilcStreamNotifier notifier, void *context) +{ + SilcStreamHeader h = stream; + return h->ops->notifier(stream, schedule, notifier, context); +} /****f* silcutil/silc_stream_get_schedule * @@ -274,6 +304,11 @@ SilcBool silc_stream_set_notifier(SilcStream stream, SilcSchedule schedule, * NULL if one has not been set for the `stream'. * ***/ -SilcSchedule silc_stream_get_schedule(SilcStream stream); +static inline +SilcSchedule silc_stream_get_schedule(SilcStream stream) +{ + SilcStreamHeader h = stream; + return h->ops->get_schedule(stream); +} #endif /* SILCSTREAM_H */ -- 2.24.0