File: functions.texi

package info (click to toggle)
octave-sockets 1.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 940 kB
  • sloc: cpp: 1,161; python: 380; makefile: 234
file content (387 lines) | stat: -rw-r--r-- 11,640 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
@c ---------------------------------------------------
@node Sockets functions
@section Sockets functions
@cindex Sockets functions
@c Sockets functions accept
@c -----------------------------------------
@subsection accept
@cindex accept
@deftypefn {Loadable Function} {[@var{client}, @var{info}] =} accept (@var{s})
Accept incoming connection on specified socket.

Accepts an incoming connection on the socket @var{s}.
The newly created socket is returned in @var{client}, and
associated information in a struct info.

See the @command{accept} man pages for further details.

@end deftypefn
@c Sockets functions bind
@c -----------------------------------------
@subsection bind
@cindex bind
@deftypefn {Loadable Function} {} bind (@var{s}, @var{portnumber})
Bind specific socket to port number.

See the @command{bind} man pages for further details.

@end deftypefn
@c Sockets functions connect
@c -----------------------------------------
@subsection connect
@cindex connect
@deftypefn {Loadable Function} {} connect (@var{s}, @var{serverinfo})
Connect socket.

Connects the socket @var{s} following the information
in the struct @var{serverinfo} which must contain the
following fields:

@table @code
@item addr
a string with the host name to connect to

@item port
the port number to connect to (an integer)
@end table

On successful connect, the returned status is zero.

See the @command{connect} man pages for further details.
@end deftypefn
@c Sockets functions disconnect
@c -----------------------------------------
@subsection disconnect
@cindex disconnect
@deftypefn {Loadable Function} {} disconnect (@var{s})
Disconnect socket.

Disconnects the socket @var{s}.  If successful, @code{disconnect} returns 0,
otherwise, it returns -1.

Since we can't call fclose on the file descriptor directly, use this
function to disconnect the socket.

@end deftypefn
@c Sockets functions gethostbyname
@c -----------------------------------------
@subsection gethostbyname
@cindex gethostbyname
@deftypefn {Loadable Function} {@var{ipaddres} =} gethostbyname (@var{hostname})
Return IP address for host name.

For example:

@example
@group
gethostbyname ("localhost")
@result{} 127.0.0.1
@end group
@end example

See the @command{gethostbyname} man pages for details.

@end deftypefn
@c Sockets functions getsockopt
@c -----------------------------------------
@subsection getsockopt
@cindex getsockopt
@deftypefn {Loadable Function} {[@var{data}, @var{status}] =} getsockopt (@var{s}, @var{level}, @var{optname})
Get a socket option value from a socket.

Returns the value of @var{level} @var{optname} from the socket @var{s}.

Data type depends on the option used. @var{status} returns as  0 if no error.

See the @command{getsockopt} man pages for further details.

@end deftypefn
@c Sockets functions listen
@c -----------------------------------------
@subsection listen
@cindex listen
@deftypefn {Loadable Function} {} listen (@var{s}, @var{backlog})
Listen on socket for connections.

Listens on socket @var{s} for connections.  @var{backlog} specifies
how large the queue of incoming connections is allowed to
grow.

On success, zero is returned.

See the @command{listen} man pages for further details.

@end deftypefn
@c Sockets functions recv
@c -----------------------------------------
@subsection recv
@cindex recv
@deftypefn  {Loadable Function} {[@var{data}, @var{count}] =} recv (@var{s}, @var{len})
@deftypefnx {Loadable Function} {[@var{data}, @var{count}] =} recv (@var{s}, @var{len}, @var{flags})
Read data from specified socket.

Requests reading @var{len} bytes from the socket @var{s}.
The optional integer @var{flags} parameter can be used to modify the
behaviour of @code{recv}.

The read data is returned in the uint8 array @var{data}.  The number of
bytes read is returned in @var{count}.

You can get non-blocking operation by using the flag @code{MSG_DONTWAIT}
which makes the @code{recv()} call return immediately.  If there is no
data, -1 is returned in count.

See the @command{recv} man pages for further details.

