Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

Socket event handling.


Detailed Description

The event library provides support for socket manipulation. Each socket must be registered with the library.


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.


Define Documentation

#define _EV_SOCK_BLOCKED
 

For internal use only.

This macro specifies the shift to apply to retrieve the flag set specifying which socket directions are blocked.

Definition at line 849 of file sock.h.

#define _EV_SOCK_CLOSED
 

For internal use only.

This macro specifies the shift to apply to retrieve the flag set specifying which socket directions are closed.

Definition at line 857 of file sock.h.

#define _EV_SOCK_EEVENTS
 

For internal use only.

This macro specifies the shift to apply to retrieve the engine event set from the socket flags.

Definition at line 841 of file sock.h.

#define _EV_SOCK_UEVENTS
 

For internal use only.

This macro specifies the shift to apply to retrieve the user event set from the socket flags.

Definition at line 833 of file sock.h.

#define _sa_ip4mask sa,
mask   ) 
 

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.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t. This parameter must be an AT_IPv4 address or an IPv4 address encapsulated in an AT_IPv6 address.
[in] mask The mask to apply.
Returns:
The masked IPv4 address component.

Definition at line 475 of file sock.h.

#define _sa_ip4mc_local sa   ) 
 

For internal use only.

This macro tests if an IPv4 multicast address in a local multicast address only.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a local IPv4 multicast address, false otherwise.

Definition at line 638 of file sock.h.

#define _sa_ipbuf16 sa,
idx   ) 
 

For internal use only.

This macro simply extracts a 16-bit integer (in host byte order) from the IP address of sa, beginning with the specified idx (in bytes).

Warning:
This macro evaluates its arguments multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
[in] idx The starting index, in bytes from which to extract the integer.
Returns:
The 16 bits of the address beginning at idx.

Definition at line 272 of file sock.h.

#define _sa_ipbuf32 sa,
idx   ) 
 

For internal use only.

This macro simply extracts a 32-bit integer (in host byte order) from the IP address of sa, beginning with the specified idx (in bytes).

Warning:
This macro evaluates its arguments multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
[in] idx The starting index, in bytes from which to extract the integer.
Returns:
The 32 bits of the address beginning at idx.

Definition at line 291 of file sock.h.

#define _sa_ipbuf8 sa,
idx   ) 
 

For internal use only.

This macro simply extracts a single 8-bit integer from the IP address of sa at the specified idx (in bytes).

Parameters:
[in] sa A pointer to an ev_sockaddr_t.
[in] idx The index of the byte to extract.
Returns:
The 8 bits of the address beginning at idx.

Definition at line 254 of file sock.h.

#define _sa_ipmask bits,
sa,
idx,
mask   ) 
 

For internal use only.

This macro extracts the specified number of bits from the IP address specified by sa, beginning at idx, and applies a mask.

Warning:
This macro may evaluate the sa and idx parameters multiple times.
Parameters:
[in] bits The number of bits to extract. May be 8 or 32.
[in] sa A pointer to an ev_sockaddr_t.
[in] idx The starting index, in bytes, from which to extract the bits.
[in] mask The mask to apply.
Returns:
The indicated number of bits, with mask applied, starting at byte offset idx.

Definition at line 317 of file sock.h.

#define _so_clr sock,
flags   ) 
 

For internal use only.

This macro is used internally to clear the flags for the socket.

Parameters:
[in,out] sock A pointer to an ev_sock_t.
[in] flags The flags to clear.

Definition at line 825 of file sock.h.

#define _so_decev flags,
shift   ) 
 

For internal use only.

This macro is used to retrieve the appropriate event flags from the flags parameter. The shift parameter should be one of _EV_SOCK_UEVENTS, _EV_SOCK_EEVENTS, _EV_SOCK_BLOCKED, or _EV_SOCK_CLOSED, to indicate which flag set is desired.

Parameters:
[in] flags The flags to be decoded.
[in] shift A bit-wise shift to apply to recover the desired flags.
Returns:
The bit-wise OR of EV_SOCK_READ and EV_SOCK_WRITE from the desired flag set.

Definition at line 787 of file sock.h.

#define _so_encev flags,
shift   ) 
 

For internal use only.

