Define IPV6 in Doxyfile, to pull in IPv6-only functions.
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1200
c9e4aea6-c8fd-4c43-8297-
357d70d61c8c
# or name=definition (no spaces). If the definition and the = are
# omitted =1 is assumed.
# or name=definition (no spaces). If the definition and the = are
# omitted =1 is assumed.
-PREDEFINED = DEBUGMODE FORCEINLINE
+PREDEFINED = DEBUGMODE FORCEINLINE IPV6
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.
-/*
- * ircd_osdep.h
- *
- * $Id$
+/** @file ircd_osdep.h
+ * @brief Public definitions and APIs for OS-dependent operations.
+ * @version $Id$
*/
#ifndef INCLUDED_ircd_osdep_h
#define INCLUDED_ircd_osdep_h
*/
#ifndef INCLUDED_ircd_osdep_h
#define INCLUDED_ircd_osdep_h
struct irc_sockaddr;
struct MsgQ;
struct irc_sockaddr;
struct MsgQ;
+/** Result of an input/output operation. */
- IO_FAILURE = -1,
- IO_BLOCKED = 0,
- IO_SUCCESS = 1
+ IO_FAILURE = -1, /**< Serious I/O error (not due to blocking). */
+ IO_BLOCKED = 0, /**< I/O could not start because it would block. */
+ IO_SUCCESS = 1 /**< I/O succeeded. */
* Client struct. When passed as a parameter, the pointer just needs
* to be forwarded to the enumeration function.
*/
* Client struct. When passed as a parameter, the pointer just needs
* to be forwarded to the enumeration function.
*/
-typedef void (*EnumFn)(struct Client*, const char* msg);
+/** Callback function to show rusage information.
+ * @param cptr Client to receive the message.
+ * @param msg Text message to send to user.
+ */
+typedef void (*EnumFn)(struct Client* cptr, const char* msg);
extern int os_disable_options(int fd);
extern int os_get_rusage(struct Client* cptr, int uptime, EnumFn enumerator);
extern int os_disable_options(int fd);
extern int os_get_rusage(struct Client* cptr, int uptime, EnumFn enumerator);
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/* @file
+ * @brief Implementation of OS-dependent operations.
+ * @version $Id$
-#define _XOPEN_SOURCE 500 /* make limits.h #define IOV_MAX */
-#define __EXTENSIONS__ 1 /* make Solaris netinet/in.h know IPv6 */
+#define _XOPEN_SOURCE 500 /**< make limits.h #define IOV_MAX */
+#define __EXTENSIONS__ 1 /**< make Solaris netinet/in.h know IPv6 */
#include "ircd_osdep.h"
#include "msgq.h"
#include "ircd_osdep.h"
#include "msgq.h"
-#define IOV_MAX 16 /* minimum required */
+#define IOV_MAX 16 /**< minimum required length of an iovec array */
+/** Native socket address type. */
#define sockaddr_native sockaddr_in6
#define sockaddr_native sockaddr_in6
+/** Field name inside sockaddr_native to find address family. */
#define sn_family sin6_family
#define sn_family sin6_family
+/** Convert native socket address to IRC format.
+ * @param[in] v6 Native socket address.
+ * @param[out] irc IRC format socket address.
+ */
void sockaddr_to_irc(const struct sockaddr_in6 *v6, struct irc_sockaddr *irc)
{
if (v6->sin6_family == AF_INET6) {
void sockaddr_to_irc(const struct sockaddr_in6 *v6, struct irc_sockaddr *irc)
{
if (v6->sin6_family == AF_INET6) {
else assert(0 && "Unhandled native address family");
}
else assert(0 && "Unhandled native address family");
}
+/** Convert IRC socket address to native format.
+ * @param[out] v6 Native socket address.
+ * @param[in] irc IRC socket address.
+ * @param[in] persist If non-zero, and \a irc is an IPv4 address,
+ * create an AF_INET size address.
+ * @return Length of address written to \a v6.
+ */
int sockaddr_from_irc(struct sockaddr_in6 *v6, const struct irc_sockaddr *irc, int persist)
{
memset(v6, 0, sizeof(*v6));
int sockaddr_from_irc(struct sockaddr_in6 *v6, const struct irc_sockaddr *irc, int persist)
{
memset(v6, 0, sizeof(*v6));
* different field names for "struct rusage".
* -avalon
*/
* different field names for "struct rusage".
* -avalon
*/
+/** Send resource usage information to a client.
+ * @param[in] cptr Client requesting information.
+ * @param[in] uptime Wall time in seconds since the server started.
+ * @param[in] enumerator Function to call to send a line to \a cptr.
+ * @return Zero if some usage reports could not be sent, non-zero on success.
+ */
int os_get_rusage(struct Client *cptr, int uptime, EnumFn enumerator)
{
#ifdef HAVE_GETRUSAGE
int os_get_rusage(struct Client *cptr, int uptime, EnumFn enumerator)
{
#ifdef HAVE_GETRUSAGE
+/** Look up the most recent socket error for a socket file descriptor.
+ * @param[in] fd File descriptor to check.
+ * @return Error code from the socket, or 0 if the OS does not support this.
+ */
int os_get_sockerr(int fd)
{
int err = 0;
int os_get_sockerr(int fd)
{
int err = 0;
-/*
- * set_non_blocking
- *
- * Set the client connection into non-blocking mode. If your
- * system doesn't support this, you can make this a dummy
- * function (and get all the old problems that plagued the
- * blocking version of IRC--not a problem if you are a
- * lightly loaded node...)
+/** Set a file descriptor to non-blocking mode.
+ * @param[in] fd %Socket file descriptor.
+ * @return Non-zero on success, or zero on failure.
*/
int os_set_nonblocking(int fd)
{
*/
int os_set_nonblocking(int fd)
{
+/** Mark a socket's address as reusable.
+ * @param[in] fd %Socket file descriptor to manipulate.
+ * @return Non-zero on success, or zero on failure.
*/
int os_set_reuseaddr(int fd)
{
*/
int os_set_reuseaddr(int fd)
{
(const char*) &opt, sizeof(opt)));
}
(const char*) &opt, sizeof(opt)));
}
+/** Set a socket's send and receive buffer sizes.
+ * @param[in] fd %Socket file descriptor to manipulate.
+ * @param[in] ssize New send buffer size.
+ * @param[in] rsize New receive buffer size.
+ * @return Non-zero on success, or zero on failure.
+ */
int os_set_sockbufs(int fd, unsigned int ssize, unsigned int rsize)
{
unsigned int sopt = ssize;
int os_set_sockbufs(int fd, unsigned int ssize, unsigned int rsize)
{
unsigned int sopt = ssize;
(const char*) &sopt, sizeof(sopt)));
}
(const char*) &sopt, sizeof(sopt)));
}
+/** Set a socket's "type of service" value.
+ * @param[in] fd %Socket file descriptor to manipulate.
+ * @param[in] tos New type of service value to use.
+ * @return Non-zero on success, or zero on failure.
+ */
int os_set_tos(int fd,int tos)
{
#if defined(IP_TOS) && defined(IPPROTO_IP)
int os_set_tos(int fd,int tos)
{
#if defined(IP_TOS) && defined(IPPROTO_IP)
+/** Disable IP options on a socket.
+ * @param[in] fd %Socket file descriptor to manipulate.
+ * @return Non-zero on success, or zero on failure.
+ */
int os_disable_options(int fd)
{
#if defined(IP_OPTIONS) && defined(IPPROTO_IP)
int os_disable_options(int fd)
{
#if defined(IP_OPTIONS) && defined(IPPROTO_IP)
+/** Set file descriptor limit for the process.
+ * @param[in] max_descriptors Ideal number of file descriptors.
+ * @return Zero on success; -1 on error; positive number of possible
+ * file descriptors if \a max_descriptors is too high.
+ */
int os_set_fdlimit(unsigned int max_descriptors)
{
#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_FD_MAX)
struct rlimit limit;
if (!getrlimit(RLIMIT_FD_MAX, &limit)) {
int os_set_fdlimit(unsigned int max_descriptors)
{
#if defined(HAVE_SETRLIMIT) && defined(RLIMIT_FD_MAX)
struct rlimit limit;
if (!getrlimit(RLIMIT_FD_MAX, &limit)) {
- if (limit.rlim_max < MAXCONNECTIONS)
+ if (limit.rlim_max < max_descriptors)
return limit.rlim_max;
limit.rlim_cur = limit.rlim_max; /* make soft limit the max */
return setrlimit(RLIMIT_FD_MAX, &limit);
return limit.rlim_max;
limit.rlim_cur = limit.rlim_max; /* make soft limit the max */
return setrlimit(RLIMIT_FD_MAX, &limit);
-/*
- * os_recv_nonb - non blocking read of a connection
- * returns:
- * 1 if data was read or socket is blocked (recoverable error)
- * count_out > 0 if data was read
- *
- * 0 if socket closed from other end
- * -1 if an unrecoverable error occurred
+/** Attempt to read from a non-blocking socket.
+ * @param[in] fd File descriptor to read from.
+ * @param[out] buf Output buffer to read into.
+ * @param[in] length Number of bytes to read.
+ * @param[out] count_out Receives number of bytes actually read.
+ * @return An IOResult value indicating status.
*/
IOResult os_recv_nonb(int fd, char* buf, unsigned int length,
unsigned int* count_out)
*/
IOResult os_recv_nonb(int fd, char* buf, unsigned int length,
unsigned int* count_out)
+/** Attempt to read from a non-blocking UDP socket.
+ * @param[in] fd File descriptor to read from.
+ * @param[out] buf Output buffer to read into.
+ * @param[in] length Number of bytes to read.
+ * @param[out] length_out Receives number of bytes actually read.
+ * @param[out] addr_out Peer address that sent the message.
+ * @return An IOResult value indicating status.
+ */
IOResult os_recvfrom_nonb(int fd, char* buf, unsigned int length,
unsigned int* length_out,
struct irc_sockaddr* addr_out)
IOResult os_recvfrom_nonb(int fd, char* buf, unsigned int length,
unsigned int* length_out,
struct irc_sockaddr* addr_out)
-/*
- * os_sendto_nonb - non blocking send to a UDP socket
- * returns:
- * 1 if data was written, *count_out contains number of bytes
- * 0 if sendto call blocked
- * -1 if an unrecoverable error occurred
+/** Attempt to write on a non-blocking UDP socket.
+ * @param[in] fd File descriptor to write to.
+ * @param[in] buf Output buffer to send from.
+ * @param[in] length Number of bytes to write.
+ * @param[out] count_out Receives number of bytes actually written.
+ * @param[in] flags Flags for call to sendto().
+ * @param[in] peer Destination address of the message.
+ * @return An IOResult value indicating status.
*/
IOResult os_sendto_nonb(int fd, const char* buf, unsigned int length,
unsigned int* count_out, unsigned int flags,
*/
IOResult os_sendto_nonb(int fd, const char* buf, unsigned int length,
unsigned int* count_out, unsigned int flags,
-/*
- * os_send_nonb - non blocking read of a connection
- * returns:
- * 1 if data was written
- * count_out contains amount written
- *
- * 0 if write call blocked, recoverable error
- * -1 if an unrecoverable error occurred
+/** Attempt to write on a connected socket.
+ * @param[in] fd File descriptor to write to.
+ * @param[in] buf Output buffer to send from.
+ * @param[in] length Number of bytes to write.
+ * @param[out] count_out Receives number of bytes actually written.
+ * @return An IOResult value indicating status.
*/
IOResult os_send_nonb(int fd, const char* buf, unsigned int length,
unsigned int* count_out)
*/
IOResult os_send_nonb(int fd, const char* buf, unsigned int length,
unsigned int* count_out)
+/** Attempt a vectored write on a connected socket.
+ * @param[in] fd File descriptor to write to.
+ * @param[in] buf Message queue to send from.
+ * @param[out] count_in Number of bytes mapped from \a buf.
+ * @param[out] count_out Receives number of bytes actually written.
+ * @return An IOResult value indicating status.
+ */
IOResult os_sendv_nonb(int fd, struct MsgQ* buf, unsigned int* count_in,
unsigned int* count_out)
{
IOResult os_sendv_nonb(int fd, struct MsgQ* buf, unsigned int* count_in,
unsigned int* count_out)
{
+/** Open a TCP or UDP socket on a particular address.
+ * @param[in] local Local address to bind to.
+ * @param[in] type SOCK_STREAM or SOCK_DGRAM.
+ * @param[in] port_name Port name (used in error diagnostics).
+ * @return Bound descriptor, or -1 on error.
+ */
int os_socket(const struct irc_sockaddr* local, int type, const char* port_name)
{
struct sockaddr_native addr;
int os_socket(const struct irc_sockaddr* local, int type, const char* port_name)
{
struct sockaddr_native addr;
+/** Accept a connection on a socket.
+ * @param[in] fd Listening file descriptor.
+ * @param[out] peer Peer address of connection.
+ * @return File descriptor for accepted connection.
+ */
int os_accept(int fd, struct irc_sockaddr* peer)
{
struct sockaddr_native addr;
int os_accept(int fd, struct irc_sockaddr* peer)
{
struct sockaddr_native addr;
+/** Start a non-blocking connection.
+ * @param[in] fd Disconnected file descriptor.
+ * @param[in] sin Target address for connection.
+ * @return IOResult code indicating status.
+ */
IOResult os_connect_nonb(int fd, const struct irc_sockaddr* sin)
{
struct sockaddr_native addr;
IOResult os_connect_nonb(int fd, const struct irc_sockaddr* sin)
{
struct sockaddr_native addr;
+/** Get local address of a socket.
+ * @param[in] fd File descriptor to operate on.
+ * @param[out] sin_out Receives local socket address.
+ * @return Non-zero on success; zero on error.
+ */
int os_get_sockname(int fd, struct irc_sockaddr* sin_out)
{
struct sockaddr_native addr;
int os_get_sockname(int fd, struct irc_sockaddr* sin_out)
{
struct sockaddr_native addr;
+/** Get remote address of a socket.
+ * @param[in] fd File descriptor to operate on.
+ * @param[out] sin_out Receives remote socket address.
+ * @return Non-zero on success; zero on error.
+ */
int os_get_peername(int fd, struct irc_sockaddr* sin_out)
{
struct sockaddr_native addr;
int os_get_peername(int fd, struct irc_sockaddr* sin_out)
{
struct sockaddr_native addr;
+/** Start listening on a socket.
+ * @param[in] fd Disconnected file descriptor.
+ * @param[in] backlog Maximum number of un-accept()ed connections to keep.
+ * @return Non-zero on success; zero on error.
+ */
int os_set_listen(int fd, int backlog)
{
return (0 == listen(fd, backlog));
int os_set_listen(int fd, int backlog)
{
return (0 == listen(fd, backlog));