@end deftypefn
@c Sockets functions recvfrom
@c -----------------------------------------
@subsection recvfrom
@cindex recvfrom
@deftypefn  {Loadable Function} {[@var{data}, @var{count}, @var{src_info}] =} recvfrom (@var{s}, @var{len})
@deftypefnx {Loadable Function} {[@var{data}, @var{count}, @var{src_info}] =} recvfrom (@var{s}, @var{len}, @var{flags})
Read data from specified socket.

Requests reading @var{len} bytes from the socket @var{s}.
The optional integer @var{flags} parameter can be used to modify the
behaviour of @code{recvfrom}.

The read data is returned in the uint8 array @var{data}.  The number of
bytes read is returned in @var{count} and a structure with fields addr and port contain the source of the
data.

You can get non-blocking operation by using the flag @code{MSG_DONTWAIT}
which makes the @code{recvfrom()} call return immediately.  If there is no
data, -1 is returned in count.

See the @command{recvfrom} man pages for further details.

@end deftypefn
@c Sockets functions select
@c -----------------------------------------
@subsection select
@cindex select
@deftypefn {Loadable Function} {[@var{status}, @var{rfdset}, @var{wfdset}, @var{efdset}] =} select (@var{nfds}, @var{rfdset}, @var{wfdset}, @var{efdset}, @var{timeout})
Wait for socket activity on selected sockets.

The fdsets are vectors of fds to check, for example [1 2 3]. Empty vectors equate to null.

nfds tests file descriptions in the range of 0 - nfds-1.

Timeout is can be either an real value for number of seconds, a struct with a tm_sec and tm_usec fields, or empty set for null.

@var{status} returns as  0 if timeout, or number of waiting sockets if ok.

See the @command{select} man pages for further details.

@end deftypefn
@c Sockets functions send
@c -----------------------------------------
@subsection send
@cindex send
@deftypefn  {Loadable Function} {@var{retval} =} send (@var{s}, @var{data})
@deftypefnx {Loadable Function} {@var{retval} =} send (@var{s}, @var{data}, @var{flags})
Send data on specified socket.

Sends data on socket @var{s}.  @var{data} should be an uint8 array or
a string.

See the @command{send} man pages for further details.

@end deftypefn
@c Sockets functions sendto
@c -----------------------------------------
@subsection sendto
@cindex sendto
@deftypefn {Loadable Function} {@var{retval} =} sendto (@var{s}, @var{data}, @var{dest_info})
@deftypefnx {Loadable Function} {@var{retval} =} sendto (@var{s}, @var{data}, @var{flags}, @var{dest_info})
Send data on specified socket.

Sends data on socket @var{s} to destination.  @var{data} should be an uint8 array or
a string.

The dest_info struct @var{dest_info} must contain the
following fields:

@table @code
@item addr
a string with the host name to send to

@item port
the port number to send to (an integer)
@end table

See the @command{sendto} man pages for further details.

@end deftypefn
@c Sockets functions setsockopt
@c -----------------------------------------
@subsection setsockopt
@cindex setsockopt
@deftypefn {Loadable Function} {@var{status} =} setsockopt (@var{s}, @var{level}, @var{optname}, @var{optvalue})
Set a socket option value on a socket.

@var{status} returns as  0 if no error.

See the @command{setsockopt} man pages for further details.

@end deftypefn
@c Sockets functions shutdown
@c -----------------------------------------
@subsection shutdown
@cindex shutdown
@deftypefn {Loadable Function} {} shutdown (@var{s}, @var{how})
Shutdown all or part of a connection of a socket.

On success, zero is returned.

See the @command{shutdown} man pages for further details.

@end deftypefn
@c Sockets functions socket
@c -----------------------------------------
@subsection socket
@cindex socket
@deftypefn  {Loadable Function} {@var{sock} =} socket ()
@deftypefnx {Loadable Function} {@var{sock} =} socket (@var{domain})
@deftypefnx {Loadable Function} {@var{sock} =} socket (@var{domain}, @var{type})
@deftypefnx {Loadable Function} {@var{sock} =} socket (@var{domain}, @var{type}, @var{protocol})
Creates a socket.