This macro is used to encode flags as an event flag set, selected by the shift parameter. The shift parameter should be one of _EV_SOCK_UEVENTS, _EV_SOCK_EEVENTS, _EV_SOCK_BLOCKED, or _EV_SOCK_CLOSED, to indicate which flag set is desired.

Parameters:
[in] flags The flags to be encoded. Should be a bit-wise OR of EV_SOCK_READ and EV_SOCK_WRITE.
[in] shift A bit-wise shift to apply to encode the desired flags.
Returns:
The encoded flag set.

Definition at line 805 of file sock.h.

#define _so_set sock,
flags   ) 
 

For internal use only.

This macro is used internally to set the flags for the socket.

Parameters:
[in,out] sock A pointer to an ev_sock_t.
[in] flags The flags to set.

Definition at line 815 of file sock.h.

#define EV_SOCK_EVMASK
 

This mask is used to select the event interest flags.

Definition at line 770 of file sock.h.

#define EV_SOCK_LOCAL
 

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 NULL or an AT_NONE address is passed for the local parameter.

Definition at line 933 of file sock.h.

#define EV_SOCK_MAGIC
 

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().

#define EV_SOCK_READ
 

This flag is used to indicate interest in a readable indication on a socket.

Definition at line 757 of file sock.h.

#define EV_SOCK_REMOTE
 

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 NULL or an AT_NONE address is passed for the local parameter.

Definition at line 943 of file sock.h.

#define EV_SOCK_STATE
 

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 state parameter.

Definition at line 923 of file sock.h.

#define EV_SOCK_TYPE
 

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 type parameter.

Definition at line 914 of file sock.h.

#define EV_SOCK_WRITE
 

This flag is used to indicate interest in a writable indication on a socket.

Definition at line 764 of file sock.h.

#define sa_ipaddrbuf sa   ) 
 

This macro retrieves a pointer to the buffer containing the socket address. It is only valid for AT_IPv4 and AT_IPv6 addresses.

Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
A pointer to an unsigned char containing the IPv4 or IPv6 address.

Definition at line 217 of file sock.h.

Referenced by main(), sockaddr_atop(), and sockaddr_export().

#define sa_ipaddrport sa   ) 
 

This macro retrieves the port number of the socket address. It is only valid for AT_IPv4 and AT_IPv6 addresses.

Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
An unsigned short giving the port number, in host byte order.

Definition at line 229 of file sock.h.

Referenced by atop_v4(), atop_v6(), main(), and sockaddr_export().

#define sa_is_broadcast sa   ) 
 

This macro tests if an ev_sockaddr_t contains the IPv4 broadcast address.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains the IPv4 broadcast address, false otherwise.

Definition at line 571 of file sock.h.

#define sa_is_classa sa   ) 
 

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.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a class A IPv4 address, false otherwise.

Definition at line 491 of file sock.h.

#define sa_is_classb sa   ) 
 

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.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a class B IPv4 address, false otherwise.

Definition at line 507 of file sock.h.

#define sa_is_classc sa   ) 
 

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.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a class C IPv4 address, false otherwise.

Definition at line 523 of file sock.h.

#define sa_is_classd sa   ) 
 

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.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a class D IPv4 address, false otherwise.

Definition at line 539 of file sock.h.

#define sa_is_experimental sa   ) 
 

This macro tests if an ev_sockaddr_t contains an experimental IPv4 address.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains an experimental IPv4 address, false otherwise.

Definition at line 555 of file sock.h.

#define sa_is_ipv4 sa   ) 
 

This macro tests if an ev_sockaddr_t is an IPv4 address, returning boolean true if so.

Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa is an IPv4 address, false otherwise.

Definition at line 330 of file sock.h.

#define sa_is_ipv6 sa   ) 
 

This macro tests if an ev_sockaddr_t is an IPv6 address, returning boolean true if so.

Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa is an IPv6 address, false otherwise.

Definition at line 342 of file sock.h.

#define sa_is_linklocal sa   ) 
 

This macro tests if an ev_sockaddr_t contains a link-local IPv6 address.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a link-local IPv6 address, false otherwise.

Definition at line 604 of file sock.h.

#define sa_is_local sa   ) 
 

This macro tests if an ev_sockaddr_t is a local address, returning boolean true if so.

Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa is a local address, false otherwise.

Definition at line 354 of file sock.h.

