1 |
\hypertarget{group__stream__common}{ |
2 |
\section{Stream common} |
3 |
\label{group__stream__common}\index{Stream common@{Stream common}} |
4 |
} |
5 |
|
6 |
|
7 |
\subsection{Detailed Description} |
8 |
Creation methods and other common methods for socket streams. |
9 |
|
10 |
|
11 |
|
12 |
\subsection*{Functions} |
13 |
\begin{CompactItemize} |
14 |
\item |
15 |
\hyperlink{group__stream_ga0}{peak\_\-stream} \hyperlink{group__stream__common_ga0}{peak\_\-stream\_\-socket\_\-create} (struct sockaddr $\ast$name, int namelen, uint32\_\-t opt, \hyperlink{group__stream_ga1}{peak\_\-stream\_\-event\_\-callback} cb, void $\ast$context) |
16 |
\begin{CompactList}\small\item\em Creates a new socket stream from a socket address. \item\end{CompactList}\item |
17 |
\hyperlink{group__stream_ga0}{peak\_\-stream} \hyperlink{group__stream__common_ga1}{peak\_\-stream\_\-accept\_\-create} (\hyperlink{group__stream_ga0}{peak\_\-stream} ss, uint32\_\-t opt, \hyperlink{group__stream_ga1}{peak\_\-stream\_\-event\_\-callback} cb, void $\ast$context) |
18 |
\begin{CompactList}\small\item\em Creates a new socket stream from a incoming connection on a listening stream. \item\end{CompactList}\item |
19 |
\hyperlink{group__stream_ga0}{peak\_\-stream} \hyperlink{group__stream__common_ga2}{peak\_\-stream\_\-raw\_\-create} (int fd, uint32\_\-t opt, \hyperlink{group__stream_ga1}{peak\_\-stream\_\-event\_\-callback} cb, void $\ast$context) |
20 |
\begin{CompactList}\small\item\em Creates a new socket stream from a \char`\"{}raw\char`\"{} file descriptor (which must be a valid opened socket). \item\end{CompactList}\item |
21 |
int \hyperlink{group__stream__common_ga3}{peak\_\-stream\_\-is\_\-open} (\hyperlink{group__stream_ga0}{peak\_\-stream} s) |
22 |
\begin{CompactList}\small\item\em Test is a socket stream is open. \item\end{CompactList}\item |
23 |
int \hyperlink{group__stream__common_ga4}{peak\_\-stream\_\-get\_\-error} (\hyperlink{group__stream_ga0}{peak\_\-stream} s) |
24 |
\begin{CompactList}\small\item\em Get last stream system error code. \item\end{CompactList}\item |
25 |
int \hyperlink{group__stream__common_ga5}{peak\_\-stream\_\-get\_\-address} (\hyperlink{group__stream_ga0}{peak\_\-stream} s, struct sockaddr $\ast$name, int $\ast$namelen) |
26 |
\begin{CompactList}\small\item\em Get peer's name (address). \item\end{CompactList}\item |
27 |
int \hyperlink{group__stream__common_ga6}{peak\_\-stream\_\-set\_\-address} (\hyperlink{group__stream_ga0}{peak\_\-stream} s, struct sockaddr $\ast$name, int namelen) |
28 |
\begin{CompactList}\small\item\em Assign a name (address) to an unnamed socket. \item\end{CompactList}\item |
29 |
int \hyperlink{group__stream__common_ga7}{peak\_\-stream\_\-connect} (\hyperlink{group__stream_ga0}{peak\_\-stream} s) |
30 |
\begin{CompactList}\small\item\em Connect the stream. \item\end{CompactList}\item |
31 |
void \hyperlink{group__stream__common_ga8}{peak\_\-stream\_\-disconnect} (\hyperlink{group__stream_ga0}{peak\_\-stream} s) |
32 |
\begin{CompactList}\small\item\em Disconnect the stream. \item\end{CompactList}\item |
33 |
void $\ast$ \hyperlink{group__stream__common_ga9}{peak\_\-stream\_\-get\_\-context} (\hyperlink{group__stream_ga0}{peak\_\-stream} s) |
34 |
\begin{CompactList}\small\item\em Get the context pointer of a stream. \item\end{CompactList}\item |
35 |
void \hyperlink{group__stream__common_ga10}{peak\_\-stream\_\-set\_\-context} (\hyperlink{group__stream_ga0}{peak\_\-stream} s, void $\ast$context) |
36 |
\begin{CompactList}\small\item\em Change the context pointer of a stream. \item\end{CompactList}\item |
37 |
size\_\-t \hyperlink{group__stream__common_ga11}{peak\_\-stream\_\-get\_\-read\_\-count} (\hyperlink{group__stream_ga0}{peak\_\-stream} s) |
38 |
\begin{CompactList}\small\item\em Get amount of bytes actually read from the stream. \item\end{CompactList}\item |
39 |
size\_\-t \hyperlink{group__stream__common_ga12}{peak\_\-stream\_\-get\_\-write\_\-count} (\hyperlink{group__stream_ga0}{peak\_\-stream} s) |
40 |
\begin{CompactList}\small\item\em Get amount of bytes actually written to the stream. \item\end{CompactList}\item |
41 |
void \hyperlink{group__stream__common_ga13}{peak\_\-stream\_\-set\_\-timeout} (\hyperlink{group__stream_ga0}{peak\_\-stream} s, int timeout) |
42 |
\begin{CompactList}\small\item\em Configure event timeout checking for a specified stream. \item\end{CompactList}\end{CompactItemize} |
43 |
|
44 |
|
45 |
\subsection{Function Documentation} |
46 |
\hypertarget{group__stream__common_ga1}{ |
47 |
\index{stream_common@{stream\_\-common}!peak_stream_accept_create@{peak\_\-stream\_\-accept\_\-create}} |
48 |
\index{peak_stream_accept_create@{peak\_\-stream\_\-accept\_\-create}!stream_common@{stream\_\-common}} |
49 |
\subsubsection[peak\_\-stream\_\-accept\_\-create]{\setlength{\rightskip}{0pt plus 5cm}\hyperlink{group__stream_ga0}{peak\_\-stream} peak\_\-stream\_\-accept\_\-create (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em ss}, uint32\_\-t {\em opt}, \hyperlink{group__stream_ga1}{peak\_\-stream\_\-event\_\-callback} {\em cb}, void $\ast$ {\em context})}} |
50 |
\label{group__stream__common_ga1} |
51 |
|
52 |
|
53 |
Creates a new socket stream from a incoming connection on a listening stream. |
54 |
|
55 |
\begin{Desc} |
56 |
\item[Parameters:] |
57 |
\begin{description} |
58 |
\item[{\em ss}]The server's socket stream that got a PEAK\_\-STREAM\_\-EVT\_\-ACCEPT event. \item[{\em opt}]Stream creation options. \item[{\em cb}]A pointer to your notification callback function that handles events that will occur on this stream once scheduled. \item[{\em context}]An extra application-defined pointer that will be passed to your event callback function (it's not used by the library).\end{description} |
59 |
\end{Desc} |
60 |
\begin{Desc} |
61 |
\item[Returns:]A newly allocated peak\_\-stream reference or NULL if the stream cannot be created. \end{Desc} |
62 |
\hypertarget{group__stream__common_ga7}{ |
63 |
\index{stream_common@{stream\_\-common}!peak_stream_connect@{peak\_\-stream\_\-connect}} |
64 |
\index{peak_stream_connect@{peak\_\-stream\_\-connect}!stream_common@{stream\_\-common}} |
65 |
\subsubsection[peak\_\-stream\_\-connect]{\setlength{\rightskip}{0pt plus 5cm}int peak\_\-stream\_\-connect (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s})}} |
66 |
\label{group__stream__common_ga7} |
67 |
|
68 |
|
69 |
Connect the stream. |
70 |
|
71 |
\begin{Desc} |
72 |
\item[Parameters:] |
73 |
\begin{description} |
74 |
\item[{\em s}]The stream reference.\end{description} |
75 |
\end{Desc} |
76 |
\begin{Desc} |
77 |
\item[Return values:] |
78 |
\begin{description} |
79 |
\item[{\em 0}]if the operation is successful. \item[{\em -1}]if the connection to the remote host failed. \end{description} |
80 |
\end{Desc} |
81 |
\hypertarget{group__stream__common_ga8}{ |
82 |
\index{stream_common@{stream\_\-common}!peak_stream_disconnect@{peak\_\-stream\_\-disconnect}} |
83 |
\index{peak_stream_disconnect@{peak\_\-stream\_\-disconnect}!stream_common@{stream\_\-common}} |
84 |
\subsubsection[peak\_\-stream\_\-disconnect]{\setlength{\rightskip}{0pt plus 5cm}void peak\_\-stream\_\-disconnect (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s})}} |
85 |
\label{group__stream__common_ga8} |
86 |
|
87 |
|
88 |
Disconnect the stream. |
89 |
|
90 |
\begin{Desc} |
91 |
\item[Parameters:] |
92 |
\begin{description} |
93 |
\item[{\em s}]The stream reference. \end{description} |
94 |
\end{Desc} |
95 |
\hypertarget{group__stream__common_ga5}{ |
96 |
\index{stream_common@{stream\_\-common}!peak_stream_get_address@{peak\_\-stream\_\-get\_\-address}} |
97 |
\index{peak_stream_get_address@{peak\_\-stream\_\-get\_\-address}!stream_common@{stream\_\-common}} |
98 |
\subsubsection[peak\_\-stream\_\-get\_\-address]{\setlength{\rightskip}{0pt plus 5cm}int peak\_\-stream\_\-get\_\-address (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s}, struct sockaddr $\ast$ {\em name}, int $\ast$ {\em namelen})}} |
99 |
\label{group__stream__common_ga5} |
100 |
|
101 |
|
102 |
Get peer's name (address). |
103 |
|
104 |
\begin{Desc} |
105 |
\item[Parameters:] |
106 |
\begin{description} |
107 |
\item[{\em s}]The stream reference. \item[{\em name}]A pointer to an allocated space for the address, enough to hold it (eg. a struct sockaddr\_\-in for an IPv4 address). \item[{\em namelen}]Input/output argument, should be initialized to indicate the amount of size pointed to by {\em name\/}. On return it contains the actual size of the name returned (in bytes).\end{description} |
108 |
\end{Desc} |
109 |
\begin{Desc} |
110 |
\item[Return values:] |
111 |
\begin{description} |
112 |
\item[{\em 0}]if the operation is successful. \item[{\em -1}]if the buffer {\em name\/} is too small. \end{description} |
113 |
\end{Desc} |
114 |
\hypertarget{group__stream__common_ga9}{ |
115 |
\index{stream_common@{stream\_\-common}!peak_stream_get_context@{peak\_\-stream\_\-get\_\-context}} |
116 |
\index{peak_stream_get_context@{peak\_\-stream\_\-get\_\-context}!stream_common@{stream\_\-common}} |
117 |
\subsubsection[peak\_\-stream\_\-get\_\-context]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ peak\_\-stream\_\-get\_\-context (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s})}} |
118 |
\label{group__stream__common_ga9} |
119 |
|
120 |
|
121 |
Get the context pointer of a stream. |
122 |
|
123 |
\begin{Desc} |
124 |
\item[Parameters:] |
125 |
\begin{description} |
126 |
\item[{\em s}]The stream reference.\end{description} |
127 |
\end{Desc} |
128 |
\begin{Desc} |
129 |
\item[Returns:]The application-defined pointer. \end{Desc} |
130 |
\hypertarget{group__stream__common_ga4}{ |
131 |
\index{stream_common@{stream\_\-common}!peak_stream_get_error@{peak\_\-stream\_\-get\_\-error}} |
132 |
\index{peak_stream_get_error@{peak\_\-stream\_\-get\_\-error}!stream_common@{stream\_\-common}} |
133 |
\subsubsection[peak\_\-stream\_\-get\_\-error]{\setlength{\rightskip}{0pt plus 5cm}int peak\_\-stream\_\-get\_\-error (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s})}} |
134 |
\label{group__stream__common_ga4} |
135 |
|
136 |
|
137 |
Get last stream system error code. |
138 |
|
139 |
Returns the last socket or system error code as defined in sys/errno.h. |
140 |
|
141 |
\begin{Desc} |
142 |
\item[Parameters:] |
143 |
\begin{description} |
144 |
\item[{\em s}]The stream reference.\end{description} |
145 |
\end{Desc} |
146 |
\begin{Desc} |
147 |
\item[Returns:]The error code. \end{Desc} |
148 |
\hypertarget{group__stream__common_ga11}{ |
149 |
\index{stream_common@{stream\_\-common}!peak_stream_get_read_count@{peak\_\-stream\_\-get\_\-read\_\-count}} |
150 |
\index{peak_stream_get_read_count@{peak\_\-stream\_\-get\_\-read\_\-count}!stream_common@{stream\_\-common}} |
151 |
\subsubsection[peak\_\-stream\_\-get\_\-read\_\-count]{\setlength{\rightskip}{0pt plus 5cm}size\_\-t peak\_\-stream\_\-get\_\-read\_\-count (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s})}} |
152 |
\label{group__stream__common_ga11} |
153 |
|
154 |
|
155 |
Get amount of bytes actually read from the stream. |
156 |
|
157 |
Statistical function. |
158 |
|
159 |
\begin{Desc} |
160 |
\item[Parameters:] |
161 |
\begin{description} |
162 |
\item[{\em s}]The stream reference.\end{description} |
163 |
\end{Desc} |
164 |
\begin{Desc} |
165 |
\item[Returns:]Number of bytes read since the stream's creation. \end{Desc} |
166 |
\hypertarget{group__stream__common_ga12}{ |
167 |
\index{stream_common@{stream\_\-common}!peak_stream_get_write_count@{peak\_\-stream\_\-get\_\-write\_\-count}} |
168 |
\index{peak_stream_get_write_count@{peak\_\-stream\_\-get\_\-write\_\-count}!stream_common@{stream\_\-common}} |
169 |
\subsubsection[peak\_\-stream\_\-get\_\-write\_\-count]{\setlength{\rightskip}{0pt plus 5cm}size\_\-t peak\_\-stream\_\-get\_\-write\_\-count (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s})}} |
170 |
\label{group__stream__common_ga12} |
171 |
|
172 |
|
173 |
Get amount of bytes actually written to the stream. |
174 |
|
175 |
Statistical function. |
176 |
|
177 |
\begin{Desc} |
178 |
\item[Parameters:] |
179 |
\begin{description} |
180 |
\item[{\em s}]The stream reference.\end{description} |
181 |
\end{Desc} |
182 |
\begin{Desc} |
183 |
\item[Returns:]Number of bytes written since the stream's creation. \end{Desc} |
184 |
\hypertarget{group__stream__common_ga3}{ |
185 |
\index{stream_common@{stream\_\-common}!peak_stream_is_open@{peak\_\-stream\_\-is\_\-open}} |
186 |
\index{peak_stream_is_open@{peak\_\-stream\_\-is\_\-open}!stream_common@{stream\_\-common}} |
187 |
\subsubsection[peak\_\-stream\_\-is\_\-open]{\setlength{\rightskip}{0pt plus 5cm}int peak\_\-stream\_\-is\_\-open (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s})}} |
188 |
\label{group__stream__common_ga3} |
189 |
|
190 |
|
191 |
Test is a socket stream is open. |
192 |
|
193 |
An open stream is a connected socket for connection oriented streams. |
194 |
|
195 |
\begin{Desc} |
196 |
\item[Parameters:] |
197 |
\begin{description} |
198 |
\item[{\em s}]The stream reference.\end{description} |
199 |
\end{Desc} |
200 |
\begin{Desc} |
201 |
\item[Return values:] |
202 |
\begin{description} |
203 |
\item[{\em 0}]Stream not open. \item[{\em 1}]Stream open. \end{description} |
204 |
\end{Desc} |
205 |
\hypertarget{group__stream__common_ga2}{ |
206 |
\index{stream_common@{stream\_\-common}!peak_stream_raw_create@{peak\_\-stream\_\-raw\_\-create}} |
207 |
\index{peak_stream_raw_create@{peak\_\-stream\_\-raw\_\-create}!stream_common@{stream\_\-common}} |
208 |
\subsubsection[peak\_\-stream\_\-raw\_\-create]{\setlength{\rightskip}{0pt plus 5cm}\hyperlink{group__stream_ga0}{peak\_\-stream} peak\_\-stream\_\-raw\_\-create (int {\em fd}, uint32\_\-t {\em opt}, \hyperlink{group__stream_ga1}{peak\_\-stream\_\-event\_\-callback} {\em cb}, void $\ast$ {\em context})}} |
209 |
\label{group__stream__common_ga2} |
210 |
|
211 |
|
212 |
Creates a new socket stream from a \char`\"{}raw\char`\"{} file descriptor (which must be a valid opened socket). |
213 |
|
214 |
\begin{Desc} |
215 |
\item[Parameters:] |
216 |
\begin{description} |
217 |
\item[{\em fd}]The socket file descriptor. \item[{\em opt}]Stream creation options. \item[{\em cb}]A pointer to your notification callback function that handles events that will occur on this stream once scheduled. \item[{\em context}]An extra application-defined pointer that will be passed to your event callback function (it's not used by the library).\end{description} |
218 |
\end{Desc} |
219 |
\begin{Desc} |
220 |
\item[Returns:]A newly allocated peak\_\-stream reference or NULL if the stream cannot be created. \end{Desc} |
221 |
\hypertarget{group__stream__common_ga6}{ |
222 |
\index{stream_common@{stream\_\-common}!peak_stream_set_address@{peak\_\-stream\_\-set\_\-address}} |
223 |
\index{peak_stream_set_address@{peak\_\-stream\_\-set\_\-address}!stream_common@{stream\_\-common}} |
224 |
\subsubsection[peak\_\-stream\_\-set\_\-address]{\setlength{\rightskip}{0pt plus 5cm}int peak\_\-stream\_\-set\_\-address (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s}, struct sockaddr $\ast$ {\em name}, int {\em namelen})}} |
225 |
\label{group__stream__common_ga6} |
226 |
|
227 |
|
228 |
Assign a name (address) to an unnamed socket. |
229 |
|
230 |
This function allow you to bind the stream to a local address which is not the default (eg. for a vhost). Not for use with streams with the {\tt PEAK\_\-STREAM\_\-OPT\_\-LISTEN} option flag. |
231 |
|
232 |
\begin{Desc} |
233 |
\item[Parameters:] |
234 |
\begin{description} |
235 |
\item[{\em s}]The stream reference. \item[{\em name}]A pointer to a structure describing the name (address) to assign to the stream socket. \item[{\em namelen}]The length of the pointed structure by name.\end{description} |
236 |
\end{Desc} |
237 |
\begin{Desc} |
238 |
\item[Return values:] |
239 |
\begin{description} |
240 |
\item[{\em 0}]if the operation is successful. \item[{\em -1}]otherwise. \end{description} |
241 |
\end{Desc} |
242 |
\hypertarget{group__stream__common_ga10}{ |
243 |
\index{stream_common@{stream\_\-common}!peak_stream_set_context@{peak\_\-stream\_\-set\_\-context}} |
244 |
\index{peak_stream_set_context@{peak\_\-stream\_\-set\_\-context}!stream_common@{stream\_\-common}} |
245 |
\subsubsection[peak\_\-stream\_\-set\_\-context]{\setlength{\rightskip}{0pt plus 5cm}void peak\_\-stream\_\-set\_\-context (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s}, void $\ast$ {\em context})}} |
246 |
\label{group__stream__common_ga10} |
247 |
|
248 |
|
249 |
Change the context pointer of a stream. |
250 |
|
251 |
\begin{Desc} |
252 |
\item[Parameters:] |
253 |
\begin{description} |
254 |
\item[{\em s}]The stream reference. \item[{\em context}]An extra application-defined pointer that will be passed to your event callback function (it's not used by the library). \end{description} |
255 |
\end{Desc} |
256 |
\hypertarget{group__stream__common_ga13}{ |
257 |
\index{stream_common@{stream\_\-common}!peak_stream_set_timeout@{peak\_\-stream\_\-set\_\-timeout}} |
258 |
\index{peak_stream_set_timeout@{peak\_\-stream\_\-set\_\-timeout}!stream_common@{stream\_\-common}} |
259 |
\subsubsection[peak\_\-stream\_\-set\_\-timeout]{\setlength{\rightskip}{0pt plus 5cm}void peak\_\-stream\_\-set\_\-timeout (\hyperlink{group__stream_ga0}{peak\_\-stream} {\em s}, int {\em timeout})}} |
260 |
\label{group__stream__common_ga13} |
261 |
|
262 |
|
263 |
Configure event timeout checking for a specified stream. |
264 |
|
265 |
This is a convenience feature. First, because an explicit timer isn't needed to check stream's timeout in your application anymore. But for thread safety too: when peak is not explicitely configured to use only one thread, an independant timer might be processed at the same time with an event on the stream, so you need to add mutual exclusive region (implementation is possible with \hyperlink{group__task__sync_ga21}{peak\_\-task\_\-exclusivity()}), and verify all it's well synchronized. With \hyperlink{group__stream__common_ga53}{peak\_\-stream\_\-set\_\-timeout()} however, the timeout event acts like a normal stream events and cannot be processed at the same time with another on the same stream. |
266 |
|
267 |
\begin{Desc} |
268 |
\item[Parameters:] |
269 |
\begin{description} |
270 |
\item[{\em s}]The stream reference. \item[{\em timeout}]Time in seconds until an event of type {\em PEAK\_\-STREAM\_\-EVT\_\-TIMEDOUT\/} will be sent. Use 0 to disable timeout checking. \end{description} |
271 |
\end{Desc} |
272 |
\hypertarget{group__stream__common_ga0}{ |
273 |
\index{stream_common@{stream\_\-common}!peak_stream_socket_create@{peak\_\-stream\_\-socket\_\-create}} |
274 |
\index{peak_stream_socket_create@{peak\_\-stream\_\-socket\_\-create}!stream_common@{stream\_\-common}} |
275 |
\subsubsection[peak\_\-stream\_\-socket\_\-create]{\setlength{\rightskip}{0pt plus 5cm}\hyperlink{group__stream_ga0}{peak\_\-stream} peak\_\-stream\_\-socket\_\-create (struct sockaddr $\ast$ {\em name}, int {\em namelen}, uint32\_\-t {\em opt}, \hyperlink{group__stream_ga1}{peak\_\-stream\_\-event\_\-callback} {\em cb}, void $\ast$ {\em context})}} |
276 |
\label{group__stream__common_ga0} |
277 |
|
278 |
|
279 |
Creates a new socket stream from a socket address. |
280 |
|
281 |
\begin{Desc} |
282 |
\item[Parameters:] |
283 |
\begin{description} |
284 |
\item[{\em name}]Pointer to a socket's name/address. For listening sockets, this is the name/local address of the socket, but for outgoing sockets this is the name/address of the other socket. Several socket protocol types are supported (PF\_\-INET, PF\_\-INET6). \item[{\em namelen}]Length of the structure pointed by name. \item[{\em opt}]Stream creation options. \item[{\em cb}]A pointer to your notification callback function that handles events that will occur on this stream once scheduled. \item[{\em context}]An extra application-defined pointer that will be passed to your event callback function (it's not used by the library).\end{description} |
285 |
\end{Desc} |
286 |
\begin{Desc} |
287 |
\item[Returns:]A newly allocated peak\_\-stream reference or NULL if the stream cannot be created. \end{Desc} |