diff --git a/include/socket.hpp b/include/socket.hpp index fee0e16..b77ef35 100644 --- a/include/socket.hpp +++ b/include/socket.hpp @@ -9,12 +9,18 @@ namespace net { +/** +* @class net::Socket +* Socket class to create Berkeley sockets. +* Uses socket domains from domain enum in SF namespace from socket_family.hpp +* Uses socket types from type enum in SF namespace from socket_family.hpp +*/ class Socket final { private: union { addrStore store; - addrIpv4 ipv4; - addrIpv6 ipv6; + addrIPv4 ipv4; + addrIPv6 ipv6; addrUnix unix; }; int sockfd; @@ -22,13 +28,25 @@ class Socket final { SF::type type; + /** + * @method low_write + * @access private + * Writes given _msg using _sockfd by calling _fn with args having flags and + * destination socket address. + * + * @param {callable} _fn Some callable that writes using socket descriptor. + * @param {string} _msg Msg to write on sockfd. + * @param {parameter_pack} args Flags, destination sockaddr objects and their + * lengths. + * @returns {ssize_t} Status of writing _msg using socket descriptor / Number + * of bytes written using socket descriptor. + */ template - auto low_write(Fn &&_fn, const int _sockfd, const std::string &_msg, - Args &&... args) const + auto low_write(Fn &&_fn, const std::string &_msg, Args &&... args) const { auto written = 0, count = 0; do { - written = std::forward(_fn)(_sockfd, _msg.c_str() + count, + written = std::forward(_fn)(sockfd, _msg.c_str() + count, _msg.length() - count, std::forward(args)...); count += written; @@ -38,9 +56,21 @@ class Socket final { } + /** + * @method low_read + * @access private + * Reads using sockfd by calling _fn with args having flags and destination + * socket address. + * + * @param {callable} _fn Some callable that reads using socket descriptor. + * @param {string} _str String to store the data. + * @param {parameter_pack} args Flags, destination sockaddr objects and their + * lengths. + * @returns {ssize_t} Status of reading data using socket descriptor / Number + * of bytes read using socket descriptor. + */ template - auto low_read(Fn &&_fn, const int _sockfd, std::string &_str, - Args &&... args) const + auto low_read(Fn &&_fn, std::string &_str, Args &&... args) const { ssize_t recvd = 0; size_t count = 0; @@ -49,7 +79,7 @@ class Socket final { const auto buffer = std::make_unique(bufSize + 1); do { - recvd = std::forward(_fn)(_sockfd, buffer.get() + count, + recvd = std::forward(_fn)(sockfd, buffer.get() + count, bufSize - count, std::forward(args)...); count += recvd; @@ -66,12 +96,28 @@ class Socket final { } + /** + * @construct Socket + * @access private + * @param {int} _sockfd Descriptor representing a socket. + * @param {SF::domain} _domain Socket domain. + * @param {void *} _addr Pointer to initialize appropriate member of Union of + * net::Socket. + */ Socket(const int, SF::domain, SF::type, const void *); Socket(const Socket &) = delete; Socket &operator=(const Socket &) = delete; + public: + /** + * @construct net::Socket + * @access public + * @param {SF::domain} _domain Socket domain. + * @param {SF::type} _type Socket type. + * @param {int} _proto Socket protocol. + */ Socket(SF::domain _domain, SF::type _type, const int _proto = 0) : domain(_domain), type(_type) { @@ -94,6 +140,11 @@ class Socket final { } + /** + * @construct net::Socket using another net::Socket. + * @access public + * @param {Socket} s Rvalue of type socket. + */ Socket(Socket &&s) { sockfd = s.sockfd; @@ -109,14 +160,31 @@ class Socket final { } } + + /** + * @method getSocket + * @access public + * Get the socket descriptor in net::Socket. + * + * @returns {int} Socket descriptor for net::Socket. + */ auto getSocket() const noexcept { return sockfd; } - // Bind method calls + /** + * @method bind + * @access public + * Binds net::Socket to local address if successful else if Address argument + * is invalid then throws invalid_argument exception + * else throws runtime_error exception signalling that bind failed. Invokes + * the callable provided to fill addrIPv4 object. + * + * @param {callable} _fn Some callable that takes arg of type addrIPv4. + */ template - auto bind(F _fn) -> decltype(_fn(std::declval()), void()) const + auto bind(F _fn) -> decltype(_fn(std::declval()), void()) const { - addrIpv4 addr; + addrIPv4 addr; auto res = _fn(addr); if (res == 1) { @@ -135,10 +203,20 @@ class Socket final { } + /** + * @method bind + * @access public + * Binds net::Socket to local address if successful else if Address argument + * is invalid then throws invalid_argument exception + * else throws runtime_error exception signalling that bind failed. Invokes + * the callable provided to fill addrIPv6 object. + * + * @param {callable} _fn Some callable that takes arg of type addrIPv6. + */ template - auto bind(F _fn) -> decltype(_fn(std::declval()), void()) const + auto bind(F _fn) -> decltype(_fn(std::declval()), void()) const { - addrIpv6 addr; + addrIPv6 addr; auto res = _fn(addr); if (res == 1) { @@ -157,6 +235,16 @@ class Socket final { } + /** + * @method bind + * @access public + * Binds net::Socket to local address if successful else if Address argument + * is invalid then throws invalid_argument exception + * else throws runtime_error exception signalling that bind failed. Invokes + * the callable provided to fill addrUnix object. + * + * @param {callable} _fn Some callable that takes arg of type addrUnix. + */ template auto bind(F _fn) -> decltype(_fn(std::declval()), void()) const { @@ -177,17 +265,39 @@ class Socket final { unix = addr; } - // Bind method calls - // Connect method calls + /** + * @method connect + * @access public + * Connects net::Socket to address _addr:_port if successful else throws + * invalid_argument exception. + * + * @param {char []} _addr Ip address in case of ipv4 or ipv6 domain, and Path + * in case of unix domain. + * @param {int} _port Port number in case of addrIPv4 or addrIPv6. + * @param {bool *} _errorNB To signal error in case of non-blocking connect. + */ void connect(const char[], const int = 0, bool * = nullptr); + + /** + * @method connect + * @access public + * Connects net::Socket to ipv4 peer if successful else throws runtime_error + * exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * Throws invalid_argument exception if destination address given is invalid. + * + * @param {callable} _fn Some callable that takes arg of type addrIPv4. + * @param {bool *} _errorNB To signal error in case of non-blocking connect. + */ template auto connect(F _fn, bool *_errorNB = nullptr) - -> decltype(_fn(std::declval()), void()) const + -> decltype(_fn(std::declval()), void()) const { - addrIpv4 addr; + addrIPv4 addr; auto res = _fn(addr); if (res == 1) { @@ -212,11 +322,24 @@ class Socket final { } + /** + * @method connect + * @access public + * Connects net::Socket to ipv6 peer if successful else throws runtime_error + * exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * Throws invalid_argument exception if destination address given is invalid. + * Invokes the callable provided to fill addrIPv4 object. + * + * @param {callable} _fn Some callable that takes arg of type addrIPv6. + * @param {bool *} _errorNB To signal error in case of non-blocking connect. + */ template auto connect(F _fn, bool *_errorNB = nullptr) - -> decltype(_fn(std::declval()), void()) const + -> decltype(_fn(std::declval()), void()) const { - addrIpv6 addr; + addrIPv6 addr; auto res = _fn(addr); if (res == 1) { @@ -241,6 +364,19 @@ class Socket final { } + /** + * @method connect + * @access public + * Connects net::Socket to unix socket peer if successful else throws + * runtime_error exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * Throws invalid_argument exception if destination address given is invalid. + * Invokes the callable provided to fill addrIPv4 object. + * + * @param {callable} _fn Some callable that takes arg of type addrUnix. + * @param {bool *} _errorNB To signal error in case of non-blocking connect. + */ template auto connect(F _fn, bool *_errorNB = nullptr) -> decltype(_fn(std::declval()), void()) const @@ -268,29 +404,106 @@ class Socket final { throw std::invalid_argument("Address argument invalid"); } } - // Connect method calls + /** + * @method start + * @access public + * Starts the net::Socket in listen mode on given ip address and given port + * with given backlog if successful + * else throws runtime_error exception. + * Throws invalid_argument exception if given ip address or port are not + * valid. + * + * @param {char []} _addr Ip address in case of ipv4 or ipv6 domain, and Path + * in case of unix domain. + * @param {int} _port Port number in case of ipv4 or ipv6. + * @param {int} _q Size of backlog of listening socket. + */ void start(const char[], const int = 0, const int = SOMAXCONN); + + /** + * @method accept + * @access public + * Returns Socket object from connected sockets queue if successful else + * throws runtime_error exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * + * @param {bool *} _errorNB To signal error in case of non-blocking accept. + * @returns {net::Socket} + */ Socket accept(bool * = nullptr) const; + /** + * @method write + * @access public + * Writes given string to Socket if successful else throws runtime_error + * exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * + * @param {string} _msg String to be written to Socket. + * @param {bool *} _errorNB To signal error in case of non-blocking write. + */ void write(const std::string &, bool * = nullptr) const; + + + /** + * @method read + * @access public + * Reads given number of bytes using Socket if successful else throws + * runtime_error exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * + * @param {int} _bufSize Number of bytes to be read using Socket. + * @param {bool *} _errorNB To signal error in case of non-blocking read. + * @returns {string} String of _bufSize bytes read using Socket. + */ std::string read(const int = 1024, bool * = nullptr) const; - // Send method calls + /** + * @method send + * @access public + * Sends given string using Socket if successful else throws runtime_error + * exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * + * @param {string} _msg String to be sent using Socket. + * @param {SF::send} _flags Modify default behaviour of send. + * @param {bool *} _errorNB To signal error in case of non-blocking send. + */ void send(const std::string &, SF::send = SF::send::NONE, bool * = nullptr) const; + /** + * @method send + * @access public + * Sends given string using Socket if successful else throws runtime_error + * exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * Throws invalid_argument exception if destination address given is invalid. + * Invokes the callable provided to fill addrIPv4 object. + * + * @param {string} _msg String to be sent using Socket. + * @param {callable} _fn Some callable that takes arg of type addrIPv4 or + * void. + * @param {SF::send} _flags Modify default behaviour of send. + * @param {bool *} _errorNB To signal error in case of non-blocking send. + */ template auto send(const std::string &_msg, F _fn, SF::send _flags = SF::send::NONE, bool *_errorNB = nullptr) const - -> decltype(_fn(std::declval()), void()) const + -> decltype(_fn(std::declval()), void()) const { - addrIpv4 addr; + addrIPv4 addr; const auto flags = static_cast(_flags); const auto res = _fn(addr); @@ -301,7 +514,7 @@ class Socket final { ssize_t sent = -1; if (res == 1) { - sent = low_write(::sendto, sockfd, _msg, flags, (sockaddr *) &addr, + sent = low_write(::sendto, _msg, flags, (sockaddr *) &addr, sizeof(addr)); } @@ -320,12 +533,28 @@ class Socket final { } + /** + * @method send + * @access public + * Sends given string using Socket if successful else throws runtime_error + * exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * Throws invalid_argument exception if destination address given is invalid. + * Invokes the callable provided to fill addrIPv6 object. + * + * @param {string} _msg String to be sent using Socket. + * @param {callable} _fn Some callable that takes arg of type addrIPv6 or + * void. + * @param {SF::send} _flags Modify default behaviour of send. + * @param {bool *} _errorNB To signal error in case of non-blocking send. + */ template auto send(const std::string &_msg, F _fn, SF::send _flags = SF::send::NONE, bool *_errorNB = nullptr) const - -> decltype(_fn(std::declval()), void()) const + -> decltype(_fn(std::declval()), void()) const { - addrIpv6 addr; + addrIPv6 addr; const auto flags = static_cast(_flags); const auto res = _fn(addr); @@ -336,7 +565,7 @@ class Socket final { ssize_t sent = -1; if (res == 1) { - sent = low_write(::sendto, sockfd, _msg, flags, (sockaddr *) &addr, + sent = low_write(::sendto, _msg, flags, (sockaddr *) &addr, sizeof(addr)); } @@ -355,6 +584,22 @@ class Socket final { } + /** + * @method send + * @access public + * Sends given string using Socket if successful else throws runtime_error + * exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * Throws invalid_argument exception if destination address given is invalid. + * Invokes the callable provided to fill addrUnix object. + * + * @param {string} _msg String to be sent using Socket. + * @param {callable} _fn Some callable that takes arg of type addrUnix or + * void. + * @param {SF::send} _flags Modify default behaviour of send. + * @param {bool *} _errorNB To signal error in case of non-blocking send. + */ template auto send(const std::string &_msg, F _fn, SF::send _flags = SF::send::NONE, bool *_errorNB = nullptr) const @@ -371,7 +616,7 @@ class Socket final { ssize_t sent = -1; if (res == 1) { - sent = low_write(::sendto, sockfd, _msg, flags, (sockaddr *) &addr, + sent = low_write(::sendto, _msg, flags, (sockaddr *) &addr, sizeof(addr)); } @@ -388,27 +633,54 @@ class Socket final { } } } - // Send method calls - - // recv method calls + /** + * @method recv + * @access public + * Reads given number of bytes using Socket if successful else throws + * runtime_error exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * + * @param {int} _bufSize Number of bytes to be read using Socket. + * @param {SF::recv} _flags Modify default behaviour of recv. + * @param {bool *} _errorNB To signal error in case of non-blocking recv. + * @returns {string} String of _bufSize bytes read from socket. + */ std::string recv(const int = 1024, SF::recv = SF::recv::NONE, bool * = nullptr) const; + + /** + * @method recv + * @access public + * Reads given number of bytes using Socket if successful else throws + * runtime_error exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * Throws invalid_argument exception if destination address given is invalid. + * Invokes the callable provided to fill addrIPv4 object. + * + * @param {string} _msg String to be sent using Socket. + * @param {callable} _fn Some callable that takes arg of type addrIPv4 or + * void. + * @param {SF::recv} _flags Modify default behaviour of recv. + * @param {bool *} _errorNB To signal error in case of non-blocking recv. + */ template auto recv(const int _bufSize, F _fn, SF::recv _flags, bool *_errorNB) const - -> decltype(_fn(std::declval()), std::string()) const + -> decltype(_fn(std::declval()), std::string()) const { - addrIpv4 addr; + addrIPv4 addr; std::string str; str.reserve(_bufSize); const auto flags = static_cast(_flags); socklen_t length = sizeof(addr); - const auto recvd = low_read(::recvfrom, sockfd, str, flags, - (sockaddr *) &addr, &length); + const auto recvd + = low_read(::recvfrom, str, flags, (sockaddr *) &addr, &length); const auto currErrno = errno; if (recvd == -1) { @@ -428,19 +700,35 @@ class Socket final { } + /** + * @method recv + * @access public + * Reads given number of bytes using Socket if successful else throws + * runtime_error exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * Throws invalid_argument exception if destination address given is invalid. + * Invokes the callable provided to fill addrIPv6 object. + * + * @param {string} _msg String to be sent using Socket. + * @param {callable} _fn Some callable that takes arg of type addrIPv6 or + * void. + * @param {SF::recv} _flags Modify default behaviour of recv. + * @param {bool *} _errorNB To signal error in case of non-blocking recv. + */ template auto recv(const int _bufSize, F _fn, SF::recv _flags, bool *_errorNB) const - -> decltype(_fn(std::declval()), std::string()) const + -> decltype(_fn(std::declval()), std::string()) const { - addrIpv6 addr; + addrIPv6 addr; std::string str; str.reserve(_bufSize); const auto flags = static_cast(_flags); socklen_t length = sizeof(addr); - const auto recvd = low_read(::recvfrom, sockfd, str, flags, - (sockaddr *) &addr, &length); + const auto recvd + = low_read(::recvfrom, str, flags, (sockaddr *) &addr, &length); const auto currErrno = errno; if (recvd == -1) { @@ -460,6 +748,22 @@ class Socket final { } + /** + * @method recv + * @access public + * Reads given number of bytes using Socket if successful else throws + * runtime_error exception. + * Throws invalid_argument exception in case of non-blocking net::Socket if + * _errorNB is missing. + * Throws invalid_argument exception if destination address given is invalid. + * Invokes the callable provided to fill addrUnix object. + * + * @param {string} _msg String to be sent using Socket. + * @param {callable} _fn Some callable that takes arg of type addrUnix or + * void. + * @param {SF::recv} _flags Modify default behaviour of recv. + * @param {bool *} _errorNB To signal error in case of non-blocking recv. + */ template auto recv(const int _bufSize, F _fn, SF::recv _flags, bool *_errorNB) const -> decltype(_fn(std::declval()), std::string()) const @@ -471,8 +775,8 @@ class Socket final { const auto flags = static_cast(_flags); socklen_t length = sizeof(addr); - const auto recvd = low_read(::recvfrom, sockfd, str, flags, - (sockaddr *) &addr, &length); + const auto recvd + = low_read(::recvfrom, str, flags, (sockaddr *) &addr, &length); const auto currErrno = errno; if (recvd == -1) { @@ -490,19 +794,53 @@ class Socket final { _fn(addr); return str; } - // recv method calls + /** + * @method setOpt + * @access public + * Set a socket option from net::SF::opt for Socket using object of type + * net::SF::sockOpt. + * + * @param {net::SF::opt} _opType Option to set for Socket. + * @param {net::SF::sockOpt} _opValue socket option structure. Present inside + * socket_family.hpp. + */ void setOpt(SF::opt, SF::sockOpt) const; + + + /** + * @method getOpt + * @access public + * Get value of some socket option for Socket. + * + * @param {net::SF::opt} _opType Option of Socket whose value to get. + */ SF::sockOpt getOpt(SF::opt) const; - void stop(SF::shut s) const noexcept + + /** + * @method stop + * @access public + * Shutdown Socket using net::SF::shut. + * + * @param {net::SF::shut} _s Option specifying which side of connection to + * shutdown for Socket. + */ + void stop(SF::shut _s) const noexcept { - shutdown(sockfd, static_cast(s)); + shutdown(sockfd, static_cast(_s)); } + + /** + * method close + * @access public + * Closes the Socket for terminating connection. + */ void close() const noexcept { ::close(sockfd); } + ~Socket() { // TODO: unlink() the path in case of addrUnix diff --git a/include/socket_family.hpp b/include/socket_family.hpp index f204c71..d777023 100644 --- a/include/socket_family.hpp +++ b/include/socket_family.hpp @@ -15,10 +15,11 @@ extern "C" { #include } + namespace net { -using addrIpv4 = sockaddr_in; -using addrIpv6 = sockaddr_in6; +using addrIPv4 = sockaddr_in; +using addrIPv6 = sockaddr_in6; using addrUnix = sockaddr_un; using addrStore = sockaddr_storage; @@ -149,6 +150,15 @@ namespace SF { namespace methods { + /** + * @function getErrorMsg + * Returns the standard human readable error message corresponding to given + * errorNumber. + * + * @param {int} errorNumber Error number whose string to return. + * @returns {string} Standard error string corresponding to given + * errorNumber. + */ inline std::string getErrorMsg(const int errorNumber) { static std::mutex m; @@ -158,35 +168,70 @@ namespace methods { return returnString; } - - inline int construct(addrIpv4 &addrStruct, const char _addr[], + /** + * @function construct + * Fills the given addrIPv4 structure object with given ip address and port. + * + * @param {addrIPv4} _addrStruct Ipv4 structure object that needs to be + * filled with given ip address and port. + * @param {char []} _addr Ip address which needs to be filled in the addrIPv4 + * structure object. + * @param {int} _port Port number which needs to be filled in the addrIPv4 + * structure object. + * @returns {int} 1 if sucessful, 0 if given ip address does not represent a + * valid ip address, -1 if some error occurred. + */ + inline int construct(addrIPv4 &_addrStruct, const char _addr[], const int _port) noexcept { - std::memset(&addrStruct, 0, sizeof(addrStruct)); - addrStruct.sin_family = AF_INET; - addrStruct.sin_port = htons(_port); + std::memset(&_addrStruct, 0, sizeof(_addrStruct)); + _addrStruct.sin_family = AF_INET; + _addrStruct.sin_port = htons(_port); - return inet_pton(AF_INET, _addr, &addrStruct.sin_addr); + return inet_pton(AF_INET, _addr, &_addrStruct.sin_addr); } - inline int construct(addrIpv6 &addrStruct, const char _addr[], + /** + * @function construct + * Fills the given addrIPv6 structure object with given ip address and port. + * + * @param {addrIPv6} _addrStruct - Ipv6 structure object that needs to be + * filled with given ip address and port. + * @param {char []} _addr Ip address which needs to be filled in the addrIPv6 + * structure object. + * @param {int} _port Port number which needs to be filled in the addrIPv6 + * structure object. + * @returns {int} 1 if sucessful, 0 if given ip address does not represent a + * valid ip address, -1 if some error occurred. + */ + inline int construct(addrIPv6 &_addrStruct, const char _addr[], const int _port) noexcept { // TODO: replace code with call to getaddrinfo() - std::memset(&addrStruct, 0, sizeof(addrStruct)); - addrStruct.sin6_family = AF_INET6; - addrStruct.sin6_port = htons(_port); + std::memset(&_addrStruct, 0, sizeof(_addrStruct)); + _addrStruct.sin6_family = AF_INET6; + _addrStruct.sin6_port = htons(_port); - return inet_pton(AF_INET6, _addr, &addrStruct.sin6_addr); + return inet_pton(AF_INET6, _addr, &_addrStruct.sin6_addr); } - inline int construct(addrUnix &addrStruct, const char _addr[]) noexcept + /** + * @function construct + * Fills the given addrUnix structure object with given address. + * + * @param {addrUnix} _addrStruct structure object that needs to be filled + * with given path. + * @param {char []} _addr Path which needs to be filled in the addrUnix + * structure object. + * @returns {int} Always returns 1. + */ + inline int construct(addrUnix &_addrStruct, const char _addr[]) noexcept { - std::memset(&addrStruct, 0, sizeof(addrStruct)); - addrStruct.sun_family = AF_UNIX; - std::strncpy(addrStruct.sun_path, _addr, 108); + std::memset(&_addrStruct, 0, sizeof(_addrStruct)); + _addrStruct.sun_family = AF_UNIX; + std::strncpy(_addrStruct.sun_path, _addr, 108); return 1; } } diff --git a/src/socket.cpp b/src/socket.cpp index f2b63ce..95d9121 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -35,13 +35,13 @@ void Socket::start(const char _addr[], const int _port, const int _q) try { switch (domain) { case SF::domain::IPv4: - bind([&](addrIpv4 &s) { + bind([&](addrIPv4 &s) { return net::methods::construct(s, _addr, _port); }); break; case SF::domain::IPv6: - bind([&](addrIpv6 &s) { + bind([&](addrIPv6 &s) { return net::methods::construct(s, _addr, _port); }); break; @@ -73,13 +73,13 @@ void Socket::connect(const char _addr[], const int _port, bool *_errorNB) try { switch (domain) { case SF::domain::IPv4: - connect([&](addrIpv4 &s) { + connect([&](addrIPv4 &s) { return net::methods::construct(s, _addr, _port); }, _errorNB); break; case SF::domain::IPv6: - connect([&](addrIpv6 &s) { + connect([&](addrIPv6 &s) { return net::methods::construct(s, _addr, _port); }, _errorNB); break; @@ -102,8 +102,8 @@ void Socket::connect(const char _addr[], const int _port, bool *_errorNB) Socket Socket::accept(bool *_errorNB) const { union { - addrIpv4 ipv4; - addrIpv6 ipv6; + addrIPv4 ipv4; + addrIPv6 ipv6; addrUnix unix; addrStore store; }; @@ -163,7 +163,7 @@ Socket Socket::accept(bool *_errorNB) const void Socket::write(const std::string &_msg, bool *_errorNB) const { - const auto written = low_write(::write, sockfd, _msg); + const auto written = low_write(::write, _msg); const auto currErrno = errno; if (written == -1) { @@ -184,7 +184,7 @@ void Socket::send(const std::string &_msg, SF::send _flags, bool *_errorNB) const { const auto flags = static_cast(_flags); - const auto sent = low_write(::send, sockfd, _msg, flags); + const auto sent = low_write(::send, _msg, flags); const auto currErrno = errno; if (sent == -1) { @@ -206,7 +206,7 @@ std::string Socket::read(const int _bufSize, bool *_errorNB) const std::string str; str.reserve(_bufSize); - const auto recvd = low_read(::read, sockfd, str); + const auto recvd = low_read(::read, str); const auto currErrno = errno; if (recvd == -1) { @@ -232,7 +232,7 @@ std::string Socket::recv(const int _bufSize, SF::recv _flags, str.reserve(_bufSize); const auto flags = static_cast(_flags); - const auto recvd = low_read(::recv, sockfd, str, flags); + const auto recvd = low_read(::recv, str, flags); const auto currErrno = errno; if (recvd == -1) {