PageRenderTime 70ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/net.tex

https://bitbucket.org/mischief/oskit
LaTeX | 1024 lines | 753 code | 185 blank | 86 comment | 0 complexity | a4a343caf23ea7ef0e77df2543d4a2da MD5 | raw file
Possible License(s): GPL-2.0
  1. %
  2. % Copyright (c) 1997-1998, 2000, 2001 University of Utah and the Flux Group.
  3. % All rights reserved.
  4. %
  5. % The University of Utah grants you the right to copy and reproduce this
  6. % document or portions thereof for academic, research, evaluation, and
  7. % personal use only, provided that (1) the title page appears prominently,
  8. % and (2) these copyright and permission notices are retained in all copies.
  9. % To arrange for alternate terms, contact the University of Utah at
  10. % csl-dist@cs.utah.edu or +1-801-585-3271.
  11. %
  12. % -*- LaTeX -*-
  13. \label{net}
  14. \section{Introduction}
  15. The \oskit{} networking framework encompasses a collection of COM
  16. interfaces used by the client operating system to invoke the
  17. networking libraries.
  18. The individual networking libraries supply additional interfaces to
  19. the client operating system for initialization, and may supply
  20. additional interfaces for supporting extended features unique to
  21. particular networking protocol implementations.
  22. % COM is described at
  23. %% \htmladdnormallinkfoot{http://www.microsoft.com/oledev/olecom/title.htm}%
  24. % {http://www.microsoft.com/oledev/olecom/title.htm}
  25. % and in
  26. % chapter (\ref{com}).
  27. \emph{At this point, we have only one interface, the oskit_socket
  28. interface, defined. Additional interfaces for configuration,
  29. routing, etc., are future work.}
  30. \apiintf{oskit_socket}{Socket Interface}
  31. The \texttt{oskit_socket} COM interface defines an interface which
  32. capture the semantics of a socket as defined in the corresponding
  33. POSIX/CAE standards.
  34. The \texttt{oskit_socket} COM interface inherits from
  35. \texttt{oskit_posixio}. It can be queried for an \texttt{oskit_stream}
  36. interface. This query will always be successful, but the resulting
  37. \texttt{oskit_stream} instance might not support all methods.
  38. Generally, at least \texttt{read} and \texttt{write} will be supported.
  39. The \texttt{oskit_socket} COM interface provides in addition to
  40. the \texttt{oskit_posixio} COM interface the following methods:
  41. \begin{csymlist}
  42. \item[accept]
  43. accept a connection on a socket
  44. \item[bind]
  45. bind a name to a socket
  46. \item[connect]
  47. initiate a connection on a socket
  48. \item[shutdown]
  49. shut down part of a full-duplex connection
  50. \item[listen]
  51. listen for connections on a socket
  52. \item[getsockname]
  53. get socket name
  54. \item[getpeername]
  55. get name of connected peer
  56. \item[getsockopt]
  57. get options on sockets
  58. \item[setsockopt]
  59. set options on sockets
  60. \item[sendto]
  61. send a message from a socket
  62. \item[recvfrom]
  63. receive a message from a socket
  64. \item[sendmsg]
  65. send a message from a socket
  66. \item[recvmsg]
  67. receive a message from a socket
  68. \end{csymlist}
  69. Note that these methods are not minimal, but correspond very
  70. closely to the traditional BSD interfaces.
  71. \begin{quote}
  72. {\bf Note:} the following paragraphs have a certain likelihood
  73. to change. The main reason for this is the obviously undesirable
  74. connection between the way socket factories and the socket interface
  75. interact. On a more positive note, everything right now is so
  76. close to the BSD interfaces that the reader familiar with those
  77. shouldn't have any problems understanding these.
  78. \end{quote}
  79. \api{oskit_socket_factory_t}{socket factories}
  80. \begin{apisyn}
  81. \cinclude{oskit/net/socket.h}
  82. \funcproto oskit_error_t
  83. oskit_socket_factory_create(
  84. oskit_socket_factory_t *factory,
  85. oskit_u32_t domain,
  86. oskit_u32_t type,
  87. oskit_u32_t protocol,
  88. \outparam oskit_socket_t **newsocket);
  89. \end{apisyn}
  90. \begin{apidesc}
  91. Socket instances are created by \emph{socket factories}.
  92. A socket factory is an instance of the \texttt{oskit_socket_factory}
  93. COM interface. Implementations of this interface will be provided
  94. by the networking stack(s) included in the \oskit{}.
  95. This interface implements a single method corresponding to the
  96. \texttt{socket(2)} call in addition to the \texttt{oskit_iunknown}
  97. interface.
  98. Each instance of socket has a type and a protocol associated with it.
  99. This type and protocol is given to the socket by its factory, and
  100. cannot be changed during the lifetime of that socket instance.
  101. \end{apidesc}
  102. \begin{apiparm}
  103. \item[factory] The socket factory used to create this socket.
  104. \item[domain] The \emph{domain} parameter specifies a communications
  105. domain within which communication will take place;
  106. this selects the protocol family which should be used.
  107. Some common formats are
  108. \begin{tabular}{ll}
  109. \texttt{OSKIT_PF_LOCAL} &
  110. Host-internal protocols \\
  111. \texttt{OSKIT_PF_INET} &
  112. DARPA Internet protocols \\
  113. \texttt{OSKIT_PF_ISO} &
  114. ISO protocols \\
  115. \texttt{OSKIT_PF_CCITT} &
  116. ITU-T protocols, like X.25 \\
  117. \texttt{OSKIT_PF_NS} &
  118. Xerox Network Systems protocols \\
  119. \end{tabular}
  120. \texttt{OSKIT_PF_INET} is the only format for
  121. which the \oskit{} currently contains an implementation.
  122. \item[type] The socket will have the indicated \emph{type}, which
  123. specifies the semantics of communication. Currently defined types are
  124. \begin{tabular}{ll}
  125. \texttt{OSKIT_SOCK_STREAM} & stream socket \\
  126. \texttt{OSKIT_SOCK_DGRAM} & datagram socket \\
  127. \texttt{OSKIT_SOCK_RAW} & raw-protocol interface \\
  128. \texttt{OSKIT_SOCK_RDM} & reliably-delivered message \\
  129. \texttt{OSKIT_SOCK_SEQPACKET} & sequenced packet stream \\
  130. \end{tabular}
  131. An \texttt{OSKIT_SOCK_STREAM} type provides sequenced, reliable, two-way
  132. connection based byte streams. An out-of-band data transmission
  133. mechanism may be supported. An \texttt{OSKIT_SOCK_DGRAM} socket supports
  134. datagrams (connectionless, unreliable messages of a fixed (typically
  135. small) maximum length).
  136. An \texttt{OSKIT_SOCK_SEQPACKET} socket may provide a sequenced,
  137. reliable, two-way connection-based data transmission path for
  138. datagrams of fixed maximum length.
  139. \texttt{OSKIT_SOCK_RAW} sockets provide access to internal network
  140. protocols and interfaces.
  141. \item[protocol]
  142. The \emph{protocol} specifies a particular protocol to be used with the
  143. socket.
  144. Normally only a single protocol exists to support a particular socket
  145. type within a given protocol family. However, it is possible that
  146. many protocols may exist, in which case a particular protocol must
  147. be specified. The protocol number to use is particular to the
  148. communication domain in which communication is to take place.
  149. Protocols for the \texttt{OSKIT_PF_INET} protocol family are defined
  150. in \texttt{oskit/c/netinet/in.h}.
  151. \item[newsocket] The new \texttt{oskit_socket_t} instance that
  152. was created.
  153. \end{apiparm}
  154. \begin{apiret}
  155. Returns 0 on success, or an error code specified in
  156. {\tt <oskit/error.h>}, on error.
  157. \end{apiret}
  158. %
  159. % accept()
  160. %
  161. \api{accept}{accept a connection on a socket}
  162. \begin{apisyn}
  163. \cinclude{oskit/net/socket.h}
  164. \funcproto oskit_error_t
  165. oskit_socket_accept(oskit_socket_t *s,
  166. \outparam struct oskit_sockaddr *name,
  167. \inoutparam oskit_size_t *anamelen,
  168. \outparam struct oskit_socket **newopenso);
  169. \end{apisyn}
  170. \begin{apidesc}
  171. The \texttt{accept} method extracts the first connection request
  172. on the queue of pending connections, creates a new socket
  173. with the same properties of s and returns it.
  174. The socket must have been bound to an address with \texttt{bind}
  175. and it must be listening for connections after a \texttt{listen}.
  176. If no pending connections are present on the queue, \texttt{accept}
  177. blocks the caller until a connection is present.
  178. \end{apidesc}
  179. \begin{apiparm}
  180. \item[s]
  181. The socket from which connections are to accepted.
  182. \item[name]
  183. Filled with the address of the connecting entity as known
  184. to the communication layer.
  185. \item[anamelen]
  186. Initially, the amount of space pointed to by name,
  187. on return it will contain the amount actually used.
  188. \item[newopenso]
  189. Newly created socket.
  190. \end{apiparm}
  191. \begin{apiret}
  192. Returns 0 on success, or an error code specified in
  193. {\tt <oskit/error.h>}, on error.
  194. \end{apiret}
  195. %
  196. % bind()
  197. %
  198. \api{bind}{bind a name to a socket}
  199. \begin{apisyn}
  200. \cinclude{oskit/net/socket.h}
  201. \funcproto oskit_error_t
  202. oskit_socket_bind(oskit_socket_t *s,
  203. const struct oskit_sockaddr *name,
  204. oskit_size_t namelen);
  205. \end{apisyn}
  206. \begin{apidesc}
  207. \texttt{bind} assigns a name to an unnamed socket.
  208. When a socket is created, it exists in a name space (address family)
  209. but has no name assigned. \texttt{bind} requests that
  210. \emph{name} be assigned to the socket.
  211. \end{apidesc}
  212. \begin{apiparm}
  213. \item[s]
  214. The socket to which a name is to be bound.
  215. \item[name]
  216. The name to which the socket is to be bound.
  217. \item[namelen]
  218. The length of \emph{name} in bytes.
  219. \end{apiparm}
  220. \begin{apiret}
  221. Returns 0 on success, or an error code specified in
  222. {\tt <oskit/error.h>}, on error.
  223. \end{apiret}
  224. %
  225. % connect()
  226. %
  227. \api{connect}{initiate a connection on a socket}
  228. \begin{apisyn}
  229. \cinclude{oskit/net/socket.h}
  230. \funcproto oskit_error_t
  231. oskit_socket_connect(oskit_socket_t *s,
  232. const struct oskit_sockaddr *name,
  233. oskit_size_t namelen);
  234. \end{apisyn}
  235. \begin{apidesc}
  236. If \emph{s} is of type \texttt{OSKIT_SOCK_DGRAM}, this call
  237. specifies the peer with which the socket is to be associated; this
  238. address is that to which datagrams are to be sent, and the only address
  239. from which datagrams are to be received. If the socket is of type
  240. \texttt{OSKIT_SOCK_STREAM}, this call attempts to make a connection
  241. to another socket.
  242. The other socket is specified by \emph{name}, which is an address
  243. in the communications space of the socket.
  244. Each communications space interprets the \emph{name} parameter
  245. in its own way. Generally, stream sockets may successfully
  246. \texttt{connect} only once; datagram sockets may use
  247. \texttt{connect} multiple times to change their association.
  248. Datagram sockets may dissolve the association by connecting to
  249. an invalid address, such as a null address.
  250. \end{apidesc}
  251. \begin{apiparm}
  252. \item[s]
  253. The socket from which the connection is to be initiated.
  254. \item[name]
  255. The address of the entity to which the connection is
  256. to be established.
  257. \item[namelen]
  258. The length of \emph{name} in bytes.
  259. \end{apiparm}
  260. \begin{apiret}
  261. Returns 0 on success, or an error code specified in
  262. {\tt <oskit/error.h>}, on error.
  263. \end{apiret}
  264. %
  265. % shutdown()
  266. %
  267. \api{shutdown}{shut down part of a full-duplex connection}
  268. \begin{apisyn}
  269. \cinclude{oskit/net/socket.h}
  270. \funcproto oskit_error_t
  271. oskit_socket_shutdown(oskit_socket_t *s,
  272. oskit_u32_t how);
  273. \end{apisyn}
  274. \begin{apidesc}
  275. The \texttt{shutdown} call causes all or part of a full-duplex
  276. connection on the socket \emph{s} to be shut down.
  277. \end{apidesc}
  278. \begin{apiparm}
  279. \item[s]
  280. The socket which is to be shut down.
  281. \item[how]
  282. Specifies what is to be disallowed:
  283. \begin{itemize}
  284. \item[how = 0] receives
  285. \item[how = 1] sends
  286. \item[how = 2] sends and receives
  287. \end{itemize}
  288. \end{apiparm}
  289. \begin{apiret}
  290. Returns 0 on success, or an error code specified in
  291. {\tt <oskit/error.h>}, on error.
  292. \end{apiret}
  293. %
  294. % listen()
  295. %
  296. \api{listen}{listen for connections on a socket}
  297. \begin{apisyn}
  298. \cinclude{oskit/net/socket.h}
  299. \funcproto oskit_error_t
  300. oskit_socket_listen(oskit_socket_t *s,
  301. oskit_u32_t backlog);
  302. \end{apisyn}
  303. \begin{apidesc}
  304. A willingness to accept incoming connections and a queue limit
  305. for incoming connections are specified with \texttt{listen},
  306. and then the connections are accepted with \texttt{accept}.
  307. The \texttt{listen} call applies only to sockets of type
  308. \texttt{OSKIT_SOCK_STREAM} or \texttt{OSKIT_SOCK_SEQPACKET}.
  309. The \emph{backlog} parameter defines the maximum length the queue of
  310. pending connections may grow to.
  311. If a connection request arrives with the queue full the client may
  312. receive an error with an indication of connection refused, or, if
  313. the underlying protocol supports retransmission, the request may
  314. be ignored so that retries may succeed.
  315. \end{apidesc}
  316. \begin{apiparm}
  317. \item[s]
  318. The socket where connections will be accepted.
  319. \item[backlog]
  320. Maximum number of pending connections.
  321. \end{apiparm}
  322. \begin{apiret}
  323. Returns 0 on success, or an error code specified in
  324. {\tt <oskit/error.h>}, on error.
  325. \end{apiret}
  326. %
  327. % getsockname()
  328. %
  329. \api{getsockname}{get socket name}
  330. \begin{apisyn}
  331. \cinclude{oskit/net/socket.h}
  332. \funcproto oskit_error_t
  333. oskit_socket_getsockname(oskit_socket_t *s,
  334. \outparam struct oskit_sockaddr *asa,
  335. \inoutparam oskit_size_t *anamelen);
  336. \end{apisyn}
  337. \begin{apidesc}
  338. \texttt{getsockname} returns the current name for the specified socket.
  339. \end{apidesc}
  340. \begin{apiparm}
  341. \item[s]
  342. The socket whose name is to be determined.
  343. \item[name]
  344. Contains the name of the socket upon return.
  345. \item[anamelen]
  346. Initially, the amount of space pointed to by name,
  347. on return it will contain the amount actually used, i.e.,
  348. the actual size of the name.
  349. \end{apiparm}
  350. \begin{apiret}
  351. Returns 0 on success, or an error code specified in
  352. {\tt <oskit/error.h>}, on error.
  353. \end{apiret}
  354. %
  355. % getpeername()
  356. %
  357. \api{getpeername}{get name of connected peer}
  358. \begin{apisyn}
  359. \cinclude{oskit/net/socket.h}
  360. \funcproto oskit_error_t
  361. oskit_socket_getpeername(oskit_socket_t *s,
  362. \outparam struct oskit_sockaddr *asa,
  363. \inoutparam oskit_size_t *anamelen);
  364. \end{apisyn}
  365. \begin{apidesc}
  366. \texttt{getpeername} returns the name of the peer connected to socket
  367. \emph{s}.
  368. \end{apidesc}
  369. \begin{apiparm}
  370. \item[s]
  371. The socket connected to the peer whose name is to be returned.
  372. \item[name]
  373. Contains the peer's name upon return.
  374. \item[anamelen]
  375. Initially, the amount of space pointed to by name,
  376. on return it will contain the amount actually used.
  377. The name is truncated if the buffer provided is too small.
  378. \end{apiparm}
  379. \begin{apiret}
  380. Returns 0 on success, or an error code specified in
  381. {\tt <oskit/error.h>}, on error.
  382. \end{apiret}
  383. %
  384. % getsockoption()
  385. %
  386. \api{getsockopt}{get options on sockets}
  387. \begin{apisyn}
  388. \cinclude{oskit/net/socket.h}
  389. \funcproto oskit_error_t
  390. oskit_socket_getsockopt(oskit_socket_t *s,
  391. oskit_u32_t level,
  392. oskit_u32_t name,
  393. \outparam void *val,
  394. \inoutparam oskit_size_t *valsize);
  395. \end{apisyn}
  396. \begin{apidesc}
  397. Get the current options
  398. associated with a socket. Options may exist at multiple protocol
  399. levels.
  400. \end{apidesc}
  401. \begin{apiparm}
  402. \item[s]
  403. The socket whose options are to be queried or set.
  404. \item[level]
  405. The level at which the option resides.
  406. See \texttt{setsockopt} for details.
  407. \item[name]
  408. \emph{name} and any specified options are passed
  409. uninterpreted to the appropriate protocol module
  410. for interpretation.
  411. See \texttt{setsockopt} for details.
  412. \item[val, valsize]
  413. The parameters \emph{val} and \emph{valsize}
  414. are used to access option values.
  415. For \texttt{getsockopt}, \emph{valsize} initially contains the
  416. size of the buffer pointed to by \emph{val},
  417. and modified on return
  418. to indicate the actual size of the value returned.
  419. If no option value is to be supplied or returned,
  420. \emph{val} may be \texttt{NULL}.
  421. \end{apiparm}
  422. \begin{apiret}
  423. Returns 0 on success, or an error code specified in
  424. {\tt <oskit/error.h>}, on error.
  425. \end{apiret}
  426. \api{setsockopt}{set options on sockets}
  427. \begin{apisyn}
  428. \cinclude{oskit/net/socket.h}
  429. \funcproto oskit_error_t
  430. oskit_socket_setsockopt(oskit_socket_t *s,
  431. oskit_u32_t level,
  432. oskit_u32_t name,
  433. const void *val,
  434. oskit_size_t valsize);
  435. \end{apisyn}
  436. \begin{apidesc}
  437. \texttt{setsockopt} manipulates the options
  438. associated with a socket. Options may exist at multiple protocol
  439. levels.
  440. \end{apidesc}
  441. \begin{apiparm}
  442. \item[s]
  443. The socket whose options are to be queried or set.
  444. \item[level] When manipulating socket options the level at
  445. which the option resides and the name of the option must be
  446. specified. To manipulate options at the socket level, \emph{level}
  447. is specified as \texttt{OSKIT_SOL_SOCKET}. To manipulate options
  448. at any other level the protocol number of the appropriate protocol
  449. controlling the option is supplied. For example, to indicate that an
  450. option is to be interpreted by the TCP protocol, \emph{level}
  451. should be set to \texttt{IPPROTO_TCP}.
  452. \item[name]
  453. \emph{name} and any specified options are passed uninterpreted to the
  454. appropriate protocol module for interpretation.
  455. Definitions for socket level options are described below.
  456. Options at other protocol levels vary in format and name.
  457. Most socket-level options utilize an \texttt{int} parameter for
  458. \emph{val}. For \texttt{setsockopt}, the parameter should be
  459. non-zero to enable a boolean option, or zero if the option is
  460. to be disabled.
  461. \texttt{OSKIT_SO_LINGER} uses a \texttt{struct oskit_linger}
  462. parameter, which specifies the desired state of the option
  463. and the linger interval (see below).
  464. %% is that really so?
  465. \texttt{OSKIT_SO_SNDTIMEO} and \texttt{OSKIT_SO_RCVTIMEO}
  466. use a \texttt{struct timeval} parameter, defined in
  467. \texttt{<oskit/c/sys/time.h>}
  468. The following options are recognized at the socket level. Except as
  469. noted, each may be examined with \texttt{getsockopt} and set with
  470. \texttt{setsockopt}.
  471. \begin{tabular}{ll}
  472. \texttt{OSKIT_SO_DEBUG} &
  473. enables recording of debugging information \\
  474. \texttt{OSKIT_SO_REUSEADDR} &
  475. enables local address reuse \\
  476. \texttt{OSKIT_SO_REUSEPORT} &
  477. enables duplicate address and port bindings \\
  478. \texttt{OSKIT_SO_KEEPALIVE} &
  479. enables keep connections alive \\
  480. \texttt{OSKIT_SO_DONTROUTE} &
  481. enables routing bypass for outgoing messages \\
  482. \texttt{OSKIT_SO_LINGER} &
  483. linger on close if data present \\
  484. \texttt{OSKIT_SO_BROADCAST} &
  485. enables permission to transmit broadcast messages \\
  486. \texttt{OSKIT_SO_OOBINLINE} &
  487. enables reception of out-of-band data in band \\
  488. \texttt{OSKIT_SO_SNDBUF} &
  489. set buffer size for output \\
  490. \texttt{OSKIT_SO_RCVBUF} &
  491. set buffer size for input \\
  492. \texttt{OSKIT_SO_SNDLOWAT} &
  493. set minimum count for output \\
  494. \texttt{OSKIT_SO_RCVLOWAT} &
  495. set minimum count for input \\
  496. \texttt{OSKIT_SO_SNDTIMEO} &
  497. set timeout value for output \\
  498. \texttt{OSKIT_SO_RCVTIMEO} &
  499. set timeout value for input \\
  500. \texttt{OSKIT_SO_TYPE} &
  501. get the type of the socket (get only) \\
  502. \texttt{OSKIT_SO_ERROR} &
  503. get and clear error on the socket (get only) \\
  504. \end{tabular}
  505. \texttt{OSKIT_SO_DEBUG} enables debugging in the underlying
  506. protocol modules.
  507. \texttt{OSKIT_SO_REUSEADDR} indicates that the rules used in
  508. validating addresses supplied in \texttt{bind}
  509. should allow reuse of local addresses.
  510. \texttt{OSKIT_SO_REUSEPORT} allows completely duplicate bindings
  511. by multiple clients if they all set \texttt{OSKIT_SO_REUSEPORT}
  512. before binding the port. This option permits multiple instances
  513. of a program to each receive UDP/IP multicast or
  514. broadcast datagrams destined for the bound port.
  515. \texttt{OSKIT_SO_KEEPALIVE} enables the periodic transmission of
  516. messages on a connected socket. Should the
  517. connected party fail to respond to these messages, the connection is
  518. considered broken and clients using the socket are notified
  519. when attempting to send data.
  520. % XXX:
  521. % ...via a SIGPIPE signal. Yeah, right.
  522. \texttt{OSKIT_SO_DONTROUTE} indicates that outgoing
  523. messages should bypass the standard routing facilities.
  524. Instead, messages are directed to the appropriate network interface
  525. according to the network portion of the destination address.
  526. \texttt{OSKIT_SO_LINGER} controls the action taken when unsent
  527. messages are queued on a socket and the socket is released.
  528. If the socket promises reliable delivery of data and
  529. \texttt{OSKIT_SO_LINGER} is set, the system will block on the last
  530. \texttt{release} attempt until it is able to transmit the data
  531. or until it decides it is unable to deliver the information
  532. (a timeout period, termed the linger interval, is specified in the
  533. \texttt{setsockopt} call when \texttt{OSKIT_SO_LINGER} is requested.
  534. If \texttt{OSKIT_SO_LINGER} is disabled, the last \texttt{release}
  535. will succeed immediately. % is that really true???
  536. The option \texttt{OSKIT_SO_BROADCAST} requests permission to send
  537. broadcast datagrams on the socket. Broadcast was a privileged
  538. operation in earlier versions of the system. With protocols that
  539. support out-of-band data, the \texttt{OSKIT_SO_OOBINLINE} option
  540. requests that out-of-band data be placed in the normal data input
  541. queue as received; it will then be accessible with \texttt{recv}
  542. or \texttt{read} calls without the \texttt{OSKIT_MSG_OOB} flag.
  543. Some protocols always behave as if this option were set.
  544. \texttt{OSKIT_SO_SNDBUF} and \texttt{OSKIT_SO_RCVBUF} are options
  545. to adjust the normal buffer sizes allocated for output and input
  546. buffers, respectively. The buffer size may be increased for
  547. high-volume connections, or may be decreased to limit the possible
  548. backlog of incoming data. An absolute limit may be places on
  549. these values.
  550. \texttt{OSKIT_SO_SNDLOWAT} is an option to set the minimum count
  551. for output operations. Most output operations process all of the
  552. data supplied by the call, delivering data to the protocol for
  553. transmission and blocking as necessary for flow control.
  554. Nonblocking output operations will process as much data as permitted
  555. subject to flow control without blocking, but will process no data
  556. if flow control does not allow the smaller of the low water
  557. mark value or the entire request to be processed.
  558. % See, there you go: we NEED select().
  559. % A select(2) operation
  560. % testing the ability to write to a socket will return true only if
  561. % the low water mark amount could be processed.
  562. The default value for \texttt{OSKIT_SO_SNDLOWAT}
  563. is set to a convenient size for network efficiency, often 1024.
  564. \texttt{OSKIT_SO_RCVLOWAT} is an option to set the minimum count
  565. for input operations.
  566. In general, receive calls will block until any (non-zero) amount of data
  567. is received, then return with the smaller of the amount available or the
  568. amount requested. The default value for \texttt{OSKIT_SO_RCVLOWAT} is 1.
  569. If \texttt{OSKIT_SO_RCVLOWAT} is set to a larger value, blocking
  570. receive calls normally wait until they have received the smaller of
  571. the low water mark value or the requested amount. Receive calls may
  572. still return less than the low water mark if an error occurs, a signal
  573. is caught, or the type of data next in the receive queue is different
  574. than that returned.
  575. \texttt{OSKIT_SO_SNDTIMEO} is an option to set a timeout value for
  576. output operations.
  577. It accepts a \texttt{struct timeval} parameter with the number
  578. of seconds and microseconds used to limit waits for output operations
  579. to complete. If a send operation has blocked for this much time,
  580. it returns with a partial count or with the error
  581. \texttt{OSKIT_EWOULDBLOCK} if no data were sent.
  582. % FreeBSD says: In the current implementation,
  583. This timer is restarted each time additional data
  584. are delivered to the protocol, implying that the limit applies to
  585. output portions ranging in size from the low water mark to the
  586. high water mark for output.
  587. \texttt{OSKIT_SO_RCVTIMEO} is an option to set a timeout value for
  588. input operations. It accepts a struct timeval parameter with the
  589. number of seconds and microseconds used to limit waits for input
  590. operations to complete.
  591. % FreeBSD says: In the current implementation,
  592. This timer is restarted each time additional data are received by
  593. the protocol, and thus the limit is in effect
  594. an inactivity timer. If a receive operation has been blocked for this
  595. much time without receiving additional data, it returns with a short
  596. count or with the error \texttt{OSKIT_EWOULDBLOCK} if no data were
  597. received.
  598. Finally, \texttt{OSKIT_SO_TYPE} and \texttt{OSKIT_SO_ERROR} are options
  599. used only with \texttt{getsockopt}.
  600. \texttt{OSKIT_SO_TYPE} returns the type of the socket, such as
  601. \texttt{OSKIT_SOCK_STREAM}.
  602. \texttt{OSKIT_SO_ERROR} returns any
  603. pending error on the socket and clears the error status.
  604. It may be used to check for asynchronous errors on connected datagram
  605. sockets or for other asynchronous errors.
  606. \item[val, valsize]
  607. The parameters \emph{val} and \emph{valsize}
  608. are used to access option values for \texttt{setsockopt}.
  609. If no option value is to be supplied or returned, \emph{val} may be
  610. \texttt{NULL}.
  611. \end{apiparm}
  612. \begin{apiret}
  613. Returns 0 on success, or an error code specified in
  614. {\tt <oskit/error.h>}, on error.
  615. \end{apiret}
  616. %
  617. % recvfrom, recvmsg
  618. %
  619. \api{recvfrom, recvmsg}{receive a message from a socket}
  620. \begin{apisyn}
  621. \cinclude{oskit/net/socket.h}
  622. \funcproto oskit_error_t
  623. oskit_socket_recvfrom(oskit_socket_t *s,
  624. \outparam void *buf,
  625. oskit_size_t len, oskit_u32_t flags,
  626. \outparam struct oskit_sockaddr *from,
  627. \inoutparam oskit_size_t *fromlen,
  628. \outparam oskit_size_t *retval);
  629. \funcproto oskit_error_t
  630. oskit_socket_recvmsg(oskit_socket_t *s,
  631. \inoutparam struct oskit_msghdr *msg,
  632. oskit_u32_t flags,
  633. \outparam oskit_size_t *retval);
  634. \end{apisyn}
  635. \begin{apidesc}
  636. \texttt{recvfrom} and \texttt{recvmsg} are used to receive messages
  637. from a socket, and may be used to receive data on a socket whether
  638. or not it is connection-oriented.
  639. \textbf{Note: } The \texttt{recv} library function
  640. can be implemented using \texttt{recvfrom} with a nil \emph{from}
  641. parameter.
  642. % BSD says:
  643. % As it is redundant, it may not be supported in future releases.
  644. If no messages are available at the socket, the receive call waits
  645. for a message to arrive.
  646. % BSD says:
  647. % unless the socket is nonblocking (see fcntl(2)) in
  648. % which case the value -1 is returned and the external variable
  649. % errno set to EAGAIN.
  650. The receive calls normally return any data available,
  651. up to the requested amount, rather than waiting for receipt of the
  652. full amount equested; this behavior is affected by the socket-level
  653. options \texttt{OSKIT_SO_RCVLOWAT} and \texttt{OSKIT_SO_RCVTIMEO}
  654. described in \texttt{getsockopt}.
  655. % BSD says:
  656. % The select(2) call may be used to determine when more data arrive.
  657. \end{apidesc}
  658. \begin{apiparm}
  659. \item[s]
  660. The socket from the message is to be received.
  661. \item[buf] Buffer in which the message is to be copied.
  662. \item[len] Length of the buffer provided.
  663. \item[flags]
  664. The \emph{flags} argument is formed by or'ing one or more
  665. of the values:
  666. \begin{tabular}{ll}
  667. \texttt{OSKIT_MSG_OOB} & process out-of-band data
  668. \\
  669. \texttt{OSKIT_MSG_PEEK} & peek at incoming message
  670. \\
  671. \texttt{OSKIT_MSG_WAITALL}& wait for full request or error
  672. \\
  673. \end{tabular}
  674. The \texttt{OSKIT_MSG_OOB} flag requests receipt of
  675. out-of-band data that would not be received in the normal
  676. data stream.
  677. Some protocols place expedited data
  678. at the head of the normal data queue, and thus this flag cannot
  679. be used with such protocols.
  680. The \texttt{OSKIT_MSG_PEEK} flag causes the receive
  681. operation to return data from the beginning of the receive
  682. queue without removing that data from the queue.
  683. Thus, a subsequent receive call will return the same data.
  684. The \texttt{OSKIT_MSG_WAITALL} flag requests that the operation
  685. block until the full request is satisfied.
  686. However, the call may still return less data than requested if
  687. an error or disconnect occurs, or the next data to be received
  688. is of a different type than that returned.
  689. \item[from]
  690. If \emph{from} is non-nil, and the socket is not
  691. connection-oriented, the source address of the message is
  692. filled in.
  693. \item[fromlen]
  694. Initialized to the size of the buffer associated with
  695. \emph{from}, and modified on return to indicate the actual
  696. size of the address stored there.
  697. \item[msg] The \texttt{recvmsg} method uses a
  698. \texttt{struct oskit_msghdr} structure to minimize the number
  699. of directly supplied parameters.
  700. \cstruct{oskit_msghdr}{
  701. oskit_addr_t msg_name; /* optional address */
  702. oskit_u32_t msg_namelen; /* size of address */
  703. struct oskit_iovec *msg_iov; /* scatter/gather array */
  704. oskit_u32_t msg_iovlen; /* \# elements in msg_iov */
  705. oskit_addr_t msg_control; /* ancillary data, see below */
  706. oskit_u32_t msg_controllen; /* ancillary data buffer len */
  707. oskit_u32_t msg_flags; /* flags on received message */
  708. };
  709. Here \emph{msg_name} and \emph{msg_namelen}
  710. specify the destination address if the socket is unconnected;
  711. \emph{msg_name} may be given as a null pointer if no names are desired
  712. or required.
  713. \emph{msg_iov} and \emph{msg_iovlen} describe scatter gather
  714. locations.
  715. \emph{msg_control}, which has length \emph{msg_controllen},
  716. points to a buffer for other protocol control related
  717. messages or other miscellaneous ancillary data.
  718. % BSD says:
  719. % The messages are of the form:
  720. %
  721. % struct cmsghdr {
  722. % u_int cmsg_len; /* data byte count, including hdr */
  723. % int cmsg_level; /* originating protocol */
  724. % int cmsg_type; /* protocol-specific type */
  725. % /* followed by
  726. % u_char cmsg_data[]; */
  727. % };
  728. % As an example, one could use this to learn of changes in the data-stream
  729. % in XNS/SPP, or in ISO, to obtain user-connection-request data by request-
  730. % ing a recvmsg with no data buffer provided immediately after an accept()
  731. % call.
  732. %
  733. % Open file descriptors are now passed as ancillary data for AF_UNIX domain
  734. % sockets, with cmsg_level set to SOL_SOCKET and cmsg_type set to
  735. % SCM_RIGHTS.
  736. The \emph{msg_flags} field is set on return according to the message
  737. received. \texttt{OSKIT_MSG_EOR} indicates end-of-record; the data
  738. returned completed a record (generally used with sockets of type
  739. \texttt{OSKIT_SOCK_SEQPACKET}). \texttt{OSKIT_MSG_TRUNC} indicates
  740. that the trailing portion of a datagram was discarded because
  741. the datagram was larger than the buffer supplied.
  742. \texttt{OSKIT_CMSG_TRUNC} indicates that some
  743. control data were discarded due to lack of space in the
  744. buffer for ancillary data. \texttt{OSKIT_MSG_OOB} is returned to
  745. indicate that expedited or out-of-band data were received.
  746. \item[retval]
  747. Contains the number of characters received, i.e., the total
  748. length of the message upon return.
  749. If a message is too long to fit in the supplied buffer,
  750. excess bytes may be discarded depending on the type of socket
  751. the message is received from.
  752. \end{apiparm}
  753. \begin{apiret}
  754. Returns 0 on success, or an error code specified in
  755. {\tt <oskit/error.h>}, on error.
  756. \end{apiret}
  757. %
  758. % sendto, sendmsg
  759. %
  760. \api{sendto, sendmsg}{send a message from a socket}
  761. \begin{apisyn}
  762. \cinclude{oskit/net/socket.h}
  763. \funcproto oskit_error_t
  764. oskit_socket_sendto(oskit_socket_t *s,
  765. const void *buf,
  766. oskit_size_t len,
  767. oskit_u32_t flags,
  768. const struct oskit_sockaddr *to,
  769. oskit_size_t tolen,
  770. \outparam oskit_size_t *retval);
  771. \funcproto oskit_error_t
  772. oskit_socket_sendmsg(oskit_socket_t *s,
  773. const struct oskit_msghdr *msg,
  774. oskit_u32_t flags,
  775. \outparam oskit_size_t *retval);
  776. \end{apisyn}
  777. \begin{apidesc}
  778. \texttt{sendto}, \texttt{sendmsg} are used to transmit
  779. a message to another socket.
  780. The C library \texttt{send} may be implemented by passing a
  781. NULL \emph{to} parameter. It may be used only when the socket
  782. is in a connected state, while \texttt{sendto} and
  783. \texttt{sendmsg} may generally be used at any time.
  784. Send will block if no messages space is available at the socket
  785. to hold the message to be transmitted.
  786. % in BSD
  787. % unless the socket has been placed in non-blocking I/O mode.
  788. % The select(2) call may be used to determine when it is possible
  789. % to send more data.
  790. \end{apidesc}
  791. \begin{apiparm}
  792. \item[s]
  793. The socket from which the message is to be sent.
  794. \item[buf]
  795. \item[len] \emph{len} gives the length of the message.
  796. If the message is too long to pass atomically through the underlying
  797. protocol, the error \texttt{OSKIT_EMSGSIZE} is returned,
  798. and the message is not transmitted.
  799. \item[flags]
  800. The \emph{flags}
  801. parameter may include one or more of the following:
  802. \begin{tabular}{ll}
  803. \texttt{OSKIT_MSG_OOB} &
  804. process out-of-band data \\
  805. \texttt{OSKIT_MSG_PEEK} &
  806. peek at incoming message \\
  807. \texttt{OSKIT_MSG_DONTROUTE} &
  808. bypass routing, use direct interface \\
  809. \texttt{OSKIT_MSG_EOR} &
  810. data completes record \\
  811. \texttt{OSKIT_MSG_EOF} &
  812. data completes transaction \\
  813. \end{tabular}
  814. The flag \texttt{OSKIT_MSG_OOB} is used to send ``out-of-band''
  815. data on sockets that support this notion
  816. (e.g. \texttt{OSKIT_SOCK_STREAM}); the underlying protocol
  817. must also support ``out-of-band'' data.
  818. \texttt{OSKIT_MSG_EOR} is used to indicate a record
  819. mark for protocols which support the concept.
  820. \texttt{OSKIT_MSG_EOF} requests that the
  821. sender side of a socket be shut down, and that an appropriate
  822. indication be sent at the end of the specified data;
  823. this flag is only implemented for \texttt{OSKIT_SOCK_STREAM}
  824. sockets in the \texttt{OSKIT_PF_INET} protocol family.
  825. \item[to, tolen]
  826. The address of the target is given by \emph{to} with \emph{tolen}
  827. specifying its size.
  828. \item[msg]
  829. See \texttt{recvmsg} for a description of the
  830. \texttt{oskit_msghdr} structure.
  831. \item[retval]
  832. Upon return \emph{*retval} contains the number of characters sent.
  833. \end{apiparm}
  834. \begin{apiret}
  835. Returns 0 on success.
  836. No indication of failure to deliver is implicit in a send.
  837. Locally detected errors are indicated by an error code specified in
  838. {\tt <oskit/error.h>}.
  839. \end{apiret}