#define sa_is_loopback sa   ) 
 

This macro tests if an ev_sockaddr_t is the loopback address for the given address type.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains the loopback address, false otherwise.

Definition at line 391 of file sock.h.

#define sa_is_multicast sa   ) 
 

This macro tests if an ev_sockaddr_t contains a multicast address, for either IPv4 or IPv6.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a multicast address, false otherwise.

Definition at line 587 of file sock.h.

#define sa_is_sitelocal sa   ) 
 

This macro tests if an ev_sockaddr_t contains a site-local IPv6 address.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a site-local IPv6 address, false otherwise.

Definition at line 621 of file sock.h.

#define sa_is_unspec sa   ) 
 

This macro tests if an ev_sockaddr_t is the unspecified address for the given address type.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains the unspecified address, false otherwise.

Definition at line 369 of file sock.h.

#define sa_is_v4compat sa   ) 
 

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.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains an IPv4-compatible IPv6 address, false otherwise.

Definition at line 432 of file sock.h.

#define sa_is_v4encap sa   ) 
 

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.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains an encapsulated IPv4 address, false otherwise.

Definition at line 452 of file sock.h.

#define sa_is_v4mapped sa   ) 
 

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.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains an IPv4-mapped IPv6 address, false otherwise.

Definition at line 413 of file sock.h.

#define sa_localaddr sa   ) 
 

This macro retrieves the local domain address. It is only valid for AT_LOCAL addresses.

Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
A pointer to a char containing the local domain address.

Definition at line 241 of file sock.h.

Referenced by main(), sockaddr_atop(), and sockaddr_export().

#define sa_mc_global sa   ) 
 

This macro tests if an ev_sockaddr_t contains a global multicast address.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a global multicast address, false otherwise.

Definition at line 724 of file sock.h.

#define sa_mc_linklocal sa   ) 
 

This macro tests if an ev_sockaddr_t contains a link-local multicast address.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a link-local multicast address, false otherwise.

Definition at line 672 of file sock.h.

#define sa_mc_nodelocal sa   ) 
 

This macro tests if an ev_sockaddr_t contains a node-local multicast address.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a node-local multicast address, false otherwise.

Definition at line 654 of file sock.h.

#define sa_mc_orglocal sa   ) 
 

This macro tests if an ev_sockaddr_t contains a org-local multicast address.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a org-local multicast address, false otherwise.

Definition at line 707 of file sock.h.

#define sa_mc_sitelocal sa   ) 
 

This macro tests if an ev_sockaddr_t contains a site-local multicast address.

Warning:
This macro evaluates the sa parameter multiple times.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
Boolean true if sa contains a site-local multicast address, false otherwise.

Definition at line 690 of file sock.h.

#define sa_type sa   ) 
 

This macro retrieves the type for the linked socket address.

Parameters:
[in] sa A pointer to an ev_sockaddr_t.
Returns:
One of AT_IPv6, AT_IPv4, AT_LOCAL, or AT_NONE.

Definition at line 205 of file sock.h.

Referenced by main().

#define SHUT_RD
 

This value, when passed to socket_shutdown() as the how parameter, will cause the read end of the socket to be closed--further receptions will be disallowed.

Definition at line 55 of file sock.h.

#define SHUT_RDWR
 

This value, when passed to socket_shutdown() as the how parameter, will cause both the read and write ends of the socket to be closed--further receptions and transmissions will be disallowed. This is functionally equivalent to calling socket_close().

Definition at line 77 of file sock.h.

#define SHUT_WR
 

This value, when passed to socket_shutdown() as the how parameter, will cause the write end of the socket to be closed--further transmissions will be disallowed.

Definition at line 65 of file sock.h.

#define so_blocked sock   ) 
 

This macro retrieves the blocked flag set from the socket.

Parameters:
[in] sock A pointer to the ev_sock_t from which to retrieve the blocked flag set.
Returns:
The blocked flag set--a bit-wise OR of EV_SOCK_READ and EV_SOCK_WRITE.

Definition at line 893 of file sock.h.

#define so_closed sock   ) 
 

This macro retrieves the closed flag set from the socket.

Parameters:
[in] sock A pointer to the ev_sock_t from which to retrieve the closed flag set.
Returns:
The closed flag set--a bit-wise OR of EV_SOCK_READ and EV_SOCK_WRITE.

