Loading src/posix/udp.cpp +1 −2 Changes for src/posix/udp.cpp: 1 added line, 2 removed lines. Original line number Diff line number Diff line Loading @@ -182,8 +182,7 @@ void udp::accept(std::unique_ptr<socket>& csock, bool nonblock) { size_t udp::sendData(buffer& data, int flags) { const char* p = data.ptr ? data.data.ptr : data.data.buf; ssize_t s = ::sendto(_Socket, p, data.size, flags, reinterpret_cast<sockaddr*>(&_Addr), _AddrLen); ssize_t s = ::send(_Socket, p, data.size, flags); if (s < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { Loading src/windows/udp.cpp +7 −27 Changes for src/windows/udp.cpp: 7 added lines, 27 removed lines. Original line number Diff line number Diff line Loading @@ -129,41 +129,21 @@ void udp::accept(std::unique_ptr<socket>& csock, bool nonblock) { } size_t udp::sendData(buffer& data, int flags) { // Copy data to _SendBuffer for async WSASend size_t sendlen = data.size; if (!_SendBuffer) { _SendBuffer = std::make_unique<buffer>(sendlen); } if (_SendBuffer->size < sendlen) { _SendBuffer = std::make_unique<buffer>(sendlen); } std::memcpy(_SendBuffer->data.buf, data.data.buf, sendlen); _SendBuffer->data.len = (ULONG)sendlen; std::memset(&_SendBuffer->overlapped, 0, sizeof(WSAOVERLAPPED)); _SendBuffer->operation = OP_WRITE; _pendingIocpWrite.store(true); DWORD bytesSent = 0; int ret = ::WSASend(_Socket, &_SendBuffer->data, 1, &bytesSent, flags, &_SendBuffer->overlapped, nullptr); int ret = ::send(_Socket, data.data.buf, (int)data.size, flags); if (ret == SOCKET_ERROR) { int err = ::WSAGetLastError(); if (err == WSA_IO_PENDING) { // Async operation started - completion will come via IOCP return sendlen; if (err == WSAEWOULDBLOCK) { NetException e; e[NetException::Note] << "udp::sendData would block"; throw e; } _pendingIocpWrite.store(false); NetException e; e[NetException::Error] << "udp::sendData WSASend failed: " << err; e[NetException::Error] << "udp::sendData failed: " << err; throw e; } // Completed synchronously - IOCP still gets completion notification return sendlen; return (size_t)ret; } size_t udp::recvData(buffer& data, int flags) { Loading Loading
src/posix/udp.cpp +1 −2 Changes for src/posix/udp.cpp: 1 added line, 2 removed lines. Original line number Diff line number Diff line Loading @@ -182,8 +182,7 @@ void udp::accept(std::unique_ptr<socket>& csock, bool nonblock) { size_t udp::sendData(buffer& data, int flags) { const char* p = data.ptr ? data.data.ptr : data.data.buf; ssize_t s = ::sendto(_Socket, p, data.size, flags, reinterpret_cast<sockaddr*>(&_Addr), _AddrLen); ssize_t s = ::send(_Socket, p, data.size, flags); if (s < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { Loading
src/windows/udp.cpp +7 −27 Changes for src/windows/udp.cpp: 7 added lines, 27 removed lines. Original line number Diff line number Diff line Loading @@ -129,41 +129,21 @@ void udp::accept(std::unique_ptr<socket>& csock, bool nonblock) { } size_t udp::sendData(buffer& data, int flags) { // Copy data to _SendBuffer for async WSASend size_t sendlen = data.size; if (!_SendBuffer) { _SendBuffer = std::make_unique<buffer>(sendlen); } if (_SendBuffer->size < sendlen) { _SendBuffer = std::make_unique<buffer>(sendlen); } std::memcpy(_SendBuffer->data.buf, data.data.buf, sendlen); _SendBuffer->data.len = (ULONG)sendlen; std::memset(&_SendBuffer->overlapped, 0, sizeof(WSAOVERLAPPED)); _SendBuffer->operation = OP_WRITE; _pendingIocpWrite.store(true); DWORD bytesSent = 0; int ret = ::WSASend(_Socket, &_SendBuffer->data, 1, &bytesSent, flags, &_SendBuffer->overlapped, nullptr); int ret = ::send(_Socket, data.data.buf, (int)data.size, flags); if (ret == SOCKET_ERROR) { int err = ::WSAGetLastError(); if (err == WSA_IO_PENDING) { // Async operation started - completion will come via IOCP return sendlen; if (err == WSAEWOULDBLOCK) { NetException e; e[NetException::Note] << "udp::sendData would block"; throw e; } _pendingIocpWrite.store(false); NetException e; e[NetException::Error] << "udp::sendData WSASend failed: " << err; e[NetException::Error] << "udp::sendData failed: " << err; throw e; } // Completed synchronously - IOCP still gets completion notification return sendlen; return (size_t)ret; } size_t udp::recvData(buffer& data, int flags) { Loading