include/event2/util.h File Reference

Common convenience functions for cross-platform portability and related socket manipulations. More...

#include <event-config.h>
#include <sys/time.h>
#include <stdint.h>
#include <sys/types.h>
#include <stddef.h>
#include <stdarg.h>

Go to the source code of this file.

Defines

#define ev_int64_t   int64_t
#define ev_uint16_t   uint16_t
#define ev_uint32_t   uint32_t
#define ev_uint64_t   uint64_t
#define ev_uint8_t   uint8_t
#define EVUTIL_CHECK_FMT(a, b)
#define EVUTIL_CLOSESOCKET(s)   close(s)
 Do the platform-specific call needed to close a socket returned from socket() or accept().
#define evutil_gettimeofday(tv, tz)   gettimeofday((tv), (tz))
#define evutil_offsetof(type, field)   ((off_t)(&((type *)0)->field))
#define EVUTIL_SET_SOCKET_ERROR(errcode)   do { errno = (errcode); } while (0)
#define EVUTIL_SOCKET_ERROR()   (errno)
#define evutil_socket_error_to_string(errcode)   (strerror(errcode))
#define evutil_socket_geterror(sock)   (errno)
#define evutil_socket_t   int
#define evutil_timeradd(tvp, uvp, vvp)   timeradd((tvp), (uvp), (vvp))
#define evutil_timerclear(tvp)   timerclear(tvp)
#define evutil_timercmp(tvp, uvp, cmp)
 Return true iff the tvp is related to uvp according to the relational operator cmp.
#define evutil_timerisset(tvp)   timerisset(tvp)
#define evutil_timersub(tvp, uvp, vvp)   timersub((tvp), (uvp), (vvp))

Functions

const char * evutil_inet_ntop (int af, const void *src, char *dst, size_t len)
 Replacement for inet_ntop for platforms which lack it.
int evutil_inet_pton (int af, const char *src, void *dst)
 Replacement for inet_pton for platforms which lack it.
int evutil_make_listen_socket_reuseable (evutil_socket_t)
 Do platform-specific operations on a listener socket to make sure that another program will be able to bind this address right after we've closed the listener.
int evutil_make_socket_nonblocking (evutil_socket_t sock)
 Do platform-specific operations as needed to make a socket nonblocking.
int evutil_parse_sockaddr_port (const char *str, struct sockaddr *out, int *outlen)
 Parse an IPv4 or IPv6 address, with optional port, from a string.
int evutil_snprintf (char *buf, size_t buflen, const char *format,...) EVUTIL_CHECK_FMT(3
 Replacement for snprintf to get consistent behavior on platforms for which the return value of snprintf does not conform to C99.
int evutil_socketpair (int d, int type, int protocol, evutil_socket_t sv[2])
 Create two new sockets that are connected to each other.
ev_int64_t evutil_strtoll (const char *s, char **endptr, int base)
 Parse a 64-bit value from a string.
int int evutil_vsnprintf (char *buf, size_t buflen, const char *format, va_list ap)


Detailed Description

Common convenience functions for cross-platform portability and related socket manipulations.


Define Documentation

#define EVUTIL_CLOSESOCKET (  )     close(s)

Do the platform-specific call needed to close a socket returned from socket() or accept().

#define evutil_timercmp ( tvp,
uvp,
cmp   ) 

Value:

(((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
         ((tvp)->tv_usec cmp (uvp)->tv_usec) :                          \
         ((tvp)->tv_sec cmp (uvp)->tv_sec))
Return true iff the tvp is related to uvp according to the relational operator cmp.

Recognized values for cmp are ==, <=, <, >=, and >.


Function Documentation

const char* evutil_inet_ntop ( int  af,
const void *  src,
char *  dst,
size_t  len 
)

Replacement for inet_ntop for platforms which lack it.

int evutil_inet_pton ( int  af,
const char *  src,
void *  dst 
)

Replacement for inet_pton for platforms which lack it.

int evutil_make_listen_socket_reuseable ( evutil_socket_t   ) 

Do platform-specific operations on a listener socket to make sure that another program will be able to bind this address right after we've closed the listener.

Parameters:
sock The socket to make reuseabla
Returns:
0 on success, -1 on failure

int evutil_make_socket_nonblocking ( evutil_socket_t  sock  ) 

Do platform-specific operations as needed to make a socket nonblocking.

Parameters:
sock The socket to make nonblocking
Returns:
0 on success, -1 on failure

int evutil_parse_sockaddr_port ( const char *  str,
struct sockaddr *  out,
int *  outlen 
)

Parse an IPv4 or IPv6 address, with optional port, from a string.

Recognized formats are:

  • [IPv6Address]:port
  • [IPv6Address]
  • IPv6Address
  • IPv4Address:port
  • IPv4Address

If no port is specified, the port in the output is set to 0.

Parameters:
str The string to parse.
out A struct sockaddr to hold the result. This should probably be a struct sockaddr_storage.
outlen A pointer to the number of bytes that that 'out' can safely hold. Set to the number of bytes used in 'out' on sucess.
Returns:
-1 if the address is not well-formed, if the port is out of range, or if out is not large enough to hold the result. Otherwise returns 0 on success.

int evutil_socketpair ( int  d,
int  type,
int  protocol,
evutil_socket_t  sv[2] 
)

Create two new sockets that are connected to each other.

On Unix, this simply calls socketpair(). On Windows, it uses the loopback network interface on 127.0.0.1, and only AF_INET,SOCK_STREAM are supported.

(This may fail on some Windows hosts where firewall software has cleverly decided to keep 127.0.0.1 from talking to itself.)

Parameters and return values are as for socketpair()

ev_int64_t evutil_strtoll ( const char *  s,
char **  endptr,
int  base 
)

Parse a 64-bit value from a string.

Arguments are as for strtol.


Generated on Fri Apr 17 21:33:56 2009 for libevent by  doxygen 1.5.7