@var{domain} is an integer, where the value AF_INET
can be used to create an IPv4 socket.

@var{type} is an integer describing the socket.  When using IP, specifying
SOCK_STREAM gives a TCP socket.

@var{protocol} is currently not used and should be 0 if specified.

If no input arguments are given, default values AF_INET and
SOCK_STREAM are used.

See the local @command{socket} reference for more details.
@end deftypefn
@c ---------------------------------------------------
@node Socket constants
@section Socket constants
@cindex Socket constants
@c Socket constants AF_APPLETALK
@c -----------------------------------------
@subsection AF_APPLETALK
@cindex AF_APPLETALK
Socket constant for AF_APPLETALK

@c Socket constants AF_INET
@c -----------------------------------------
@subsection AF_INET
@cindex AF_INET
Socket constant for AF_INET

@c Socket constants AF_LOCAL
@c -----------------------------------------
@subsection AF_LOCAL
@cindex AF_LOCAL
Socket constant for AF_LOCAL

@c Socket constants AF_UNIX
@c -----------------------------------------
@subsection AF_UNIX
@cindex AF_UNIX
Socket constant for AF_UNIX

@c Socket constants MSG_DONTWAIT
@c -----------------------------------------
@subsection MSG_DONTWAIT
@cindex MSG_DONTWAIT
Socket constant for MSG_DONTWAIT

@c Socket constants MSG_PEEK
@c -----------------------------------------
@subsection MSG_PEEK
@cindex MSG_PEEK
Socket constant for MSG_PEEK

@c Socket constants MSG_WAITALL
@c -----------------------------------------
@subsection MSG_WAITALL
@cindex MSG_WAITALL
Socket constant for MSG_WAITALL

@c Socket constants SHUT_RD
@c -----------------------------------------
@subsection SHUT_RD
@cindex SHUT_RD
Socket constant for SHUT_RD

@c Socket constants SHUT_RDWR
@c -----------------------------------------
@subsection SHUT_RDWR
@cindex SHUT_RDWR
Socket constant for SHUT_RDWR

@c Socket constants SHUT_WR
@c -----------------------------------------
@subsection SHUT_WR
@cindex SHUT_WR
Socket constant for SHUT_WR

@c Socket constants SOCK_DGRAM
@c -----------------------------------------
@subsection SOCK_DGRAM
@cindex SOCK_DGRAM
Socket constant for SOCK_DGRAM

@c Socket constants SOCK_RAW
@c -----------------------------------------
@subsection SOCK_RAW
@cindex SOCK_RAW
Socket constant for SOCK_RAW

@c Socket constants SOCK_RDM
@c -----------------------------------------
@subsection SOCK_RDM
@cindex SOCK_RDM
Socket constant for SOCK_RDM

@c Socket constants SOCK_SEQPACKET
@c -----------------------------------------
@subsection SOCK_SEQPACKET
@cindex SOCK_SEQPACKET
Socket constant for SOCK_SEQPACKET

@c Socket constants SOCK_STREAM
@c -----------------------------------------
@subsection SOCK_STREAM
@cindex SOCK_STREAM
Socket constant for SOCK_STREAM

@c Socket constants SOL_SOCKET
@c -----------------------------------------
@subsection SOL_SOCKET
@cindex SOL_SOCKET
Socket constant for SOL_SOCKET

@c Socket constants SO_BROADCAST
@c -----------------------------------------
@subsection SO_BROADCAST
@cindex SO_BROADCAST
Socket constant for SO_BROADCAST

@c Socket constants SO_DONTROUTE
@c -----------------------------------------
@subsection SO_DONTROUTE
@cindex SO_DONTROUTE
Socket constant for SO_DONTROUTE

@c Socket constants SO_KEEPALIVE
@c -----------------------------------------
@subsection SO_KEEPALIVE
@cindex SO_KEEPALIVE
Socket constant for SO_KEEPALIVE

@c Socket constants SO_REUSEADDR
@c -----------------------------------------
@subsection SO_REUSEADDR
@cindex SO_REUSEADDR
Socket constant for SO_REUSEADDR