Definition at line 905 of file sock.h.

#define so_eevents sock   ) 
 

This macro retrieves the engine event set from the socket.

Parameters:
[in] sock A pointer to the ev_sock_t from which to retrieve the engine event set.
Returns:
The engine event set--a bit-wise OR of EV_SOCK_READ and EV_SOCK_WRITE.

Definition at line 881 of file sock.h.

#define so_fd sock   ) 
 

This macro retrieves the file descriptor for the socket. Note that this will be -1 if the socket state is SS_CLOSED.

Parameters:
[in] sock A pointer to an ev_sock_t.
Returns:
The integer specifying the file descriptor of the socket.

Definition at line 1028 of file sock.h.

#define so_flags sock   ) 
 

This macro retrieves the current flags for the socket.

Parameters:
[in] sock A pointer to an ev_sock_t.
Returns:
The flags for the socket.

Definition at line 1016 of file sock.h.

#define so_peername sock   ) 
 

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.

Parameters:
[in] sock A pointer to an ev_sock_t.
Returns:
A pointer to an ev_sockaddr_t containing the peer address of the socket.

Definition at line 1006 of file sock.h.

#define so_sockname sock   ) 
 

This macro retrieves the address of this side of a socket connection.

Parameters:
[in] sock A pointer to an ev_sock_t.
Returns:
A pointer to an ev_sockaddr_t containing the local address of the socket.

Definition at line 993 of file sock.h.

#define so_state sock   ) 
 

This macro retrieves the current state of the socket, which will be one of the ev_sockstate_t constants.

Parameters:
[in] sock A pointer to an ev_sock_t.
Returns:
One of the ev_sockstate_t constants specifying the state of the socket.

Definition at line 981 of file sock.h.

#define so_type sock   ) 
 

This macro retrieves the type of the socket, which will be one of the ev_socktype_t constants.

Parameters:
[in] sock A pointer to an ev_sock_t.
Returns:
One of the ev_socktype_t constants specifying the type of the socket.

Definition at line 969 of file sock.h.

#define so_uevents sock   ) 
 

This macro retrieves the user event set from the socket.

Parameters:
[in] sock A pointer to the ev_sock_t from which to retrieve the user event set.
Returns:
The user event set--a bit-wise OR of EV_SOCK_READ and EV_SOCK_WRITE.

Definition at line 869 of file sock.h.

#define so_verify sock   ) 
 

This macro verifies that a given pointer actually does point to an ev_sock_t.

Warning:
This macro evaluates the sock argument twice.
Parameters:
[in] sock A pointer to an ev_sock_t.
Returns:
Boolean true if sock is a valid socket generator or false otherwise.

Definition at line 957 of file sock.h.

#define SOCK_ADDRBUFV4_LEN
 

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().

#define SOCK_ADDRBUFV6_LEN
 

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().

#define SOCK_ADDRSTRV4_LEN
 

This macro gives the maximum length, in characters, of the buffer necessary to contain the text representation of an IPv4 address.

Definition at line 92 of file sock.h.

#define SOCK_ADDRSTRV6_LEN
 

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().

#define SOCK_LOCALADDR_LEN
 

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().

#define SOCKADDR_ATOP_NOPORT
 

This flag is used to signal to the sockaddr_atop() function that the caller does not want the port.

Definition at line 1161 of file sock.h.

Referenced by atop_v4(), and atop_v6().


Typedef Documentation

typedef struct _ev_sock_s ev_sock_t
 

Sockets are described using this structure.

Definition at line 170 of file sock.h.

typedef struct _ev_sockaddr_s ev_sockaddr_t
 

This structure is used to abstract the addresses of the socket endpoints.

Definition at line 164 of file sock.h.

typedef struct _ev_sockattr_t* ev_sockattr_t
 

Socket attributes are used to modify various characteristics of the sockets being created.

Definition at line 177 of file sock.h.


Enumeration Type Documentation

enum ev_satype_t
 

This enumeration is used to label a socket address with its corresponding type.

Enumerator:
AT_NONE  No specific address type.
AT_IPv6  IPv6 socket address.
AT_IPv4  IPv4 socket address.
AT_LOCAL  Local domain socket address.

