## ## SA - OSSP Socket Abstraction Library ## Copyright (c) 2001 Ralf S. Engelschall ## Copyright (c) 2001 The OSSP Project ## Copyright (c) 2001 Cable & Wireless Deutschland ## ## This file is part of OSSP SA, a socket abstraction library which ## can be found at http://www.ossp.org/pkg/sa/. ## ## Permission to use, copy, modify, and distribute this software for ## any purpose with or without fee is hereby granted, provided that ## the above copyright notice and this permission notice appear in all ## copies. ## ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ## SUCH DAMAGE. ## ## sa.pod: socket abstraction library manual page ## =pod =head1 NAME B - Socket Abstraction Library =head1 SYNOPSIS =over 4 =item B: sa_rc_t, sa_addr_t, sa_t. =item B
: sa_addr_create, sa_addr_destroy. =item B
: sa_addr_u2a, sa_addr_s2a, sa_addr_a2u, sa_addr_a2s, sa_addr_match. =item B: sa_create, sa_destroy. =item B: sa_type, sa_timeout, sa_buffer, sa_syscall. =item B: sa_bind, sa_connect, sa_listen, sa_accept, sa_getremote, sa_getlocal, sa_getfd, sa_shutdown. =item B: sa_read, sa_readln, sa_write, sa_writef, sa_flush. =item B: sa_recv, sa_send. =item B: sa_error. =back =head1 DESCRIPTION B is an abstraction library for the Unix I networking interface featuring stream and datagram oriented communication over I and I (TCP and UDP) sockets. It provides the following key features: =over 4 =item B Although there are various Open Source libraries available which provide a similar abstraction approach, they all either lack important features or unfortunately depend on other companion libraries. B fills this gap by providing all important features (see following points) as a stand-alone and fully self-contained library. This way B can be trivially embedded as a sub-library into other libraries. It especially provides additional support for namespace-safe embedding of its API in order to avoid symbol conflicts (see C in F). =item B
Most of the uglyness in the Unix I API is the necessarity to have to deal with the various address structures (C) which exist because of both the different communication types and addressing schemes. B fully hides this by providing an abstract and opaque address type (C) together with utility functions which allow one to convert from the traditional C or URI specification to the C and vice versa without having to deal with special cases related to the underlying particular C. B support I and both IPv4 and IPv6 I addressing. =item B Some other subtle details in the Unix I API make the life hard in practice: C and C. These two types originally were (and on some platforms still are) plain integers or unsigned integers while POSIX later introduced own types for them (and even revised these types after some time again). This is nasty, because for 100% type-correct API usage (especially important on 64-bit machines where pointers to different integer types make trouble), every application has to check whether the newer types exists and if not provide own definitions which map to the still actually used integer type on the underlying platform. B hides most of this in its API and for C provides a backward-compatibility definition. Instead of C it uses C because B does not use traditional Unix return code semantics. =item B Each I/O function in B is aware of timeouts (set by sa_timeout()), i.e., all I/O operations return C if the timeout expired before the I/O operation was able to succeed. This allows one to easily program less-blocking network services. B internally implements these timeouts either through the C feature on more modern I implementations or through traditional select(2). This way high performance is achieved on modern platforms while the full functionality still is available on older platforms. =item B If B is used for stream communication, internally all I/O operations can be performed through input and/or output buffers (set by sa_buffer()) for achieving higher I/O performance by doing I/O operations on larger aggregated messages and with less system calls. Additionally if B is used for stream communication, for convinience reasons line-oriented reading (sa_readln()) and formatted writing (sa_writef()) is provided, modelled after STDIO's fgets(3) and fprintf(3). Both features fully leverage from the I/O buffering. =back =head1 DATA TYPES B uses three data types in its API: =over 4 =item B (Return Code Type) This is an exported enumerated integer type with the following possible values: C (everything ok, operation succeeded); C (invalid argument(s) passed to function); C (function used in wrong context); C (out of memory); C (end of file/socket in communication); C (operating system error; errno contains details); C (any other internal error). =item B (Socket Address Abstraction Type) This is an opaque type representing a socket address. Only pointers to this abstract type are used in the API. =item B (Socket Abstraction Type) This is an opaque type representing a socket. Only pointers to this abstract type are used in the API. =back =head1 FUNCTIONS =head2 Address Object Operations =over 4 =item sa_rc_t B(sa_addr_t **I); Create a socket address abstraction object. =item sa_rc_t B(sa_addr_t *I); Destroy a socket address abstraction object. =back =head2 Address Operations =over 4 =item sa_rc_t B(sa_addr_t *I, const char *I, ...); Import an address by converting from an URI specification to the corresponding address abstraction. The supported URI syntax is: "CI" for I addresses and "CIC<:>I" for I addresses. I can be an absolute or relative file path to an existing or not-existing file. I can be an IPv4 address in dotted decimal notation (C<127.0.0.1>), an IPv6 address in colon-seperated (optionally shortended) hexadecimal notation (C<::1>) or a to-be-resolved hostname (C). I has to be a decimal port in the range C<1>...C<65535>. =item sa_rc_t B(sa_addr_t *I, const struct sockaddr *I, socklen_t I); Import an address by converting from a tranditional C object to the corresponding address abstraction. =item sa_rc_t B(sa_addr_t *I, char **I); Export an address by converting from the address abstraction to the corresponding URI specification. =item sa_rc_t B(sa_addr_t *I, struct sockaddr **I, socklen_t *I); Export an address by converting from the address abstraction to the corresponding traditional C object. =item sa_rc_t B(sa_addr_t *I, sa_addr_t *I, size_t I); Match two address abstractions =back =head2 Socket Object Operations =over 4 =item sa_rc_t B(sa_t **I); =item sa_rc_t B(sa_t *I); =back =head2 Socket Parameter Operations =over 4 =item sa_rc_t B(sa_t *I, sa_type_t I); =item sa_rc_t B(sa_t *I, sa_timeout_t I, long I, long I); =item sa_rc_t B(sa_t *I, sa_buffer_t I, size_t I); =item sa_rc_t B(sa_t *I, sa_syscall_t I, void (*I)(), void *I); =back =head2 Socket Connection Operations =over 4 =item sa_rc_t B(sa_t *I, sa_addr_t *I); =item sa_rc_t B(sa_t *I, sa_addr_t *I); =item sa_rc_t B(sa_t *I, int I); =item sa_rc_t B(sa_t *I, sa_addr_t **I, sa_t **I); =item sa_rc_t B(sa_t *I, sa_addr_t **I); =item sa_rc_t B(sa_t *I, sa_addr_t **I); =item sa_rc_t B(sa_t *I, int *I); =item sa_rc_t B(sa_t *I, char *I); =back =head2 Socket Input/Output Operations (Stream Communication) =over 4 =item sa_rc_t B(sa_t *I, char *I, size_t I, size_t *I); =item sa_rc_t B(sa_t *I, char *I, size_t I, size_t *I); =item sa_rc_t B(sa_t *I, const char *I, size_t I, size_t *I); =item sa_rc_t B(sa_t *I, const char *I, ...); =item sa_rc_t B(sa_t *I); =back =head2 Socket Input/Output Operations (Stream Communication) =over 4 =item sa_rc_t B(sa_t *I, char *I, size_t I, size_t *I, sa_addr_t **I); =item sa_rc_t B(sa_t *I, const char *I, size_t I, size_t *I, sa_addr_t *I); =back =head2 Socket Error Handling =over 4 =item char *B(sa_rc_t I); =back =head1 HISTORY B was invented in August 2001 by Ralf S. Engelschall for use inside the OSSP project. Its creation was prompted by the requirement to implement an SMTP logging channel for B (logging library). Its initial code was derived from a predecessor sub-library originally written for socket address abstraction inside B. =head1 AUTHORS Ralf S. Engelschall rse@engelschall.com www.engelschall.com =cut