Mercurial > code
changeset 582:09091721c0b9
Net: reduce column limit
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 20 Jul 2016 17:03:26 +0200 |
parents | e7b311bfcaf1 |
children | c7f92fd77953 |
files | modules/net/net.hpp |
diffstat | 1 files changed, 104 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/modules/net/net.hpp Wed Jul 20 16:41:56 2016 +0200 +++ b/modules/net/net.hpp Wed Jul 20 17:03:26 2016 +0200 @@ -75,31 +75,38 @@ * # General options * * - **NET_NO_AUTO_INIT**: (bool) Set to 0 if you don't want Socket class to - * automatically calls init function and finish functions. + * automatically calls init function and finish functions. * - * - **NET_NO_SSL**: (bool) Set to 0 if you don't have access to OpenSSL library. + * - **NET_NO_SSL**: (bool) Set to 0 if you don't have access to OpenSSL + * library. * - * - **NET_NO_AUTO_SSL_INIT**: (bool) Set to 0 if you don't want Socket class with Tls to automatically init - * the OpenSSL library. You will need to call ssl::init and ssl::finish. + * - **NET_NO_AUTO_SSL_INIT**: (bool) Set to 0 if you don't want Socket class + * with Tls to automatically init the OpenSSL library. You will need to call + * ssl::init and ssl::finish. * * # General compatibility options. * - * The following options are auto detected but you can override them if you want. + * The following options are auto detected but you can override them if you + * want. * - * - **NET_HAVE_INET_PTON**: (bool) Set to 1 if you have inet_pton function. True for all platforms and Windows + * - **NET_HAVE_INET_PTON**: (bool) Set to 1 if you have inet_pton function. + * True for all platforms and Windows * if _WIN32_WINNT is greater or equal to 0x0600. * * - **NET_HAVE_INET_NTOP**: (bool) Same as above. * - * **Note:** On Windows, it is highly encouraged to set _WIN32_WINNT to at least 0x0600 on MinGW. + * **Note:** On Windows, it is highly encouraged to set _WIN32_WINNT to at least + * 0x0600 on MinGW. * * # Options for Listener class * - * Feature detection, multiple implementations may be avaible, for example, Linux has poll, select and epoll. + * Feature detection, multiple implementations may be avaible, for example, + * Linux has poll, select and epoll. * * We assume that `select(2)` is always available. * - * Of course, you can set the variables yourself if you test it with your build system. + * Of course, you can set the variables yourself if you test it with your build + * system. * * - **NET_HAVE_POLL**: Defined on all BSD, Linux. Also defined on Windows * if _WIN32_WINNT is set to 0x0600 or greater. @@ -129,9 +136,11 @@ /** * \page net-concept-backend Backend (Concept) * - * A backend is an interface for the Listener class. It is primarily designed to be the most suitable for the host environment. + * A backend is an interface for the Listener class. It is primarily designed to + * be the most suitable for the host environment. * - * The backend must be default constructible, it is highly encouraged to be move constructible. + * The backend must be default constructible, it is highly encouraged to be move + * constructible. * * This concepts requires the following functions: * @@ -156,7 +165,8 @@ * ## Synopsis * * ```` - * void set(const ListenerTable &table, Handle handle, Condition condition, bool add); + * void set(const ListenerTable &table, Handle handle, Condition condition, + * bool add); * ```` * * ## Arguments @@ -164,7 +174,7 @@ * - **table**: the current table of sockets, * - **handle**: the handle to set, * - **condition**: the condition to add (may be OR'ed), - * - **add**: hint set to true if the handle is not currently registered at all. + * - **add**: hint set to true if the handle is not currently registered. * * # unset * @@ -173,7 +183,8 @@ * ## Synopsis * * ```` - * void unset(const ListenerTable &table, Handle handle, Condition condition, bool remove); + * void unset(const ListenerTable &table, Handle handle, Condition condition, + * bool remove); * ```` * * ## Arguments @@ -208,7 +219,8 @@ * * An option can be set or get from a socket. * - * If an operation is not available, provides the function but throws an exception with ENOSYS message. + * If an operation is not available, provides the function but throws an + * exception with ENOSYS message. * * This concepts requires the following functions: * @@ -301,8 +313,9 @@ * * Accept a new client. * - * If no pending connection is available and operation would block, the implementation must throw WouldBlockError. Any other error - * can be thrown otherwise a valid socket must be returned. + * If no pending connection is available and operation would block, the + * implementation must throw WouldBlockError. Any other error can be thrown + * otherwise a valid socket must be returned. * * ## Synopsis * @@ -394,8 +407,9 @@ * ## Synopsis * * ```` - * unsigned recvfrom(void *data, unsigned length, sockaddr *address, socklen_t *addrlen); // (0) - * unsigned recvfrom(void *data, unsigned length, Address *source) // (1) (Optional) + * unsigned recvfrom(void *data, unsigned length, sockaddr *address, + * socklen_t *addrlen); + * unsigned recvfrom(void *data, unsigned length, Address *source) * ```` * * ## Arguments @@ -417,8 +431,9 @@ * # sendto * * ```` - * unsigned sendto(const void *data, unsigned length, const sockaddr *address, socklen_t addrlen); // (0) - * unsigned sendto(const void *data, unsigned length, const Address &address); // (1) (Optional) + * unsigned sendto(const void *data, unsigned length, const sockaddr *address, + * socklen_t addrlen); + * unsigned sendto(const void *data, unsigned length, const Address &address); * ```` * * ## Arguments @@ -443,7 +458,10 @@ * ------------------------------------------------------------------ */ -// Include Windows headers before because it brings _WIN32_WINNT if not specified by the user. +/* + * Include Windows headers before because it brings _WIN32_WINNT if not + * specified by the user. + */ #if defined(_WIN32) # include <WinSock2.h> # include <WS2tcpip.h> @@ -643,7 +661,8 @@ * Portable constants. * ------------------------------------------------------------------ * - * These constants are needed to check functions return codes, they are rarely needed in end user code. + * These constants are needed to check functions return codes, they are rarely + * needed in end user code. */ #if defined(_WIN32) @@ -683,7 +702,8 @@ } /** - * Initialize the socket library. Except if you defined NET_NO_AUTO_INIT, you don't need to call this + * Initialize the socket library. Except if you defined NET_NO_AUTO_INIT, you + * don't need to call this * function manually. */ inline void init() noexcept @@ -700,7 +720,10 @@ WSADATA wsa; WSAStartup(MAKEWORD(2, 2), &wsa); - // If NET_NO_AUTO_INIT is not set then the user must also call finish himself. + /* + * If NET_NO_AUTO_INIT is not set then the user must also call finish + * himself. + */ #if !defined(NET_NO_AUTO_INIT) atexit(finish); #endif @@ -740,7 +763,8 @@ } /** - * Get the last socket system error. The error is set from errno or from WSAGetLastError on Windows. + * Get the last socket system error. The error is set from errno or from + * WSAGetLastError on Windows. * * \return a string message */ @@ -770,8 +794,8 @@ }; /** - * Initialize the OpenSSL library. Except if you defined NET_NO_AUTO_SSL_INIT, you don't need to call this function - * manually. + * Initialize the OpenSSL library. Except if you defined NET_NO_AUTO_SSL_INIT, + * you don't need to call this function manually. */ inline void init() noexcept { @@ -1138,8 +1162,9 @@ * * This iterator can be used to try to connect to an host. * - * When you use resolve with unspecified domain or socket type, the function may retrieve several different addresses that you can - * iterate over to try to connect to. + * When you use resolve with unspecified domain or socket type, the function may + * retrieve several different addresses that you can iterate over to try to + * connect to. * * Example: * @@ -1151,7 +1176,8 @@ * sc.connect(it->address(), it->length()); * ```` * - * When an iterator equals to a default constructed iterator, it is considered not dereferenceable. + * When an iterator equals to a default constructed iterator, it is considered + * not dereferenceable. */ class AddressIterator : public std::iterator<std::forward_iterator_tag, Address> { private: @@ -1332,8 +1358,8 @@ /** * Create a socket handle. * - * This is the primary function and the only one that creates the socket handle, all other constructors - * are just overloaded functions. + * This is the primary function and the only one that creates the socket + * handle, all other constructors are just overloaded functions. * * \param domain the domain AF_* * \param type the type SOCK_* @@ -1362,7 +1388,8 @@ } /** - * Create an invalid socket. Can be used when you cannot instanciate the socket immediately. + * Create an invalid socket. Can be used when you cannot instanciate the + * socket immediately. */ explicit inline Socket(std::nullptr_t) noexcept : m_handle(Invalid) @@ -1466,8 +1493,8 @@ /** * Object-oriented option getter. * - * The object must have `T get(Socket &) const`, T can be any type and it is the value - * returned from this function. + * The object must have `T get(Socket &) const`, T can be any type and it is + * the value returned from this function. * * \pre isOpen() * \return the same value as get() in the option @@ -1693,7 +1720,8 @@ * \brief Clear TCP implementation. * \ingroup net-module-tcp * - * This is the basic TCP protocol that implements recv, send, connect and accept as wrappers of the usual C functions. + * This is the basic TCP protocol that implements recv, send, connect and accept + * as wrappers of the usual C functions. */ class TcpSocket : public Socket { public: @@ -1729,7 +1757,8 @@ * * \param address the address * \param length the address length - * \throw WouldBlockError if the socket is marked non-blocking and connection cannot be established immediately + * \throw WouldBlockError if the socket is marked non-blocking and + * connection cannot be established immediately * \throw Error on other errors */ void connect(const sockaddr *address, socklen_t length) @@ -1755,7 +1784,8 @@ * Overloaded function. * * \param address the address - * \throw WouldBlockError if the socket is marked non-blocking and connection cannot be established immediately + * \throw WouldBlockError if the socket is marked non-blocking and + * connection cannot be established immediately * \throw Error on other errors */ void connect(const Address &address) @@ -1769,7 +1799,8 @@ * If there are no pending connection, an invalid socket is returned. * * \return the new socket - * \throw WouldBlockError if the socket is marked non-blocking and no connection are available + * \throw WouldBlockError if the socket is marked non-blocking and no + * connection are available * \throw Error on other errors */ TcpSocket accept() @@ -1900,7 +1931,8 @@ * \param address the source address * \param addrlen the source address in/out length * \return the number of bytes received - * \throw WouldBlockError if the socket is marked non-blocking and the operation would block + * \throw WouldBlockError if the socket is marked non-blocking and the + * operation would block * \throw Error on other errors */ unsigned recvfrom(void *data, unsigned length, sockaddr *address, socklen_t *addrlen) @@ -1933,7 +1965,8 @@ * \param data the data * \param length the length * \param source the source information (optional) - * \throw WouldBlockError if the socket is marked non-blocking and the operation would block + * \throw WouldBlockError if the socket is marked non-blocking and the + * operation would block * \throw Error on other errors */ inline unsigned recvfrom(void *data, unsigned length, Address *source = nullptr) @@ -1957,7 +1990,8 @@ * \param address the destination address * \param addrlen the destination address length * \return the number of bytes sent - * \throw WouldBlockError if the socket is marked non-blocking and the operation would block + * \throw WouldBlockError if the socket is marked non-blocking and the + * operation would block * \throw Error on other errors */ unsigned sendto(const void *data, unsigned length, const sockaddr *address, socklen_t addrlen) @@ -1991,7 +2025,8 @@ * \param length the data length * \param address the destination address * \return the number of bytes sent - * \throw WouldBlockError if the socket is marked non-blocking and the operation would block + * \throw WouldBlockError if the socket is marked non-blocking and the + * operation would block * \throw Error on other errors */ inline unsigned sendto(const void *data, unsigned length, const Address &address) @@ -2013,8 +2048,8 @@ * \brief SSL connection mode. */ enum Mode { - Server, //!< Use Server when you accept a socket server side, - Client //!< Use Client when you connect to a server. + Server, //!< Use Server when you accept a socket server side, + Client //!< Use Client when you connect to a server. }; private: @@ -2081,7 +2116,8 @@ /** * Create a socket around an existing one. * - * The original socket is moved to this instance and must not be used anymore. + * The original socket is moved to this instance and must not be used + * anymore. * * \param sock the TCP socket * \param mode the mode @@ -2487,7 +2523,8 @@ /** * \ingroup net-module-options * \brief Set or get the blocking-mode for a socket. - * \warning On Windows, it's not possible to check if the socket is blocking or not. + * \warning On Windows, it's not possible to check if the socket is blocking or + * not. */ class SockBlockMode { private: @@ -2739,7 +2776,8 @@ * \ingroup net-module-options * \brief Control IPPROTO_IPV6/IPV6_V6ONLY * - * Note: some systems may or not set this option by default so it's a good idea to set it in any case to either + * Note: some systems may or not set this option by default so it's a good idea + * to set it in any case to either * false or true if portability is a concern. */ class Ipv6Only { @@ -2903,9 +2941,9 @@ } /** - * For set and unset, we need to apply the whole flags required, so if the socket - * was set to Connection::Readable and user *8adds** Connection::Writable, we must - * place both. + * For set and unset, we need to apply the whole flags required, so if the + * socket was set to Connection::Readable and user **adds** + * Connection::Writable, we must set both. * * \param table the listener table * \param h the handle @@ -3171,9 +3209,11 @@ Condition condition = Condition::None; /* - * Poll implementations mark the socket differently regarding the disconnection of a socket. + * Poll implementations mark the socket differently regarding the + * disconnection of a socket. * - * At least, even if POLLHUP or POLLIN is set, recv() always return 0 so we mark the socket as readable. + * At least, even if POLLHUP or POLLIN is set, recv() always return 0 so + * we mark the socket as readable. */ if ((event & POLLIN) || (event & POLLHUP)) condition |= Condition::Readable; @@ -3274,7 +3314,8 @@ * \ingroup net-module-backends * \brief Implements select(2) * - * This class is the fallback of any other method, it is not preferred at all for many reasons. + * This class is the fallback of any other method, it is not preferred at all + * for many reasons. */ class Select { public: @@ -3528,7 +3569,8 @@ /** * Remove completely the socket from the listener. * - * It is a shorthand for unset(sc, Condition::Readable | Condition::Writable); + * It is a shorthand for unset(sc, Condition::Readable | + * Condition::Writable); * * \param sc the socket */ @@ -3557,7 +3599,8 @@ } /** - * Select a socket. Waits for a specific amount of time specified as the duration. + * Select a socket. Waits for a specific amount of time specified as the + * duration. * * \param duration the duration * \return the socket ready @@ -3620,7 +3663,10 @@ * \return the address iterator * \throw Error on failures */ -inline AddressIterator resolve(const std::string &host, const std::string &service, int domain = AF_UNSPEC, int type = 0) +inline AddressIterator resolve(const std::string &host, + const std::string &service, + int domain = AF_UNSPEC, + int type = 0) { #if !defined(NET_NO_AUTO_INIT) init();