Definition at line 152 of file sock.h.

enum ev_sockstate_t
 

Sockets may be in one of several states. This enumeration describes those states.

Enumerator:
SS_NONE  Socket state unknown.
SS_CONNECTING  A connection is in progress.
SS_LISTENING  Socket is a listening socket.
SS_CONNECTED  Socket is connected to a peer.
SS_UNCONNECTED  Socket is not connected to a peer (datagram sockets).
SS_CLOSED  Socket has been closed.

Definition at line 137 of file sock.h.

enum ev_socktype_t
 

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.)

Enumerator:
ST_NONE  Socket type unknown.
ST_STREAM  Stream socket (TCP).
ST_DGRAM  Datagram socket (UDP).
ST_SEQPACKET  Sequenced packet socket (SCTP).
ST_PIPE  Pipe "socket."

Definition at line 124 of file sock.h.


Function Documentation

ev_err_t sa_ipaddrbuf_set ev_sockaddr_t sa,
const unsigned char *  address
 

This function is used to set the address buffer of the given ev_sockaddr_t to address. Note that the length of the address is determined by the type set on sa. This function is only valid for AT_IPv6 and AT_IPv4 addresses.

Test:
This function is tested in t_sockaddr_fcns.c.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
[in] address A pointer to unsigned char containing the address to fill the address structure with.
Return values:
EINVAL An invalid argument was given.

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().

ev_err_t sa_ipaddrport_set ev_sockaddr_t sa,
unsigned short  port
 

This function is used to set the address port of the given ev_sockaddr_t to port. This function is only valid for AT_IPv6 and AT_IPv4 addresses.

Test:
This function is tested in t_sockaddr_fcns.c.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
[in] port An unsigned short containing the port number (in host byte order).
Return values:
EINVAL An invalid argument was given.

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().

ev_err_t sa_localaddr_set ev_sockaddr_t sa,
const char *  address
 

This function is used to set the local domain address of the given ev_sockaddr_t to address. This function is only valid for AT_LOCAL addresses.

Test:
This function is tested in t_sockaddr_fcns.c.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
[in] address A pointer to char designating the local domain address to set.
Return values:
EINVAL An invalid argument was given.
ENOSPC Address is too large.

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().

ev_err_t sa_type_set ev_sockaddr_t sa,
ev_satype_t  type
 

This function sets the type of the given ev_sockaddr_t to the specified type.

Test:
This function is tested in t_sockaddr_fcns.c.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
[in] type One of the valid type values: AT_IPv6, AT_IPv4, AT_LOCAL, or AT_NONE.
Return values:
EINVAL An invalid argument was given.

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().

ev_err_t sockaddr_atop const ev_sockaddr_t sa,
char *  buf,
int  size,
ev_flags_t  flags
 

This function fills the buffer given with the presentation format of the address given by sa. The representation will be truncated so as to not overflow the buffer, and the terminating '\0' will always be present.

Test:
This function is tested in t_sockaddr_fcns.c.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
[out] buf The buffer to fill in with the presentation format of the address.
[in] size The size of the buffer.
[in] flags Flags to indicate which components of the address to omit; pass 0 to include all components of the address. To omit the port, use the SOCKADDR_ATOP_NOPORT flag. Note that this flag has no meaning for AT_LOCAL addresses.
Return values:
EINVAL An invalid argument was given.

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:

ev_err_t sockaddr_export const ev_sockaddr_t sa,
struct sockaddr *  addr,
int *  len
 

This function fills in a struct sockaddr from the sa socket address.

Test:
This function is tested in t_sockaddr_fcns.c.
Parameters:
[in] sa A pointer to an ev_sockaddr_t to be exported.
[out] addr A pointer to struct sockaddr to be filled in.
[in,out] len This is a value-result parameter; on function entry, it contains the size of the addr buffer, and on return, it will contain the actual amount of data in the buffer.
Return values:
EINVAL An invalid argument was given.
ENOSPC The address would be too large to fit in the user buffer.
ENOSYS Address type is not natively supported.

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().

ev_err_t sockaddr_import ev_sockaddr_t sa,
const struct sockaddr *  addr
 

This function fills in the sa socket address given a pointer to an initialized struct sockaddr.

