Files | |
file | sock.h |
Socket event system header file. | |
Data Structures | |
struct | _ev_sockaddr_s |
Socket address structure. More... | |
struct | _ev_sock_s |
Socket generator structure. More... | |
Defines | |
#define | SHUT_RD |
Shut down socket reads. | |
#define | SHUT_WR |
Shut down socket writes. | |
#define | SHUT_RDWR |
Shut down socket reads and writes. | |
#define | SOCK_ADDRBUFV4_LEN |
Socket address buffer size (IPv4). | |
#define | SOCK_ADDRSTRV4_LEN |
Socket address string length (IPv4). | |
#define | SOCK_ADDRBUFV6_LEN |
Socket address buffer size (IPv6). | |
#define | SOCK_ADDRSTRV6_LEN |
Socket address string length (IPv6). | |
#define | SOCK_LOCALADDR_LEN |
Local domain socket address length. | |
#define | sa_type(sa) |
Socket address type. | |
#define | sa_ipaddrbuf(sa) |
Socket address buffer. | |
#define | sa_ipaddrport(sa) |
Socket address port. | |
#define | sa_localaddr(sa) |
Local socket address. | |
#define | _sa_ipbuf8(sa, idx) |
Extract a single byte from the IP address buffer. | |
#define | _sa_ipbuf16(sa, idx) |
Extract a certain portion of the IP address buffer as a 16-bit integer. | |
#define | _sa_ipbuf32(sa, idx) |
Extract a certain portion of the IP address buffer as a 32-bit integer. | |
#define | _sa_ipmask(bits, sa, idx, mask) |
Extract a certain portion of the IP address buffer as the specified type and AND a mask. | |
#define | sa_is_ipv4(sa) |
Test if an ev_sockaddr_t is an IPv4 address. | |
#define | sa_is_ipv6(sa) |
Test if an ev_sockaddr_t is an IPv6 address. | |
#define | sa_is_local(sa) |
Test if an ev_sockaddr_t is a local address. | |
#define | sa_is_unspec(sa) |
Test if an ev_sockaddr_t contains the unspecified address. | |
#define | sa_is_loopback(sa) |
Test if an ev_sockaddr_t contains the loopback address. | |
#define | sa_is_v4mapped(sa) |
Test if an ev_sockaddr_t contains an IPv4-mapped IPv6 address. | |
#define | sa_is_v4compat(sa) |
Test if an ev_sockaddr_t contains an IPv4-compatible IPv6 address. | |
#define | sa_is_v4encap(sa) |
Test if an ev_sockaddr_t contains an encapsulated IPv4 address. | |
#define | _sa_ip4mask(sa, mask) |
Select the IPv4 component of an address and apply a mask. | |
#define | sa_is_classa(sa) |
Test if an ev_sockaddr_t contains a class A IPv4 address. | |
#define | sa_is_classb(sa) |
Test if an ev_sockaddr_t contains a class B IPv4 address. | |
#define | sa_is_classc(sa) |
Test if an ev_sockaddr_t contains a class C IPv4 address. | |
#define | sa_is_classd(sa) |
Test if an ev_sockaddr_t contains a class D IPv4 address. | |
#define | sa_is_experimental(sa) |
Test if an ev_sockaddr_t contains an experimental IPv4 address. | |
#define | sa_is_broadcast(sa) |
Test if an ev_sockaddr_t contains the IPv4 broadcast address. | |
#define | sa_is_multicast(sa) |
Test if an ev_sockaddr_t contains a multicast address. | |
#define | sa_is_linklocal(sa) |
Test if an ev_sockaddr_t contains a link-local IPv6 address. | |
#define | sa_is_sitelocal(sa) |
Test if an ev_sockaddr_t contains a site-local IPv6 address. | |
#define | _sa_ip4mc_local(sa) |
Test if an IPv4 multicast address is local. | |
#define | sa_mc_nodelocal(sa) |
Test if an ev_sockaddr_t contains a node-local multicast address. | |
#define | sa_mc_linklocal(sa) |
Test if an ev_sockaddr_t contains a link-local multicast address. | |
#define | sa_mc_sitelocal(sa) |
Test if an ev_sockaddr_t contains a site-local multicast address. | |
#define | sa_mc_orglocal(sa) |
Test if an ev_sockaddr_t contains a org-local multicast address. | |
#define | sa_mc_global(sa) |
Test if an ev_sockaddr_t contains a global multicast address. | |
#define | EV_SOCK_MAGIC |
Socket generator magic number. | |
#define | EV_SOCK_READ |
Socket readable event flag. | |
#define | EV_SOCK_WRITE |
Socket writable event flag. | |
#define | EV_SOCK_EVMASK |
Socket event mask. | |
#define | _so_decev(flags, shift) |
Decode event flag set. | |
#define | _so_encev(flags, shift) |
Encode event flag set. | |
#define | _so_set(sock, flags) |
Set event flags. | |
#define | _so_clr(sock, flags) |
Clear event flags. | |
#define | _EV_SOCK_UEVENTS |
User events shift. | |
#define | _EV_SOCK_EEVENTS |
Engine events shift. | |
#define | _EV_SOCK_BLOCKED |
Blocked flags shift. | |
#define | _EV_SOCK_CLOSED |
Closed flags shift. | |
#define | so_uevents(sock) |
User events. | |
#define | so_eevents(sock) |
Engine events. | |
#define | so_blocked(sock) |
Blocked flags. | |
#define | so_closed(sock) |
Closed flags. | |
#define | EV_SOCK_TYPE |
Socket type valid. | |
#define | EV_SOCK_STATE |
Socket state valid. | |
#define | EV_SOCK_LOCAL |
Socket local address valid. | |
#define | EV_SOCK_REMOTE |
Socket remote address valid. | |
#define | so_verify(sock) |
Socket generator verification macro. | |
#define | so_type(sock) |
Socket type. | |
#define | so_state(sock) |
Socket state. | |
#define | so_sockname(sock) |
Socket name. | |
#define | so_peername(sock) |
Socket peer name. | |
#define | so_flags(sock) |
Socket flags. | |
#define | so_fd(sock) |
Socket file descriptor. | |
#define | SOCKADDR_ATOP_NOPORT |
Omit port from presentation format. | |
Typedefs | |
typedef _ev_sockaddr_s | ev_sockaddr_t |
Socket address. | |
typedef _ev_sock_s | ev_sock_t |
Socket generator. | |
typedef _ev_sockattr_t * | ev_sockattr_t |
Socket attributes. | |
Enumerations | |
enum | ev_socktype_t { ST_NONE, ST_STREAM, ST_DGRAM, ST_SEQPACKET, ST_PIPE } |
Socket types. More... | |
enum | ev_sockstate_t { SS_NONE, SS_CONNECTING, SS_LISTENING, SS_CONNECTED, SS_UNCONNECTED, SS_CLOSED } |
Socket states. More... | |
enum | ev_satype_t { AT_NONE, AT_IPv6, AT_IPv4, AT_LOCAL } |
Socket address types. More... | |
Functions | |
ev_err_t | sa_type_set (ev_sockaddr_t *sa, ev_satype_t type) |
Set address type. | |
ev_err_t | sa_ipaddrbuf_set (ev_sockaddr_t *sa, const unsigned char *address) |
Fill address buffer. | |
ev_err_t | sa_ipaddrport_set (ev_sockaddr_t *sa, unsigned short port) |
Set address port. | |
ev_err_t | sa_localaddr_set (ev_sockaddr_t *sa, const char *address) |
Set local domain address. | |
ev_err_t | sockaddr_ptoa (ev_sockaddr_t *sa, const char *address, int alen) |
Fill an ev_sockaddr_t from a presentation format. | |
ev_err_t | sockaddr_atop (const ev_sockaddr_t *sa, char *buf, int size, ev_flags_t flags) |
Build presentation format of an ev_sockaddr_t. | |
ev_err_t | sockaddr_import (ev_sockaddr_t *sa, const struct sockaddr *addr) |
Import an ev_sockaddr_t from a struct sockaddr . | |
ev_err_t | sockaddr_export (const ev_sockaddr_t *sa, struct sockaddr *addr, int *len) |
Export an ev_sockaddr_t to a struct sockaddr . | |
ev_err_t | socket_open (ev_ctx_t *ctx, ev_socktype_t type, const ev_sockaddr_t *local, const ev_sockaddr_t *remote, ev_flags_t events, const ev_sockattr_t *attr, ev_call_t call, void *data, ev_sock_t **sock_p) |
Open a socket. | |
ev_err_t | socket_fdopen (ev_ctx_t *ctx, int fd, ev_socktype_t type, ev_sockstate_t state, const ev_sockaddr_t *local, const ev_sockaddr_t *remote, ev_flags_t events, const ev_sockattr_t *attr, ev_call_t call, void *data, ev_sock_t **sock_p) |
Create an ev_sock_t for an open socket. | |
ev_err_t | socket_pair (ev_ctx_t *ctx, ev_socktype_t type, ev_flags_t events1, const ev_sockattr_t *attr1, ev_call_t call1, void *data1, ev_flags_t events2, const ev_sockattr_t *attr2, ev_call_t call2, void *data2, ev_sock_t **sock1_p, ev_sock_t **sock2_p) |
Open a pair of sockets or a pipe. | |
ev_err_t | socket_connect (ev_ctx_t *ctx, ev_sock_t *sock, const ev_sockaddr_t *addr) |
Connect a socket. | |
ev_err_t | socket_close (ev_ctx_t *ctx, ev_sock_t *sock) |
Close a socket. | |
ev_err_t | socket_shutdown (ev_ctx_t *ctx, ev_sock_t *sock, int how) |
Shutdown one direction of a socket. | |
ev_err_t | socket_events (ev_ctx_t *ctx, ev_sock_t *sock, ev_flags_t events) |
Change socket event set. | |
ev_err_t | socket_destroy (ev_ctx_t *ctx, ev_sock_t *sock) |
Destroy a socket. |
|
For internal use only. This macro specifies the shift to apply to retrieve the flag set specifying which socket directions are blocked. |
|
For internal use only. This macro specifies the shift to apply to retrieve the flag set specifying which socket directions are closed. |
|
For internal use only. This macro specifies the shift to apply to retrieve the engine event set from the socket flags. |
|
For internal use only. This macro specifies the shift to apply to retrieve the user event set from the socket flags. |
|
For internal use only. This macro applies a mask to the IPv4 component of an address, whether an encapsulated IPv4 address or an actual AT_IPv4 address.
|
|
For internal use only. This macro tests if an IPv4 multicast address in a local multicast address only.
|
|
For internal use only.
This macro simply extracts a 16-bit integer (in host byte order) from the IP address of
|
|
For internal use only.
This macro simply extracts a 32-bit integer (in host byte order) from the IP address of
|
|
For internal use only.
This macro simply extracts a single 8-bit integer from the IP address of
|
|
For internal use only.
This macro extracts the specified number of
|
|
For internal use only.
This macro is used internally to clear the
|
|
For internal use only.
This macro is used to retrieve the appropriate event flags from the
|
|
For internal use only.
This macro is used to encode
|
|
For internal use only.
This macro is used internally to set the
|
|
This mask is used to select the event interest flags. |
|
This flag, when set on the socket, indicates that the local address of the socket is available. When this flag is passed to socket_fdopen(), the library will not attempt to determine the local address if |
|
This is the magic number used for the socket generator structure. Definition at line 750 of file sock.h. Referenced by event_init(), and main(). |
|
This flag is used to indicate interest in a readable indication on a socket. |
|
This flag, when set on the socket, indicates that the remote address of the socket is available. When this flag is passed to socket_fdopen(), the library will not attempt to determine the remote address if |
|
This flag, when set on the socket, indicates that the socket state is available. When this flag is passed to socket_fdopen(), the library will not attempt to determine the socket state if SS_NONE is passed for the |
|
This flag, when set on the socket, indicates that the socket type is available. When this flag is passed to socket_fdopen(), the library will not attempt to determine the socket type if ST_NONE is passed for the |
|
This flag is used to indicate interest in a writable indication on a socket. |
|
This macro retrieves a pointer to the buffer containing the socket address. It is only valid for AT_IPv4 and AT_IPv6 addresses.
Definition at line 217 of file sock.h. Referenced by main(), sockaddr_atop(), and sockaddr_export(). |
|
This macro retrieves the port number of the socket address. It is only valid for AT_IPv4 and AT_IPv6 addresses.
Definition at line 229 of file sock.h. Referenced by atop_v4(), atop_v6(), main(), and sockaddr_export(). |
|
This macro tests if an ev_sockaddr_t contains the IPv4 broadcast address.
|
|
This macro tests if an ev_sockaddr_t contains a class A IPv4 address. Note that IPv4 address classes are obsolete; this macro is provided for completeness.
|
|
This macro tests if an ev_sockaddr_t contains a class B IPv4 address. Note that IPv4 address classes are obsolete; this macro is provided for completeness.
|
|
This macro tests if an ev_sockaddr_t contains a class C IPv4 address. Note that IPv4 address classes are obsolete; this macro is provided for completeness.
|
|
This macro tests if an ev_sockaddr_t contains a class D IPv4 address. Note that IPv4 address classes are obsolete; this macro is provided for completeness.
|
|
This macro tests if an ev_sockaddr_t contains an experimental IPv4 address.
|
|
This macro tests if an ev_sockaddr_t is an IPv4 address, returning boolean true if so.
|
|
This macro tests if an ev_sockaddr_t is an IPv6 address, returning boolean true if so.
|
|
This macro tests if an ev_sockaddr_t contains a link-local IPv6 address.
|
|
This macro tests if an ev_sockaddr_t is a local address, returning boolean true if so.
|
|
This macro tests if an ev_sockaddr_t is the loopback address for the given address type.
|
|
This macro tests if an ev_sockaddr_t contains a multicast address, for either IPv4 or IPv6.
|
|
This macro tests if an ev_sockaddr_t contains a site-local IPv6 address.
|
|
This macro tests if an ev_sockaddr_t is the unspecified address for the given address type.
|
|
This macro tests if an ev_sockaddr_t contains an IPv4-compatible IPv6 address. It will evaluate to false if the address is not an IPv6 address to begin with.
|
|
This macro tests if an ev_sockaddr_t contains an encapsulated IPv4 address. It will evaluate to false if the address is not an IPv6 address to begin with.
|
|
This macro tests if an ev_sockaddr_t contains an IPv4-mapped IPv6 address. It will evaluate to false if the address is not an IPv6 address to begin with.
|
|
This macro retrieves the local domain address. It is only valid for AT_LOCAL addresses.
Definition at line 241 of file sock.h. Referenced by main(), sockaddr_atop(), and sockaddr_export(). |
|
This macro tests if an ev_sockaddr_t contains a global multicast address.
|
|
This macro tests if an ev_sockaddr_t contains a link-local multicast address.
|
|
This macro tests if an ev_sockaddr_t contains a node-local multicast address.
|
|
This macro tests if an ev_sockaddr_t contains a org-local multicast address.
|
|
This macro tests if an ev_sockaddr_t contains a site-local multicast address.
|
|
This macro retrieves the type for the linked socket address.
Definition at line 205 of file sock.h. Referenced by main(). |
|
This value, when passed to socket_shutdown() as the |
|
This value, when passed to socket_shutdown() as the |
|
This value, when passed to socket_shutdown() as the |
|
This macro retrieves the blocked flag set from the socket.
|
|
This macro retrieves the closed flag set from the socket.
|
|
This macro retrieves the engine event set from the socket.
|
|
This macro retrieves the file descriptor for the socket. Note that this will be -1 if the socket state is SS_CLOSED.
|
|
This macro retrieves the current flags for the socket.
|
|
This macro retrieves the address of the peer side of a socket connection. Note that this address will have type AT_NONE if this is a listening socket or an unconnected datagram socket.
|
|
This macro retrieves the address of this side of a socket connection.
|
|
This macro retrieves the current state of the socket, which will be one of the ev_sockstate_t constants.
|
|
This macro retrieves the type of the socket, which will be one of the ev_socktype_t constants.
|
|
This macro retrieves the user event set from the socket.
|
|
This macro verifies that a given pointer actually does point to an ev_sock_t.
|
|
This macro gives the size, in bytes, of the buffer necessary to contain an IPv4 address. Definition at line 85 of file sock.h. Referenced by atop_v6(), main(), sa_ipaddrbuf_set(), sockaddr_export(), and sockaddr_import(). |
|
This macro gives the size, in bytes, of the buffer necessary to contain an IPv6 address. Definition at line 99 of file sock.h. Referenced by atop_v6(), main(), sa_ipaddrbuf_set(), sockaddr_export(), sockaddr_import(), and sockaddr_ptoa(). |
|
This macro gives the maximum length, in characters, of the buffer necessary to contain the text representation of an IPv4 address. |
|
This macro gives the maximum length, in characters, of the buffer necessary to contain the text representation of an IPv6 address. Definition at line 106 of file sock.h. Referenced by sockaddr_atop(). |
|
This macro contains the maximum length of a local domain socket address, in characters. Definition at line 113 of file sock.h. Referenced by main(), sa_localaddr_set(), sockaddr_export(), sockaddr_import(), and sockaddr_ptoa(). |
|
This flag is used to signal to the sockaddr_atop() function that the caller does not want the port. |
|
Sockets are described using this structure. |
|
This structure is used to abstract the addresses of the socket endpoints. |
|
Socket attributes are used to modify various characteristics of the sockets being created. |
|
This enumeration is used to label a socket address with its corresponding type. |
|
Sockets may be in one of several states. This enumeration describes those states. |
|
Sockets may be stream sockets, datagram sockets, or pipe "sockets." (Pipes are fundamentally different from sockets, and so we must differentiate between them in order for the library to be able to operate on them. We must be able to make use of pipes because the default signal engine must use a pipe to communicate from the signal handler.) |
|
This function is used to set the address buffer of the given ev_sockaddr_t to
Definition at line 34 of file sa_ipaddrbuf_set.c. References AT_IPv4, AT_IPv6, ev_init, ev_return, _ev_sockaddr_s::sa_addr, _ev_sockaddr_s::sa_type, SOCK_ADDRBUFV4_LEN, and SOCK_ADDRBUFV6_LEN. Referenced by main(). |
|
This function is used to set the address port of the given ev_sockaddr_t to
Definition at line 32 of file sa_ipaddrport_set.c. References AT_IPv4, AT_IPv6, ev_init, ev_return, _ev_sockaddr_s::sa_addr, and _ev_sockaddr_s::sa_type. Referenced by main(). |
|
This function is used to set the local domain address of the given ev_sockaddr_t to
Definition at line 34 of file sa_localaddr_set.c. References AT_LOCAL, ev_init, ev_return, _ev_sockaddr_s::sa_addr, _ev_sockaddr_s::sa_type, and SOCK_LOCALADDR_LEN. Referenced by main(). |
|
This function sets the type of the given ev_sockaddr_t to the specified
Definition at line 32 of file sa_type_set.c. References AT_IPv4, AT_IPv6, AT_LOCAL, AT_NONE, ev_init, ev_return, and _ev_sockaddr_s::sa_type. Referenced by main(). |
|
This function fills the buffer given with the presentation format of the address given by
Definition at line 162 of file sockaddr_atop.c. References AT_IPv4, AT_IPv6, AT_LOCAL, AT_NONE, atop_v4(), atop_v6(), ev_init, ev_return, sa_ipaddrbuf, sa_localaddr, _ev_sockaddr_s::sa_type, and SOCK_ADDRSTRV6_LEN. Referenced by main(). Here is the call graph for this function: ![]() |
|
This function fills in a
Definition at line 38 of file sockaddr_export.c. References AT_IPv4, AT_IPv6, AT_LOCAL, ev_init, ev_return, sa_ipaddrbuf, sa_ipaddrport, sa_localaddr, _ev_sockaddr_s::sa_type, SOCK_ADDRBUFV4_LEN, SOCK_ADDRBUFV6_LEN, and SOCK_LOCALADDR_LEN. Referenced by main(). |
|
This function fills in the
Definition at line 38 of file sockaddr_import.c. References AT_IPv4, AT_IPv6, AT_LOCAL, ev_assert, ev_init, ev_return, _ev_sockaddr_s::sa_addr, _ev_sockaddr_s::sa_type, SOCK_ADDRBUFV4_LEN, SOCK_ADDRBUFV6_LEN, and SOCK_LOCALADDR_LEN. Referenced by main(). |
|
This function parses the string representation of the
Definition at line 313 of file sockaddr_ptoa.c. References accum, accumulate, partaddr::addr, AT_IPv4, AT_IPv6, AT_LOCAL, AT_NONE, bcd, bcd_isquad, partaddr::cnt, COLON, ctype, dec_accum, DIGIT, ev_init, ev_return, hex_accum, partaddr_init, PERIOD, _ev_sockaddr_s::sa_addr, _ev_sockaddr_s::sa_type, partaddr::segs, SOCK_ADDRBUFV6_LEN, SOCK_LOCALADDR_LEN, test_v6, and XDIGIT. Referenced by main(). |
|
This function simply closes the socket, removing it from the engine and clearing the events set. Note that the socket generator will NOT be destroyed; the application must do that explicitly with a call to socket_destroy().
|
|
This function calls the connect() function to connect a socket (typically a datagram socket) to a given remote address. If the remote address
|
|
This function destroys a socket. If the socket is open, unless it was created with the sockattr_noclose() attribute, it will also be closed.
|
|
This function changes the set of events the user is interested in on
|
|
The library only directly handles sockets used for network communication. Many systems provide other types of sockets for communication with the system itself or for other purposes (including forms of network communications that the library does not support). This function allows such sockets, as well as sockets opened by other libraries, to be registered with the library, so that events may be generated when the sockets become readable or writable.
|
|
This function will create a socket of the given
|
|
This function will create a pair of sockets, connected to each other, in the AT_LOCAL domain. (If
|
|
This function shuts down one direction of the socket, clearing the appropriate event. The
|