Loading src/event/iocp.cpp +6 −1 Changes for src/event/iocp.cpp: 6 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -110,8 +110,13 @@ namespace netplus { void AcceptConnection(LPFN_ACCEPTEX lpfnAcceptEx, int tid, ULONG_PTR args) { client* pClientContext = new client(g_eventapi); if (g_serversocket->_Type == TCP) if (g_serversocket->_Type == TCP) { pClientContext->CurCon->csock = std::make_unique<tcp>(); } else { NetException exp; exp[NetException::Error] << "Wrong Protocol only tcp supported at the moment !"; throw exp; } try { g_serversocket->accept(lpfnAcceptEx, pClientContext->CurCon->csock); Loading src/socket.h +3 Changes for src/socket.h: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -129,7 +129,10 @@ namespace netplus { public: tcp(); tcp(SOCKET sock); tcp(const netplus::tcp& ctcp) = delete; tcp& operator=(const tcp& socket) = delete; tcp(const std::string &uxsocket,int maxconnections, int sockopts); tcp(const std::string &addr,int port,int maxconnections, Loading src/windows/tcp.cpp +42 −14 Changes for src/windows/tcp.cpp: 42 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <iostream> #include <chrono> #include <thread> #include <vector> Loading Loading @@ -62,17 +62,17 @@ netplus::tcp::tcp(const std::string &addr, int port,int maxconnections,int socko hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; hints.ai_protocol = 0; hints.ai_protocol = IPPROTO_TCP; hints.ai_canonname = NULL; hints.ai_addr = NULL; hints.ai_next = NULL; int tsock; char serv[512]; char serv[512] = {'\0'}; snprintf(serv,512,"%d",port); if ((tsock=::getaddrinfo(addr.c_str(), serv,&hints,&result)) < 0) { if ((tsock=::getaddrinfo(addr.c_str(), serv,&hints,&result)) != 0 ) { exception[NetException::Critical] << "Socket Invalid address/ Address not supported"; throw exception; } Loading @@ -80,21 +80,32 @@ netplus::tcp::tcp(const std::string &addr, int port,int maxconnections,int socko for (rp = result; rp != nullptr; rp = rp->ai_next) { _Socket = ::WSASocketW(rp->ai_family, rp->ai_socktype, rp->ai_protocol,nullptr, 0, sockopts); if (_Socket == -1) if (_Socket == INVALID_SOCKET) continue; break; } _SocketInfoLen = sizeof(hints); copyAddrInfo(&_SocketInfo, (ULONG_PTR)rp,sizeof(hints)); if (_Socket == INVALID_SOCKET) { ::freeaddrinfo(result); exception[NetException::Critical] << "Create Socket " << (int)_Socket << " failed : " << GetLastError(); throw exception; } if (rp != nullptr) { _SocketInfoLen = rp->ai_addrlen; copyAddrInfo(&_SocketInfo, (ULONG_PTR)rp->ai_addr, rp->ai_addrlen); } ::freeaddrinfo(result); _SocketInfoLen = sizeof(hints); _Type=sockettype::TCP; } netplus::tcp::~tcp(){ int one = 1; if (_Socket!=-1) if (_Socket!=INVALID_SOCKET) ::closesocket(_Socket); } Loading Loading @@ -331,10 +342,27 @@ void netplus::tcp::connect(std::unique_ptr<socket> &csock){ void netplus::tcp::getAddress(std::string& addr) { char buf[512]; char buf[INET6_ADDRSTRLEN]; // Use INET6_ADDRSTRLEN for IPv6 support const void* src = nullptr; if (((struct addrinfo*)_SocketInfo)->ai_family == AF_INET) { struct sockaddr_in* ipv4 = (struct sockaddr_in*)((struct addrinfo*)_SocketInfo)->ai_addr; src = &(ipv4->sin_addr); } else if (((struct addrinfo*)_SocketInfo)->ai_family == AF_INET6) { struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)((struct addrinfo*)_SocketInfo)->ai_addr; src = &(ipv6->sin6_addr); } else { // Unsupported address family addr = "Unsupported address family"; return; } addr = inet_ntop(((struct addrinfo*)_SocketInfo)->ai_family, &((struct addrinfo*)_SocketInfo)->ai_addr->sa_data + sizeof(struct sockaddr_storage), buf, ((struct addrinfo*)_SocketInfo)->ai_addrlen ); if (src != nullptr && inet_ntop(((struct addrinfo*)_SocketInfo)->ai_family, src, buf, sizeof(buf)) != nullptr) { addr = buf; } else { addr = "Invalid address"; // Handle errors from inet_ntop } } src/windows/udp.cpp +23 −6 Changes for src/windows/udp.cpp: 23 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ netplus::udp::udp(const std::string &addr, int port, int maxconnections, int soc hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_PASSIVE; hints.ai_protocol = 0; hints.ai_protocol = IPPROTO_UDP; hints.ai_canonname = NULL; hints.ai_addr = NULL; hints.ai_next = NULL; Loading Loading @@ -328,10 +328,27 @@ void netplus::udp::connect(std::unique_ptr<socket> &csock) { void netplus::udp::getAddress(std::string& addr) { char buf[512]; char buf[INET6_ADDRSTRLEN]; // Use INET6_ADDRSTRLEN for IPv6 support const void* src = nullptr; addr = inet_ntop(((struct addrinfo*)_SocketInfo)->ai_family, &((struct addrinfo*)_SocketInfo)->ai_addr->sa_data + sizeof(struct sockaddr_storage), buf, ((struct addrinfo*)_SocketInfo)->ai_addrlen ); if (((struct addrinfo*)_SocketInfo)->ai_family == AF_INET) { struct sockaddr_in* ipv4 = (struct sockaddr_in*)((struct addrinfo*)_SocketInfo)->ai_addr; src = &(ipv4->sin_addr); } else if (((struct addrinfo*)_SocketInfo)->ai_family == AF_INET6) { struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)((struct addrinfo*)_SocketInfo)->ai_addr; src = &(ipv6->sin6_addr); } else { // Unsupported address family addr = "Unsupported address family"; return; } if (src != nullptr && inet_ntop(((struct addrinfo*)_SocketInfo)->ai_family, src, buf, sizeof(buf)) != nullptr) { addr = buf; } else { addr = "Invalid address"; // Handle errors from inet_ntop } } Loading
src/event/iocp.cpp +6 −1 Changes for src/event/iocp.cpp: 6 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -110,8 +110,13 @@ namespace netplus { void AcceptConnection(LPFN_ACCEPTEX lpfnAcceptEx, int tid, ULONG_PTR args) { client* pClientContext = new client(g_eventapi); if (g_serversocket->_Type == TCP) if (g_serversocket->_Type == TCP) { pClientContext->CurCon->csock = std::make_unique<tcp>(); } else { NetException exp; exp[NetException::Error] << "Wrong Protocol only tcp supported at the moment !"; throw exp; } try { g_serversocket->accept(lpfnAcceptEx, pClientContext->CurCon->csock); Loading
src/socket.h +3 Changes for src/socket.h: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -129,7 +129,10 @@ namespace netplus { public: tcp(); tcp(SOCKET sock); tcp(const netplus::tcp& ctcp) = delete; tcp& operator=(const tcp& socket) = delete; tcp(const std::string &uxsocket,int maxconnections, int sockopts); tcp(const std::string &addr,int port,int maxconnections, Loading
src/windows/tcp.cpp +42 −14 Changes for src/windows/tcp.cpp: 42 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <iostream> #include <chrono> #include <thread> #include <vector> Loading Loading @@ -62,17 +62,17 @@ netplus::tcp::tcp(const std::string &addr, int port,int maxconnections,int socko hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; hints.ai_protocol = 0; hints.ai_protocol = IPPROTO_TCP; hints.ai_canonname = NULL; hints.ai_addr = NULL; hints.ai_next = NULL; int tsock; char serv[512]; char serv[512] = {'\0'}; snprintf(serv,512,"%d",port); if ((tsock=::getaddrinfo(addr.c_str(), serv,&hints,&result)) < 0) { if ((tsock=::getaddrinfo(addr.c_str(), serv,&hints,&result)) != 0 ) { exception[NetException::Critical] << "Socket Invalid address/ Address not supported"; throw exception; } Loading @@ -80,21 +80,32 @@ netplus::tcp::tcp(const std::string &addr, int port,int maxconnections,int socko for (rp = result; rp != nullptr; rp = rp->ai_next) { _Socket = ::WSASocketW(rp->ai_family, rp->ai_socktype, rp->ai_protocol,nullptr, 0, sockopts); if (_Socket == -1) if (_Socket == INVALID_SOCKET) continue; break; } _SocketInfoLen = sizeof(hints); copyAddrInfo(&_SocketInfo, (ULONG_PTR)rp,sizeof(hints)); if (_Socket == INVALID_SOCKET) { ::freeaddrinfo(result); exception[NetException::Critical] << "Create Socket " << (int)_Socket << " failed : " << GetLastError(); throw exception; } if (rp != nullptr) { _SocketInfoLen = rp->ai_addrlen; copyAddrInfo(&_SocketInfo, (ULONG_PTR)rp->ai_addr, rp->ai_addrlen); } ::freeaddrinfo(result); _SocketInfoLen = sizeof(hints); _Type=sockettype::TCP; } netplus::tcp::~tcp(){ int one = 1; if (_Socket!=-1) if (_Socket!=INVALID_SOCKET) ::closesocket(_Socket); } Loading Loading @@ -331,10 +342,27 @@ void netplus::tcp::connect(std::unique_ptr<socket> &csock){ void netplus::tcp::getAddress(std::string& addr) { char buf[512]; char buf[INET6_ADDRSTRLEN]; // Use INET6_ADDRSTRLEN for IPv6 support const void* src = nullptr; if (((struct addrinfo*)_SocketInfo)->ai_family == AF_INET) { struct sockaddr_in* ipv4 = (struct sockaddr_in*)((struct addrinfo*)_SocketInfo)->ai_addr; src = &(ipv4->sin_addr); } else if (((struct addrinfo*)_SocketInfo)->ai_family == AF_INET6) { struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)((struct addrinfo*)_SocketInfo)->ai_addr; src = &(ipv6->sin6_addr); } else { // Unsupported address family addr = "Unsupported address family"; return; } addr = inet_ntop(((struct addrinfo*)_SocketInfo)->ai_family, &((struct addrinfo*)_SocketInfo)->ai_addr->sa_data + sizeof(struct sockaddr_storage), buf, ((struct addrinfo*)_SocketInfo)->ai_addrlen ); if (src != nullptr && inet_ntop(((struct addrinfo*)_SocketInfo)->ai_family, src, buf, sizeof(buf)) != nullptr) { addr = buf; } else { addr = "Invalid address"; // Handle errors from inet_ntop } }
src/windows/udp.cpp +23 −6 Changes for src/windows/udp.cpp: 23 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ netplus::udp::udp(const std::string &addr, int port, int maxconnections, int soc hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_PASSIVE; hints.ai_protocol = 0; hints.ai_protocol = IPPROTO_UDP; hints.ai_canonname = NULL; hints.ai_addr = NULL; hints.ai_next = NULL; Loading Loading @@ -328,10 +328,27 @@ void netplus::udp::connect(std::unique_ptr<socket> &csock) { void netplus::udp::getAddress(std::string& addr) { char buf[512]; char buf[INET6_ADDRSTRLEN]; // Use INET6_ADDRSTRLEN for IPv6 support const void* src = nullptr; addr = inet_ntop(((struct addrinfo*)_SocketInfo)->ai_family, &((struct addrinfo*)_SocketInfo)->ai_addr->sa_data + sizeof(struct sockaddr_storage), buf, ((struct addrinfo*)_SocketInfo)->ai_addrlen ); if (((struct addrinfo*)_SocketInfo)->ai_family == AF_INET) { struct sockaddr_in* ipv4 = (struct sockaddr_in*)((struct addrinfo*)_SocketInfo)->ai_addr; src = &(ipv4->sin_addr); } else if (((struct addrinfo*)_SocketInfo)->ai_family == AF_INET6) { struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)((struct addrinfo*)_SocketInfo)->ai_addr; src = &(ipv6->sin6_addr); } else { // Unsupported address family addr = "Unsupported address family"; return; } if (src != nullptr && inet_ntop(((struct addrinfo*)_SocketInfo)->ai_family, src, buf, sizeof(buf)) != nullptr) { addr = buf; } else { addr = "Invalid address"; // Handle errors from inet_ntop } }