Test:
This function is tested in t_sockaddr_fcns.c.
Parameters:
[in] sa A pointer to an ev_sockaddr_t to be filled in.
[in] addr A pointer to struct sockaddr containing the address to be imported.
Return values:
EINVAL An invalid argument was given.

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().

ev_err_t sockaddr_ptoa ev_sockaddr_t sa,
const char *  address,
int  alen
 

This function parses the string representation of the address to fill in an ev_sockaddr_t.

Test:
This function is tested in t_sockaddr_fcns.c.
Parameters:
[in] sa A pointer to an ev_sockaddr_t.
[in] address A pointer to char designating the presentation format of the address.
[in] alen The length of the presentation format of the address. If less than 0, the string will be assumed to end with '\0'.
Return values:
EINVAL An invalid argument was given.
EV_ERR_ADDRTOOLONG Address contains too many segments.
EV_ERR_ADDRINCOMPLETE Address is incomplete.
EV_ERR_INVALIDCHAR Invalid character in address.
EV_ERR_COLONEXPECTED A colon was expected.
EV_ERR_BADADDR Unable to parse address.

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().

ev_err_t socket_close ev_ctx_t ctx,
ev_sock_t sock
 

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().

Todo:
Implement; write test program.
Parameters:
[in] ctx A pointer to an ev_ctx_t.
[in] sock A pointer to the ev_sock_t to close.
Return values:
EINVAL An invalid argument was given.
XXX Other errors...

ev_err_t socket_connect ev_ctx_t ctx,
ev_sock_t sock,
const ev_sockaddr_t addr
 

This function calls the connect() function to connect a socket (typically a datagram socket) to a given remote address. If the remote address addr is NULL, the socket will be unconnected.

Todo:
Implement; write test program.
Parameters:
[in] ctx A pointer to an ev_ctx_t.
[in] sock A pointer to the ev_sock_t to connect to addr.
[in] addr The address to which the socket should be connected, or NULL to unconnect the socket.
Return values:
EINVAL An invalid argument was given.
XXX Other errors...

ev_err_t socket_destroy ev_ctx_t ctx,
ev_sock_t sock
 

This function destroys a socket. If the socket is open, unless it was created with the sockattr_noclose() attribute, it will also be closed.

Todo:
Implement; write test program.
Parameters:
[in] ctx A pointer to an ev_ctx_t.
[in] sock A pointer to the ev_sock_t to destroy.
Return values:
EINVAL An invalid argument was given.
XXX Other errors...

ev_err_t socket_events ev_ctx_t ctx,
ev_sock_t sock,
ev_flags_t  events
 

This function changes the set of events the user is interested in on sock to events. The events parameter consists of a bit-wise OR of EV_SOCK_READ, indicating interest in readable conditions on the socket, and EV_SOCK_WRITE, indicating interest in writable conditions on the socket. The function only affects the user's interest set, not the set of events currently being searched for by the library, which may be modified by blocking status.

Todo:
Implement; write test program.
Parameters:
[in] ctx A pointer to an ev_ctx_t.
[in] sock A pointer to the ev_sock_t to change the interest set of.
[in] events The interest set to change to.
Return values:
EINVAL An invalid argument was given.
XXX Other errors...

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
 

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.

Todo:
Implement; write test program.
Parameters:
[in] ctx A pointer to an ev_ctx_t.
[in] fd The socket file descriptor.
[in] type A hint as to the type of the socket. If none of the library-supplied types applies, use the ST_NONE type.
[in] state A hint as to the socket state. If none of the library-supplied states applies, use the SS_NONE state.
[in] local A hint as to the address of the local end of the socket. If the local address cannot be represented by the library, pass NULL.
[in] remote A hint as to the address of the remote end of the socket. If the remote address cannot be represented by the library, pass NULL.
[in] events The initial set of events--a bit-wise OR of EV_SOCK_READ and EV_SOCK_WRITE. See the documentation for socket_events() for more information. The special flags EV_SOCK_TYPE, EV_SOCK_STATE, EV_SOCK_LOCAL, and EV_SOCK_REMOTE may also be used to inhibit the library from attempting to query those attributes.
[in] attr Attributes to apply to the socket. If NULL, the library will not attempt to apply any socket options except non-blocking. See the sockattr_nonblock() function for a means to deactivate this default behavior.
[in] call The callback function for the library to use. If NULL, the library may not be used in the event loop mode.
[in] data Any application-specific data that must be passed to the callback function.
[out] sock_p A pointer to a pointer to an ev_sock_t. A NULL value may be passed if the application does not need a pointer to the socket generator.
Return values:
EINVAL An invalid argument was given.
ENOMEM Out of memory.
XXX Other errors...

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
 

