Loading src/posix/tcp.cpp +0 −1 Original line number Diff line number Diff line Loading @@ -400,7 +400,6 @@ void tcp::connectTimeout(const std::string& addr, int port, int timeout_ms) { } } void tcp::getAddress(std::string& addr) { char buf[INET6_ADDRSTRLEN]{}; Loading src/posix/udp.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "socket.h" #include "exception.h" #include "error.h" #include "eventapi.h" #include <cstdio> #include <cstring> Loading Loading @@ -320,6 +321,33 @@ void netplus::udp::connect(const std::string& addr, int port,bool ){ throw exception; } void udp::connectTimeout(const std::string& addr, int port, int timeout_ms) { try { connect(addr, port, true); return; // connected immediately } catch (NetException &e) { if (e.getErrorType() != NetException::Note) throw; } netplus::socketwait sw; if (!sw.waitWrite(*this, timeout_ms)) { NetException ne; ne[NetException::Error] << "udp::connectTimeout: timed out connecting to " << addr << ":" << port; throw ne; } int err = 0; socklen_t errlen = sizeof(err); if (::getsockopt(fd(), SOL_SOCKET, SO_ERROR, &err, &errlen) != 0 || err != 0) { NetException ne; ne[NetException::Error] << "udp::connectTimeout: could not connect to " << addr << ":" << port << " (" << strerror(err) << ")"; throw ne; } } void udp::getAddress(std::string& addr) { char buf[INET6_ADDRSTRLEN]{}; sockaddr* sa = reinterpret_cast<sockaddr*>(&_Addr); Loading src/socket.h +10 −7 Original line number Diff line number Diff line Loading @@ -213,6 +213,14 @@ namespace netplus { virtual void pushReceivedData(const uint8_t* data, size_t len) { (void)data; (void)len; } virtual void connect(const std::string& addr, int port, bool nonblock = false) = 0; // Non-blocking connect bounded by timeout_ms, instead of the OS // default (which can be minutes) or blocking forever -- for callers // that need a configurable ceiling on how long an unreachable host // (dead service, wrong address, dropped SYNs) can stall them. // Throws NetException on failure or timeout; returns once connected. virtual void connectTimeout(const std::string& addr, int port, int timeout_ms) = 0; virtual void getAddress(std::string& addr) = 0; SOCKET fd(); Loading Loading @@ -296,13 +304,7 @@ namespace netplus { size_t recvData(buffer& data, int flags = 0) override; void connect(const std::string& addr, int port, bool nonblock = false) override; // Non-blocking connect bounded by timeout_ms, instead of the OS // default (which can be minutes) or blocking forever -- for callers // that need a configurable ceiling on how long an unreachable host // (dead service, wrong address, dropped SYNs) can stall them. // Throws NetException on failure or timeout; returns once connected. void connectTimeout(const std::string& addr, int port, int timeout_ms); void connectTimeout(const std::string& addr, int port, int timeout_ms) override; void getAddress(std::string& addr) override; Loading Loading @@ -344,6 +346,7 @@ namespace netplus { size_t sendTo(buffer& data, int flags = 0); void connect(const std::string& addr, int port, bool nonblock = false) override; void connectTimeout(const std::string& addr, int port, int timeout_ms) override; void getAddress(std::string& addr) override; // ---- UDP GSO/GRO + batched I/O (Linux kernel offload) ---- Loading src/windows/tcp.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "socket.h" #include "exception.h" #include "eventapi.h" #include <ws2tcpip.h> #include <cstring> Loading Loading @@ -400,6 +401,33 @@ void netplus::tcp::connect(const std::string& addr, int port, bool nonblock) throw exception; } void tcp::connectTimeout(const std::string& addr, int port, int timeout_ms) { try { connect(addr, port, true); return; // connected immediately } catch (NetException &e) { if (e.getErrorType() != NetException::Note) throw; } netplus::socketwait sw; if (!sw.waitWrite(*this, timeout_ms)) { NetException ne; ne[NetException::Error] << "tcp::connectTimeout: timed out connecting to " << addr << ":" << port; throw ne; } int err = 0; int errlen = sizeof(err); if (::getsockopt(fd(), SOL_SOCKET, SO_ERROR, (char*)&err, &errlen) != 0 || err != 0) { NetException ne; ne[NetException::Error] << "tcp::connectTimeout: could not connect to " << addr << ":" << port << " (" << err << ")"; throw ne; } } void tcp::setBlock() { u_long mode = 0; if (::ioctlsocket(_Socket, FIONBIO, &mode) == SOCKET_ERROR) { Loading src/windows/udp.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "socket.h" #include "exception.h" #include "eventapi.h" #include <ws2tcpip.h> #include <cstring> Loading Loading @@ -383,6 +384,33 @@ void udp::connect(const std::string& addr, int port, bool nonblock) throw exception; } void udp::connectTimeout(const std::string& addr, int port, int timeout_ms) { try { connect(addr, port, true); return; // connected immediately } catch (NetException &e) { if (e.getErrorType() != NetException::Note) throw; } netplus::socketwait sw; if (!sw.waitWrite(*this, timeout_ms)) { NetException ne; ne[NetException::Error] << "udp::connectTimeout: timed out connecting to " << addr << ":" << port; throw ne; } int err = 0; int errlen = sizeof(err); if (::getsockopt(fd(), SOL_SOCKET, SO_ERROR, (char*)&err, &errlen) != 0 || err != 0) { NetException ne; ne[NetException::Error] << "udp::connectTimeout: could not connect to " << addr << ":" << port << " (" << err << ")"; throw ne; } } void udp::getAddress(std::string& addr) { char buf[INET6_ADDRSTRLEN]{}; Loading Loading
src/posix/tcp.cpp +0 −1 Original line number Diff line number Diff line Loading @@ -400,7 +400,6 @@ void tcp::connectTimeout(const std::string& addr, int port, int timeout_ms) { } } void tcp::getAddress(std::string& addr) { char buf[INET6_ADDRSTRLEN]{}; Loading
src/posix/udp.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "socket.h" #include "exception.h" #include "error.h" #include "eventapi.h" #include <cstdio> #include <cstring> Loading Loading @@ -320,6 +321,33 @@ void netplus::udp::connect(const std::string& addr, int port,bool ){ throw exception; } void udp::connectTimeout(const std::string& addr, int port, int timeout_ms) { try { connect(addr, port, true); return; // connected immediately } catch (NetException &e) { if (e.getErrorType() != NetException::Note) throw; } netplus::socketwait sw; if (!sw.waitWrite(*this, timeout_ms)) { NetException ne; ne[NetException::Error] << "udp::connectTimeout: timed out connecting to " << addr << ":" << port; throw ne; } int err = 0; socklen_t errlen = sizeof(err); if (::getsockopt(fd(), SOL_SOCKET, SO_ERROR, &err, &errlen) != 0 || err != 0) { NetException ne; ne[NetException::Error] << "udp::connectTimeout: could not connect to " << addr << ":" << port << " (" << strerror(err) << ")"; throw ne; } } void udp::getAddress(std::string& addr) { char buf[INET6_ADDRSTRLEN]{}; sockaddr* sa = reinterpret_cast<sockaddr*>(&_Addr); Loading
src/socket.h +10 −7 Original line number Diff line number Diff line Loading @@ -213,6 +213,14 @@ namespace netplus { virtual void pushReceivedData(const uint8_t* data, size_t len) { (void)data; (void)len; } virtual void connect(const std::string& addr, int port, bool nonblock = false) = 0; // Non-blocking connect bounded by timeout_ms, instead of the OS // default (which can be minutes) or blocking forever -- for callers // that need a configurable ceiling on how long an unreachable host // (dead service, wrong address, dropped SYNs) can stall them. // Throws NetException on failure or timeout; returns once connected. virtual void connectTimeout(const std::string& addr, int port, int timeout_ms) = 0; virtual void getAddress(std::string& addr) = 0; SOCKET fd(); Loading Loading @@ -296,13 +304,7 @@ namespace netplus { size_t recvData(buffer& data, int flags = 0) override; void connect(const std::string& addr, int port, bool nonblock = false) override; // Non-blocking connect bounded by timeout_ms, instead of the OS // default (which can be minutes) or blocking forever -- for callers // that need a configurable ceiling on how long an unreachable host // (dead service, wrong address, dropped SYNs) can stall them. // Throws NetException on failure or timeout; returns once connected. void connectTimeout(const std::string& addr, int port, int timeout_ms); void connectTimeout(const std::string& addr, int port, int timeout_ms) override; void getAddress(std::string& addr) override; Loading Loading @@ -344,6 +346,7 @@ namespace netplus { size_t sendTo(buffer& data, int flags = 0); void connect(const std::string& addr, int port, bool nonblock = false) override; void connectTimeout(const std::string& addr, int port, int timeout_ms) override; void getAddress(std::string& addr) override; // ---- UDP GSO/GRO + batched I/O (Linux kernel offload) ---- Loading
src/windows/tcp.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "socket.h" #include "exception.h" #include "eventapi.h" #include <ws2tcpip.h> #include <cstring> Loading Loading @@ -400,6 +401,33 @@ void netplus::tcp::connect(const std::string& addr, int port, bool nonblock) throw exception; } void tcp::connectTimeout(const std::string& addr, int port, int timeout_ms) { try { connect(addr, port, true); return; // connected immediately } catch (NetException &e) { if (e.getErrorType() != NetException::Note) throw; } netplus::socketwait sw; if (!sw.waitWrite(*this, timeout_ms)) { NetException ne; ne[NetException::Error] << "tcp::connectTimeout: timed out connecting to " << addr << ":" << port; throw ne; } int err = 0; int errlen = sizeof(err); if (::getsockopt(fd(), SOL_SOCKET, SO_ERROR, (char*)&err, &errlen) != 0 || err != 0) { NetException ne; ne[NetException::Error] << "tcp::connectTimeout: could not connect to " << addr << ":" << port << " (" << err << ")"; throw ne; } } void tcp::setBlock() { u_long mode = 0; if (::ioctlsocket(_Socket, FIONBIO, &mode) == SOCKET_ERROR) { Loading
src/windows/udp.cpp +28 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "socket.h" #include "exception.h" #include "eventapi.h" #include <ws2tcpip.h> #include <cstring> Loading Loading @@ -383,6 +384,33 @@ void udp::connect(const std::string& addr, int port, bool nonblock) throw exception; } void udp::connectTimeout(const std::string& addr, int port, int timeout_ms) { try { connect(addr, port, true); return; // connected immediately } catch (NetException &e) { if (e.getErrorType() != NetException::Note) throw; } netplus::socketwait sw; if (!sw.waitWrite(*this, timeout_ms)) { NetException ne; ne[NetException::Error] << "udp::connectTimeout: timed out connecting to " << addr << ":" << port; throw ne; } int err = 0; int errlen = sizeof(err); if (::getsockopt(fd(), SOL_SOCKET, SO_ERROR, (char*)&err, &errlen) != 0 || err != 0) { NetException ne; ne[NetException::Error] << "udp::connectTimeout: could not connect to " << addr << ":" << port << " (" << err << ")"; throw ne; } } void udp::getAddress(std::string& addr) { char buf[INET6_ADDRSTRLEN]{}; Loading