5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2008 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcutil/Buffer Stream Interface
24 * Buffer stream interface to send and receive buffers. The benefit of this
25 * interface is that the receiver need not parse buffers from the received
26 * data but each buffer sent is delivered separately to the receiver
27 * callback, even if multiple buffers were received at the same time. The
28 * length of the buffer is delivered with the data. The buffer data follows
29 * a 32-bit length field in the stream.
31 * This interface is named SILC Buffer Stream API instead of simply SILC
32 * Packet API which would be more desriptive name but that API name is already
33 * used by another SILC distribution.
37 #ifndef SILCBUFFERSTREAM_H
38 #define SILCBUFFERSTREAM_H
40 /****f* silcutil/SilcBufferReceiveCallback
44 * typedef void (*SilcBufferReceiveCallback)(SilcResult status,
51 * Callback function to deliver the received `buffer' from the `stream'.
52 * The `buffer' is the buffer that was sent to the stream. If more than
53 * one buffers were sent each is delivered separately to this callback.
54 * The `status' will indicate an error if such occurred in the stream.
55 * The `buffer' is NULL in case of error. The receiver must free
59 typedef void (*SilcBufferReceiveCallback)(SilcResult status,
64 /****f* silcutil/silc_buffer_stream_create
68 * SilcStream silc_buffer_stream_create(SilcStream stream,
69 * SilcBufferReceiveCallback receiver,
74 * Creates a buffer stream and returns it. The `stream' is the underlaying
75 * stream to be used to actually send the buffer and receive buffers.
76 * The returned stream is used with this API to send the buffers. The
77 * `stream' must stay valid as long the buffer stream is used.
79 * To send buffers to the stream silc_buffer_stream_send can be used.
80 * The silc_stream_write cannot be used with the returned stream. Buffers
81 * coming from the `stream' will be delivered to the `receiver' callback.
82 * The returned stream and `context' will also be delivered to `receiver'.
84 * The returned stream must be destroyed by calling silc_stream_destroy.
85 * Other SilcStream API functions cannot be used with buffer stream.
88 SilcStream silc_buffer_stream_create(SilcStream stream,
89 SilcBufferReceiveCallback receiver,
92 /****f* silcutil/silc_buffer_stream_send
96 * SilcBool silc_buffer_stream_send(SilcStream stream,
101 * Sends `buffer' to the buffer stream indicated by `stream'. If the
102 * `stream' is not a buffer stream created by silc_buffer_stream_create
103 * this will return FALSE. Returns FALSE on error and sets silc_errno.
106 SilcBool silc_buffer_stream_send(SilcStream stream,
109 #endif /* SILCBUFFERSTREAM_H */