This function will create a socket of the given type, with the local address specified by local. If a remote address is specified, the socket will be connected; otherwise, in the case of an ST_STREAM socket, a listening socket will be created.

Todo:
Implement; write test program.
Parameters:
[in] ctx A pointer to an ev_ctx_t.
[in] type A socket type--one of the constants from the ev_socktype_t enumeration.
[in] local The address for the local end of the connection. If NULL, a suitable default will be chosen. If both local and remote are NULL, the socket will be created in the IPv4 domain.
[in] remote The address for the remote end of the connection. If NULL, the socket will be unconnected (a listening socket, in the case of ST_STREAM sockets). If both local and remote are NULL, the socket will be created in the IPv4 domain.
[in] events The initial set of events--a bit-wise OR of EV_SOCK_READ and EV_SOCK_WRITE. See the documentation for socket_events() for more information.
[in] attr Attributes to apply to the socket. If NULL, the library defaults will be applied.
[in] call The callback function for the library to use. If NULL, the library may not be used in the event loop mode.
[in] data Any application-specific data that must be passed to the callback function.
[out] sock_p A pointer to a pointer to an ev_sock_t. A NULL value may be passed if the application does not need a pointer to the socket generator.
Return values:
EINVAL An invalid argument was given.
ENOMEM Out of memory.
XXX Other errors...

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
 

This function will create a pair of sockets, connected to each other, in the AT_LOCAL domain. (If type is ST_PIPE, a pipe will be created instead.)

Todo:
Implement; write test program.
Parameters:
[in] ctx A pointer to an ev_ctx_t.
[in] type A socket type--one of the constants from the ev_socktype_t enumeration.
[in] events1 The initial set of events for the first end of the socket pair (or for the read end of the pipe)--a bit-wise OR of EV_SOCK_READ and EV_SOCK_WRITE. See the documentation for socket_events() for more information.
[in] attr1 Attributes to apply to the socket or pipe. If NULL, the library defaults will be applied.
[in] call1 The callback function for the library to use. If NULL, the library may not be used in the event loop mode.
[in] data1 Any application-specific data that must be passed to the callback function.
[in] events2 The initial set of events for the second end of the socket pair (or for the write end of the pipe)--a bit-wise OR of EV_SOCK_READ and EV_SOCK_WRITE. See the documentation for socket_events() for more information.
[in] attr2 Attributes to apply to the socket or pipe. If NULL, the library defaults will be applied.
[in] call2 The callback function for the library to use. If NULL, the library may not be used in the event loop mode.
[in] data2 Any application-specific data that must be passed to the callback function.
[out] sock1_p A pointer to a pointer to an ev_sock_t. A NULL value may be passed if the application does not need a pointer to the first socket generator.
[out] sock2_p A pointer to a pointer to an ev_sock_t. A NULL value may be passed if the application does not need a pointer to the second socket generator.
Return values:
EINVAL An invalid argument was given.
ENOMEM Out of memory.
XXX Other errors...

ev_err_t socket_shutdown ev_ctx_t ctx,
ev_sock_t sock,
int  how
 

This function shuts down one direction of the socket, clearing the appropriate event. The how argument should be one of SHUT_RD, SHUT_WR, or SHUT_RDWR. Should the action result in both socket directions being shutdown (as with a how of SHUT_RDWR), the socket will be closed as if with socket_close(). Note that the socket generator will NOT be destroyed in this case; the application must do that explicitly with a call to socket_destroy().

Todo:
Implement; write test program.
Parameters:
[in] ctx A pointer to an ev_ctx_t.
[in] sock A pointer to the ev_sock_t to shut down.
[in] how One of the values SHUT_RD, SHUT_WR, or SHUT_RDWR to shut down the appropriate direction.
Return values:
EINVAL An invalid argument was given.
XXX Other errors...


Generated on Wed Dec 28 23:38:08 2005 for event by  doxygen 1.4.4