Loading src/socket.h +6 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,8 @@ namespace netplus { virtual void accept(std::unique_ptr<socket> &csock)=0; #ifdef Windows virtual void accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket> &csock)=0; virtual size_t sendDataWSA(buffer &data, int flags = 0)=0; virtual size_t recvDataWSA(buffer &data, int flags = 0)=0; #endif virtual void bind()=0; virtual void listen()=0; Loading Loading @@ -145,6 +147,8 @@ namespace netplus { ~tcp(); #ifdef Windows void accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket> &csock); size_t sendDataWSA(buffer &data, int flags = 0); // Renamed from sendData size_t recvDataWSA(buffer &data, int flags = 0); // Renamed from recvData #endif void accept(std::unique_ptr <socket> &csock); void bind(); Loading Loading @@ -179,6 +183,8 @@ namespace netplus { void accept(std::unique_ptr<socket> &csock); #ifdef Windows void accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket> &csock); size_t sendDataWSA(buffer &data, int flags = 0); // Renamed from sendData size_t recvDataWSA(buffer &data, int flags = 0); // Renamed from recvData #endif void bind(); void listen(); Loading src/windows/tcp.cpp +33 −0 Original line number Diff line number Diff line Loading @@ -364,3 +364,36 @@ void netplus::tcp::getAddress(std::string& addr) { addr = "Invalid address"; // Handle errors from inet_ntop } } // tcp.cpp size_t netplus::tcp::sendDataWSA(buffer& data, int flags) { NetException exception; _wsaBuf.buf = data.ptr ? (char*)data.data.ptr : data.data.buf; _wsaBuf.len = static_cast<ULONG>(data.size); DWORD dwBytes = 0; // Note: We do not reset _Overlapped here because it is managed by the IOCP context int rval = ::WSASend(_Socket, &_wsaBuf, 1, &dwBytes, flags, &_Overlapped, nullptr); if (rval == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING) { exception[NetException::Error] << "WSASend failed: " << GetLastError(); throw exception; } return (size_t)dwBytes; } size_t netplus::tcp::recvDataWSA(buffer& data, int flags) { NetException exception; _wsaBuf.buf = data.data.buf; _wsaBuf.len = static_cast<ULONG>(data.size); DWORD dwBytes = 0; DWORD dwFlags = (DWORD)flags; int rval = ::WSARecv(_Socket, &_wsaBuf, 1, &dwBytes, &dwFlags, &_Overlapped, nullptr); if (rval == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING) { exception[NetException::Error] << "WSARecv failed: " << GetLastError(); throw exception; } return (size_t)dwBytes; } src/windows/udp.cpp +43 −0 Original line number Diff line number Diff line Loading @@ -362,3 +362,46 @@ void netplus::udp::getAddress(std::string& addr) { addr = "Invalid address"; // Handle errors from inet_ntop } } size_t netplus::udp::sendDataWSA(buffer& data, int flags) { NetException exception; // Assign buffer pointers to the Windows-specific WSABUF _wsaBuf.buf = data.ptr ? (char*)data.data.ptr : data.data.buf; _wsaBuf.len = static_cast<ULONG>(data.size); DWORD dwBytes = 0; // Initiate the overlapped send operation int rval = ::WSASend(_Socket, &_wsaBuf, 1, &dwBytes, flags, &_Overlapped, nullptr); if (rval == SOCKET_ERROR) { int lastError = WSAGetLastError(); if (lastError != WSA_IO_PENDING) { exception[NetException::Error] << "UDP WSASend failed: " << lastError; throw exception; } } return (size_t)dwBytes; } size_t netplus::udp::recvDataWSA(buffer& data, int flags) { NetException exception; _wsaBuf.buf = data.data.buf; _wsaBuf.len = static_cast<ULONG>(data.size); DWORD dwBytes = 0; DWORD dwFlags = (DWORD)flags; // Initiate the overlapped receive operation int rval = ::WSARecv(_Socket, &_wsaBuf, 1, &dwBytes, &dwFlags, &_Overlapped, nullptr); if (rval == SOCKET_ERROR) { int lastError = WSAGetLastError(); if (lastError != WSA_IO_PENDING) { exception[NetException::Error] << "UDP WSARecv failed: " << lastError; throw exception; } } return (size_t)dwBytes; } Loading
src/socket.h +6 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,8 @@ namespace netplus { virtual void accept(std::unique_ptr<socket> &csock)=0; #ifdef Windows virtual void accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket> &csock)=0; virtual size_t sendDataWSA(buffer &data, int flags = 0)=0; virtual size_t recvDataWSA(buffer &data, int flags = 0)=0; #endif virtual void bind()=0; virtual void listen()=0; Loading Loading @@ -145,6 +147,8 @@ namespace netplus { ~tcp(); #ifdef Windows void accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket> &csock); size_t sendDataWSA(buffer &data, int flags = 0); // Renamed from sendData size_t recvDataWSA(buffer &data, int flags = 0); // Renamed from recvData #endif void accept(std::unique_ptr <socket> &csock); void bind(); Loading Loading @@ -179,6 +183,8 @@ namespace netplus { void accept(std::unique_ptr<socket> &csock); #ifdef Windows void accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket> &csock); size_t sendDataWSA(buffer &data, int flags = 0); // Renamed from sendData size_t recvDataWSA(buffer &data, int flags = 0); // Renamed from recvData #endif void bind(); void listen(); Loading
src/windows/tcp.cpp +33 −0 Original line number Diff line number Diff line Loading @@ -364,3 +364,36 @@ void netplus::tcp::getAddress(std::string& addr) { addr = "Invalid address"; // Handle errors from inet_ntop } } // tcp.cpp size_t netplus::tcp::sendDataWSA(buffer& data, int flags) { NetException exception; _wsaBuf.buf = data.ptr ? (char*)data.data.ptr : data.data.buf; _wsaBuf.len = static_cast<ULONG>(data.size); DWORD dwBytes = 0; // Note: We do not reset _Overlapped here because it is managed by the IOCP context int rval = ::WSASend(_Socket, &_wsaBuf, 1, &dwBytes, flags, &_Overlapped, nullptr); if (rval == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING) { exception[NetException::Error] << "WSASend failed: " << GetLastError(); throw exception; } return (size_t)dwBytes; } size_t netplus::tcp::recvDataWSA(buffer& data, int flags) { NetException exception; _wsaBuf.buf = data.data.buf; _wsaBuf.len = static_cast<ULONG>(data.size); DWORD dwBytes = 0; DWORD dwFlags = (DWORD)flags; int rval = ::WSARecv(_Socket, &_wsaBuf, 1, &dwBytes, &dwFlags, &_Overlapped, nullptr); if (rval == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING) { exception[NetException::Error] << "WSARecv failed: " << GetLastError(); throw exception; } return (size_t)dwBytes; }
src/windows/udp.cpp +43 −0 Original line number Diff line number Diff line Loading @@ -362,3 +362,46 @@ void netplus::udp::getAddress(std::string& addr) { addr = "Invalid address"; // Handle errors from inet_ntop } } size_t netplus::udp::sendDataWSA(buffer& data, int flags) { NetException exception; // Assign buffer pointers to the Windows-specific WSABUF _wsaBuf.buf = data.ptr ? (char*)data.data.ptr : data.data.buf; _wsaBuf.len = static_cast<ULONG>(data.size); DWORD dwBytes = 0; // Initiate the overlapped send operation int rval = ::WSASend(_Socket, &_wsaBuf, 1, &dwBytes, flags, &_Overlapped, nullptr); if (rval == SOCKET_ERROR) { int lastError = WSAGetLastError(); if (lastError != WSA_IO_PENDING) { exception[NetException::Error] << "UDP WSASend failed: " << lastError; throw exception; } } return (size_t)dwBytes; } size_t netplus::udp::recvDataWSA(buffer& data, int flags) { NetException exception; _wsaBuf.buf = data.data.buf; _wsaBuf.len = static_cast<ULONG>(data.size); DWORD dwBytes = 0; DWORD dwFlags = (DWORD)flags; // Initiate the overlapped receive operation int rval = ::WSARecv(_Socket, &_wsaBuf, 1, &dwBytes, &dwFlags, &_Overlapped, nullptr); if (rval == SOCKET_ERROR) { int lastError = WSAGetLastError(); if (lastError != WSA_IO_PENDING) { exception[NetException::Error] << "UDP WSARecv failed: " << lastError; throw exception; } } return (size_t)dwBytes; }