Merge remote-tracking branch 'refs/remotes/origin/master' into enet_wip_nothing_to_see_here
This commit is contained in:
commit
f59b59da27
|
|
@ -29,7 +29,7 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
using BitField = typename std::conditional<(EnumAsFlags<E>::max > 32), UInt64, UInt32>::type;
|
using BitField = typename std::conditional<(EnumAsFlags<E>::max > 32), UInt64, UInt32>::type;
|
||||||
|
|
||||||
constexpr Flags(BitField value);
|
constexpr Flags(BitField value = 0);
|
||||||
constexpr Flags(E enumVal);
|
constexpr Flags(E enumVal);
|
||||||
|
|
||||||
explicit constexpr operator bool() const;
|
explicit constexpr operator bool() const;
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,13 @@ namespace Nz
|
||||||
* \brief Core class used to combine enumeration values into flags bitfield
|
* \brief Core class used to combine enumeration values into flags bitfield
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Constructs a Flags object using a bitfield
|
* \brief Constructs a Flags object using a bitfield
|
||||||
*
|
*
|
||||||
* \param value Bitfield to be used
|
* \param value Bitfield to be used
|
||||||
*
|
*
|
||||||
* Uses a bitfield to builds the flag value. (e.g. if bit 0 is active, then Enum value 0 will be set as active).
|
* Uses a bitfield to builds the flag value. (e.g. if bit 0 is active, then Enum value 0 will be set as active).
|
||||||
*/
|
*/
|
||||||
template<typename E>
|
template<typename E>
|
||||||
constexpr Flags<E>::Flags(BitField value) :
|
constexpr Flags<E>::Flags(BitField value) :
|
||||||
m_value(value)
|
m_value(value)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2017 Jérôme Leclercq
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Network module"
|
// This file is part of the "Nazara Engine - Network module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Network module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_NETBUFFER_HPP
|
||||||
|
#define NAZARA_NETBUFFER_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
struct NetBuffer
|
||||||
|
{
|
||||||
|
void* data;
|
||||||
|
std::size_t dataLength;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NAZARA_NETBUFFER_HPP
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include <Nazara/Core/Stream.hpp>
|
#include <Nazara/Core/Stream.hpp>
|
||||||
#include <Nazara/Network/AbstractSocket.hpp>
|
#include <Nazara/Network/AbstractSocket.hpp>
|
||||||
#include <Nazara/Network/IpAddress.hpp>
|
#include <Nazara/Network/IpAddress.hpp>
|
||||||
|
#include <Nazara/Network/NetBuffer.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
|
@ -49,6 +50,7 @@ namespace Nz
|
||||||
bool ReceivePacket(NetPacket* packet);
|
bool ReceivePacket(NetPacket* packet);
|
||||||
|
|
||||||
bool Send(const void* buffer, std::size_t size, std::size_t* sent);
|
bool Send(const void* buffer, std::size_t size, std::size_t* sent);
|
||||||
|
bool SendMultiple(const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent);
|
||||||
bool SendPacket(const NetPacket& packet);
|
bool SendPacket(const NetPacket& packet);
|
||||||
|
|
||||||
bool SetCursorPos(UInt64 offset) override;
|
bool SetCursorPos(UInt64 offset) override;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2017 Jérôme Leclercq
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Network module"
|
// This file is part of the "Nazara Engine - Network module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Network/AbstractSocket.hpp>
|
#include <Nazara/Network/AbstractSocket.hpp>
|
||||||
#include <Nazara/Network/IpAddress.hpp>
|
#include <Nazara/Network/IpAddress.hpp>
|
||||||
|
#include <Nazara/Network/NetBuffer.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
|
@ -42,6 +43,7 @@ namespace Nz
|
||||||
bool ReceivePacket(NetPacket* packet, IpAddress* from);
|
bool ReceivePacket(NetPacket* packet, IpAddress* from);
|
||||||
|
|
||||||
bool Send(const IpAddress& to, const void* buffer, std::size_t size, std::size_t* sent);
|
bool Send(const IpAddress& to, const void* buffer, std::size_t size, std::size_t* sent);
|
||||||
|
bool SendMultiple(const IpAddress& to, const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent);
|
||||||
bool SendPacket(const IpAddress& to, const NetPacket& packet);
|
bool SendPacket(const IpAddress& to, const NetPacket& packet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
@ -463,9 +464,11 @@ namespace Nz
|
||||||
if (byteRead == SOCKET_ERROR)
|
if (byteRead == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
int errorCode = GetLastErrorCode();
|
int errorCode = GetLastErrorCode();
|
||||||
|
if (errorCode == EAGAIN)
|
||||||
|
errorCode = EWOULDBLOCK;
|
||||||
|
|
||||||
switch (errorCode)
|
switch (errorCode)
|
||||||
{
|
{
|
||||||
case EAGAIN:
|
|
||||||
case EWOULDBLOCK:
|
case EWOULDBLOCK:
|
||||||
{
|
{
|
||||||
// If we have no data and are not blocking, return true with 0 byte read
|
// If we have no data and are not blocking, return true with 0 byte read
|
||||||
|
|
@ -513,6 +516,9 @@ namespace Nz
|
||||||
if (byteRead == SOCKET_ERROR)
|
if (byteRead == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
int errorCode = GetLastErrorCode();
|
int errorCode = GetLastErrorCode();
|
||||||
|
if (errorCode == EAGAIN)
|
||||||
|
errorCode = EWOULDBLOCK;
|
||||||
|
|
||||||
switch (errorCode)
|
switch (errorCode)
|
||||||
{
|
{
|
||||||
case EWOULDBLOCK:
|
case EWOULDBLOCK:
|
||||||
|
|
@ -562,10 +568,24 @@ namespace Nz
|
||||||
int byteSent = send(handle, reinterpret_cast<const char*>(buffer), length, 0);
|
int byteSent = send(handle, reinterpret_cast<const char*>(buffer), length, 0);
|
||||||
if (byteSent == SOCKET_ERROR)
|
if (byteSent == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
if (error)
|
int errorCode = GetLastErrorCode();
|
||||||
*error = TranslateErrnoToResolveError(GetLastErrorCode());
|
if (errorCode == EAGAIN)
|
||||||
|
errorCode = EWOULDBLOCK;
|
||||||
|
|
||||||
return false; //< Error
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case EWOULDBLOCK:
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
*error = TranslateErrnoToResolveError(errorCode);
|
||||||
|
|
||||||
|
return false; //< Error
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sent)
|
if (sent)
|
||||||
|
|
@ -577,6 +597,60 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SocketImpl::SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error)
|
||||||
|
{
|
||||||
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
NazaraAssert(buffers && bufferCount > 0, "Invalid buffers");
|
||||||
|
|
||||||
|
StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(iovec));
|
||||||
|
struct iovec* sysBuffers = static_cast<struct iovec*>(memory.GetPtr());
|
||||||
|
for (std::size_t i = 0; i < bufferCount; ++i)
|
||||||
|
{
|
||||||
|
sysBuffers[i].iov_base = buffers[i].data;
|
||||||
|
sysBuffers[i].iov_len = buffers[i].dataLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct msghdr header;
|
||||||
|
std::memset(&header, 0, sizeof(header);
|
||||||
|
|
||||||
|
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||||
|
header.msg_namelen = IpAddressImpl::ToSockAddr(to, nameBuffer.data());
|
||||||
|
header.msg_name = nameBuffer.data();
|
||||||
|
msgHdr.msg_iov = sysBuffers;
|
||||||
|
msgHdr.msg_iovlen = static_cast<int>(bufferCount);
|
||||||
|
|
||||||
|
int sentLength = sendmsg(socket, &msgHdr, MSG_NOSIGNAL);
|
||||||
|
if (byteSent == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
int errorCode = GetLastErrorCode();
|
||||||
|
if (errorCode == EAGAIN)
|
||||||
|
errorCode = EWOULDBLOCK;
|
||||||
|
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case EWOULDBLOCK:
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
*error = TranslateErrnoToResolveError(errorCode);
|
||||||
|
|
||||||
|
return false; //< Error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sent)
|
||||||
|
*sent = static_cast<int>(byteSent);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
*error = SocketError_NoError;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool SocketImpl::SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error)
|
bool SocketImpl::SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error)
|
||||||
{
|
{
|
||||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
|
@ -588,10 +662,24 @@ namespace Nz
|
||||||
int byteSent = sendto(handle, reinterpret_cast<const char*>(buffer), length, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength);
|
int byteSent = sendto(handle, reinterpret_cast<const char*>(buffer), length, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength);
|
||||||
if (byteSent == SOCKET_ERROR)
|
if (byteSent == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
if (error)
|
int errorCode = GetLastErrorCode();
|
||||||
*error = TranslateErrnoToResolveError(GetLastErrorCode());
|
if (errorCode == EAGAIN)
|
||||||
|
errorCode = EWOULDBLOCK;
|
||||||
|
|
||||||
return false; //< Error
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case EWOULDBLOCK:
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
*error = TranslateErrnoToResolveError(errorCode);
|
||||||
|
|
||||||
|
return false; //< Error
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sent)
|
if (sent)
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ namespace Nz
|
||||||
static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error);
|
static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error);
|
||||||
|
|
||||||
static bool Send(SocketHandle handle, const void* buffer, int length, int* sent, SocketError* error);
|
static bool Send(SocketHandle handle, const void* buffer, int length, int* sent, SocketError* error);
|
||||||
|
static bool SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error);
|
||||||
static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error);
|
static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error);
|
||||||
|
|
||||||
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
||||||
|
|
|
||||||
|
|
@ -353,6 +353,45 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sends multiple buffers at once
|
||||||
|
* \return true If data were sent
|
||||||
|
*
|
||||||
|
* \param buffers A pointer to an array of NetBuffer containing buffers and size data
|
||||||
|
* \param size Number of NetBuffer to send
|
||||||
|
* \param sent Optional argument to get the number of bytes sent
|
||||||
|
*/
|
||||||
|
bool TcpClient::SendMultiple(const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent)
|
||||||
|
{
|
||||||
|
NazaraAssert(buffers && bufferCount > 0, "Invalid buffer");
|
||||||
|
|
||||||
|
int byteSent;
|
||||||
|
if (!SocketImpl::SendMultiple(m_handle, buffers, bufferCount, m_peerAddress, &byteSent, &m_lastError))
|
||||||
|
{
|
||||||
|
switch (m_lastError)
|
||||||
|
{
|
||||||
|
case SocketError_ConnectionClosed:
|
||||||
|
case SocketError_ConnectionRefused:
|
||||||
|
UpdateState(SocketState_NotConnected);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sent)
|
||||||
|
*sent = byteSent;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sent)
|
||||||
|
*sent = byteSent;
|
||||||
|
|
||||||
|
UpdateState(SocketState_Connected);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Sends the packet available
|
* \brief Sends the packet available
|
||||||
* \return true If packet sent
|
* \return true If packet sent
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,18 @@ namespace Nz
|
||||||
|
|
||||||
int read;
|
int read;
|
||||||
if (!SocketImpl::ReceiveFrom(m_handle, buffer, static_cast<int>(size), from, &read, &m_lastError))
|
if (!SocketImpl::ReceiveFrom(m_handle, buffer, static_cast<int>(size), from, &read, &m_lastError))
|
||||||
return false;
|
{
|
||||||
|
switch (m_lastError)
|
||||||
|
{
|
||||||
|
case SocketError_ConnectionClosed:
|
||||||
|
m_lastError = SocketError_NoError;
|
||||||
|
read = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (received)
|
if (received)
|
||||||
*received = read;
|
*received = read;
|
||||||
|
|
@ -179,6 +190,31 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sends multiple buffers as one datagram
|
||||||
|
* \return true If data were sent
|
||||||
|
*
|
||||||
|
* \param to Destination IpAddress (must match socket protocol)
|
||||||
|
* \param buffers A pointer to an array of NetBuffer containing buffers and size data
|
||||||
|
* \param size Number of NetBuffer to send
|
||||||
|
* \param sent Optional argument to get the number of bytes sent
|
||||||
|
*/
|
||||||
|
bool UdpSocket::SendMultiple(const IpAddress& to, const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent)
|
||||||
|
{
|
||||||
|
NazaraAssert(to.IsValid(), "Invalid ip address");
|
||||||
|
NazaraAssert(to.GetProtocol() == m_protocol, "IP Address has a different protocol than the socket");
|
||||||
|
NazaraAssert(buffers && bufferCount > 0, "Invalid buffer");
|
||||||
|
|
||||||
|
int byteSent;
|
||||||
|
if (!SocketImpl::SendMultiple(m_handle, buffers, bufferCount, to, &byteSent, &m_lastError))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (sent)
|
||||||
|
*sent = byteSent;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Sends the packet available
|
* \brief Sends the packet available
|
||||||
* \return true If packet sent
|
* \return true If packet sent
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
// Copyright (C) 2017 Jérôme Leclercq
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Network module"
|
// This file is part of the "Nazara Engine - Network module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Network/Win32/SocketImpl.hpp>
|
#include <Nazara/Network/Win32/SocketImpl.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Core/Log.hpp>
|
#include <Nazara/Core/Log.hpp>
|
||||||
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
#include <Nazara/Network/Win32/IpAddressImpl.hpp>
|
#include <Nazara/Network/Win32/IpAddressImpl.hpp>
|
||||||
|
|
||||||
#if defined(NAZARA_COMPILER_MINGW) && __GNUC__ < 5
|
#if defined(NAZARA_COMPILER_MINGW) && __GNUC__ < 5
|
||||||
|
|
@ -593,10 +594,23 @@ namespace Nz
|
||||||
int byteSent = send(handle, reinterpret_cast<const char*>(buffer), length, 0);
|
int byteSent = send(handle, reinterpret_cast<const char*>(buffer), length, 0);
|
||||||
if (byteSent == SOCKET_ERROR)
|
if (byteSent == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
if (error)
|
int errorCode = WSAGetLastError();
|
||||||
*error = TranslateWSAErrorToSocketError(WSAGetLastError());
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case WSAEWOULDBLOCK:
|
||||||
|
{
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return false; //< Error
|
default:
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
*error = TranslateWSAErrorToSocketError(errorCode);
|
||||||
|
|
||||||
|
return false; //< Error
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sent)
|
if (sent)
|
||||||
|
|
@ -608,6 +622,53 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SocketImpl::SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error)
|
||||||
|
{
|
||||||
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
NazaraAssert(buffers && bufferCount > 0, "Invalid buffers");
|
||||||
|
|
||||||
|
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||||
|
int bufferLength = IpAddressImpl::ToSockAddr(to, nameBuffer.data());
|
||||||
|
|
||||||
|
StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(WSABUF));
|
||||||
|
WSABUF* winBuffers = static_cast<WSABUF*>(memory.GetPtr());
|
||||||
|
for (std::size_t i = 0; i < bufferCount; ++i)
|
||||||
|
{
|
||||||
|
winBuffers[i].buf = static_cast<CHAR*>(buffers[i].data);
|
||||||
|
winBuffers[i].len = static_cast<ULONG>(buffers[i].dataLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD byteSent;
|
||||||
|
if (WSASendTo(handle, winBuffers, static_cast<DWORD>(bufferCount), &byteSent, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength, nullptr, nullptr) == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
int errorCode = WSAGetLastError();
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case WSAEWOULDBLOCK:
|
||||||
|
{
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
*error = TranslateWSAErrorToSocketError(errorCode);
|
||||||
|
|
||||||
|
return false; //< Error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sent)
|
||||||
|
*sent = static_cast<int>(byteSent);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
*error = SocketError_NoError;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool SocketImpl::SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error)
|
bool SocketImpl::SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error)
|
||||||
{
|
{
|
||||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
|
@ -619,10 +680,23 @@ namespace Nz
|
||||||
int byteSent = sendto(handle, reinterpret_cast<const char*>(buffer), length, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength);
|
int byteSent = sendto(handle, reinterpret_cast<const char*>(buffer), length, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength);
|
||||||
if (byteSent == SOCKET_ERROR)
|
if (byteSent == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
if (error)
|
int errorCode = WSAGetLastError();
|
||||||
*error = TranslateWSAErrorToSocketError(WSAGetLastError());
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case WSAEWOULDBLOCK:
|
||||||
|
{
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return false; //< Error
|
default:
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
*error = TranslateWSAErrorToSocketError(errorCode);
|
||||||
|
|
||||||
|
return false; //< Error
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sent)
|
if (sent)
|
||||||
|
|
@ -719,7 +793,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
|
||||||
DWORD option = size;
|
DWORD option = static_cast<DWORD>(size);
|
||||||
if (setsockopt(handle, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
|
if (setsockopt(handle, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
|
|
@ -738,7 +812,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
|
||||||
DWORD option = size;
|
DWORD option = static_cast<DWORD>(size);
|
||||||
if (setsockopt(handle, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
|
if (setsockopt(handle, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2017 Jérôme Leclercq
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Network module"
|
// This file is part of the "Nazara Engine - Network module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -7,9 +7,10 @@
|
||||||
#ifndef NAZARA_SOCKETIMPL_HPP
|
#ifndef NAZARA_SOCKETIMPL_HPP
|
||||||
#define NAZARA_SOCKETIMPL_HPP
|
#define NAZARA_SOCKETIMPL_HPP
|
||||||
|
|
||||||
#include <Nazara/Network/SocketHandle.hpp>
|
|
||||||
#include <Nazara/Network/Enums.hpp>
|
#include <Nazara/Network/Enums.hpp>
|
||||||
#include <Nazara/Network/IpAddress.hpp>
|
#include <Nazara/Network/IpAddress.hpp>
|
||||||
|
#include <Nazara/Network/NetBuffer.hpp>
|
||||||
|
#include <Nazara/Network/SocketHandle.hpp>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
|
||||||
#define NAZARA_NETWORK_POLL_SUPPORT NAZARA_CORE_WINDOWS_NT6
|
#define NAZARA_NETWORK_POLL_SUPPORT NAZARA_CORE_WINDOWS_NT6
|
||||||
|
|
@ -65,6 +66,7 @@ namespace Nz
|
||||||
static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error);
|
static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error);
|
||||||
|
|
||||||
static bool Send(SocketHandle handle, const void* buffer, int length, int* sent, SocketError* error);
|
static bool Send(SocketHandle handle, const void* buffer, int length, int* sent, SocketError* error);
|
||||||
|
static bool SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error);
|
||||||
static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error);
|
static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error);
|
||||||
|
|
||||||
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue