Merge remote-tracking branch 'refs/remotes/origin/master' into ast-shader-generation
This commit is contained in:
commit
35d9516ae8
2
Doxyfile
2
Doxyfile
|
|
@ -38,7 +38,7 @@ PROJECT_NAME = "Nazara Engine"
|
|||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = 0.2
|
||||
PROJECT_NUMBER = 0.3
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
|
|
|
|||
|
|
@ -158,11 +158,16 @@ namespace Ndk
|
|||
}
|
||||
m_systemBits.Clear();
|
||||
|
||||
UnregisterAllHandles();
|
||||
// We properly destroy each component
|
||||
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
|
||||
m_components[i]->SetEntity(nullptr);
|
||||
|
||||
m_components.clear();
|
||||
m_componentBits.Reset();
|
||||
|
||||
// And then free every handle
|
||||
UnregisterAllHandles();
|
||||
|
||||
m_valid = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace Nz
|
|||
public:
|
||||
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);
|
||||
|
||||
explicit constexpr operator bool() const;
|
||||
|
|
@ -54,13 +54,13 @@ namespace Nz
|
|||
private:
|
||||
BitField m_value;
|
||||
};
|
||||
|
||||
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs);
|
||||
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator|(E lhs, E rhs);
|
||||
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator&(E lhs, E rhs);
|
||||
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator^(E lhs, E rhs);
|
||||
}
|
||||
|
||||
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator~(E lhs);
|
||||
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator|(E lhs, E rhs);
|
||||
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator&(E lhs, E rhs);
|
||||
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator^(E lhs, E rhs);
|
||||
|
||||
#include <Nazara/Core/Flags.inl>
|
||||
|
||||
#endif // NAZARA_FLAGS_HPP
|
||||
|
|
|
|||
|
|
@ -209,68 +209,67 @@ namespace Nz
|
|||
{
|
||||
return 1U << static_cast<BitField>(enumValue);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Override binary NOT operator on enum to turns into a Flags object.
|
||||
* \return A Flags object with reversed bits.
|
||||
*
|
||||
* \param lhs Enumeration value to reverse.
|
||||
*
|
||||
* Returns a Flags object with all state enabled except for the enum one.
|
||||
*/
|
||||
template<typename E>
|
||||
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator~(E lhs)
|
||||
{
|
||||
return ~Nz::Flags<E>(lhs);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Override binary NOT operator on enum to turns into a Flags object.
|
||||
* \return A Flags object with reversed bits.
|
||||
*
|
||||
* \param lhs Enumeration value to reverse.
|
||||
*
|
||||
* Returns a Flags object with all state enabled except for the enum one.
|
||||
*/
|
||||
template<typename E>
|
||||
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs)
|
||||
{
|
||||
return ~Flags<E>(lhs);
|
||||
}
|
||||
/*!
|
||||
* \brief Override binary OR operator on enum to turns into a Flags object.
|
||||
* \return A Flags object with combined enum states.
|
||||
*
|
||||
* \param lhs First enumeration value to combine.
|
||||
* \param rhs Second enumeration value to combine.
|
||||
*
|
||||
* Returns a Flags object with combined states from the two enumeration values.
|
||||
*/
|
||||
template<typename E>
|
||||
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator|(E lhs, E rhs)
|
||||
{
|
||||
return Nz::Flags<E>(lhs) | rhs;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Override binary OR operator on enum to turns into a Flags object.
|
||||
* \return A Flags object with combined enum states.
|
||||
*
|
||||
* \param lhs First enumeration value to combine.
|
||||
* \param rhs Second enumeration value to combine.
|
||||
*
|
||||
* Returns a Flags object with combined states from the two enumeration values.
|
||||
*/
|
||||
template<typename E>
|
||||
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator|(E lhs, E rhs)
|
||||
{
|
||||
return Flags<E>(lhs) | rhs;
|
||||
}
|
||||
/*!
|
||||
* \brief Override binary AND operator on enum to turns into a Flags object.
|
||||
* \return A Flags object with compare enum states.
|
||||
*
|
||||
* \param lhs First enumeration value to compare.
|
||||
* \param rhs Second enumeration value to compare.
|
||||
*
|
||||
* Returns a Flags object with compared states from the two enumeration values.
|
||||
* In this case, only one flag will be enabled if both enumeration values are the same.
|
||||
*/
|
||||
template<typename E>
|
||||
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator&(E lhs, E rhs)
|
||||
{
|
||||
return Nz::Flags<E>(lhs) & rhs;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Override binary AND operator on enum to turns into a Flags object.
|
||||
* \return A Flags object with compare enum states.
|
||||
*
|
||||
* \param lhs First enumeration value to compare.
|
||||
* \param rhs Second enumeration value to compare.
|
||||
*
|
||||
* Returns a Flags object with compared states from the two enumeration values.
|
||||
* In this case, only one flag will be enabled if both enumeration values are the same.
|
||||
*/
|
||||
template<typename E>
|
||||
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator&(E lhs, E rhs)
|
||||
{
|
||||
return Flags<E>(lhs) & rhs;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Override binary XOR operator on enum to turns into a Flags object.
|
||||
* \return A Flags object with XORed enum states.
|
||||
*
|
||||
* \param lhs First enumeration value to compare.
|
||||
* \param rhs Second enumeration value to compare.
|
||||
*
|
||||
* Returns a Flags object with XORed states from the two enumeration values.
|
||||
* In this case, two flags will be enabled if both the enumeration values are different.
|
||||
*/
|
||||
template<typename E>
|
||||
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator^(E lhs, E rhs)
|
||||
{
|
||||
return Flags<E>(lhs) ^ rhs;
|
||||
}
|
||||
/*!
|
||||
* \brief Override binary XOR operator on enum to turns into a Flags object.
|
||||
* \return A Flags object with XORed enum states.
|
||||
*
|
||||
* \param lhs First enumeration value to compare.
|
||||
* \param rhs Second enumeration value to compare.
|
||||
*
|
||||
* Returns a Flags object with XORed states from the two enumeration values.
|
||||
* In this case, two flags will be enabled if both the enumeration values are different.
|
||||
*/
|
||||
template<typename E>
|
||||
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator^(E lhs, E rhs)
|
||||
{
|
||||
return Nz::Flags<E>(lhs) ^ rhs;
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -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 - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
|
@ -38,6 +38,9 @@ namespace Nz
|
|||
template<typename T, typename... Args>
|
||||
T* PlacementNew(T* ptr, Args&&... args);
|
||||
|
||||
template<typename T>
|
||||
void PlacementDestroy(T* ptr);
|
||||
|
||||
class StackAllocation
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -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 - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
|
@ -64,6 +64,17 @@ namespace Nz
|
|||
return new (ptr) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calls the object destructor explicitly
|
||||
*
|
||||
* \param ptr Pointer to a previously constructed pointer on raw memory
|
||||
*/
|
||||
template<typename T>
|
||||
void PlacementDestroy(T* ptr)
|
||||
{
|
||||
ptr->~T();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::StackAllocation
|
||||
|
|
|
|||
|
|
@ -22,12 +22,14 @@ namespace Nz
|
|||
~MemoryPool() = default;
|
||||
|
||||
void* Allocate(unsigned int size);
|
||||
|
||||
template<typename T> void Delete(T* ptr);
|
||||
|
||||
void Free(void* ptr);
|
||||
|
||||
unsigned int GetBlockSize() const;
|
||||
unsigned int GetFreeBlocks() const;
|
||||
unsigned int GetSize() const;
|
||||
inline unsigned int GetBlockSize() const;
|
||||
inline unsigned int GetFreeBlocks() const;
|
||||
inline unsigned int GetSize() const;
|
||||
|
||||
template<typename T, typename... Args> T* New(Args&&... args);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/MemoryPool.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
|
|
@ -95,9 +96,8 @@ namespace Nz
|
|||
*
|
||||
* \remark If ptr is null, nothing is done
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
inline void MemoryPool::Delete(T* ptr)
|
||||
void MemoryPool::Delete(T* ptr)
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ namespace Nz
|
|||
template<typename T> bool operator<(const T& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator<(const ObjectHandle<T>& lhs, const T& rhs);
|
||||
|
||||
template<typename T> bool operator<=(const ObjectHandle<T>, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator<=(const ObjectHandle<T>&, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator<=(const T& lhs, const ObjectHandle<T>& rhs);
|
||||
template<typename T> bool operator<=(const ObjectHandle<T>& lhs, const T& rhs);
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#ifndef NAZARA_ENUMS_NETWORK_HPP
|
||||
#define NAZARA_ENUMS_NETWORK_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum NetCode : UInt16
|
||||
|
|
|
|||
|
|
@ -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/Network/AbstractSocket.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <Nazara/Network/NetBuffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -49,6 +50,7 @@ namespace Nz
|
|||
bool ReceivePacket(NetPacket* packet);
|
||||
|
||||
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 SetCursorPos(UInt64 offset) override;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Network/AbstractSocket.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <Nazara/Network/NetBuffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -42,6 +43,7 @@ namespace Nz
|
|||
bool ReceivePacket(NetPacket* packet, IpAddress* from);
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace Nz
|
|||
static std::array<Vector4f, 2 * 2 * 2 * 2 * 2> s_gradients4;
|
||||
|
||||
private:
|
||||
std::default_random_engine m_randomEngine;
|
||||
std::mt19937 m_randomEngine;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@
|
|||
|
||||
// Nazara version macro
|
||||
#define NAZARA_VERSION_MAJOR 0
|
||||
#define NAZARA_VERSION_MINOR 2
|
||||
#define NAZARA_VERSION_PATCH 1
|
||||
#define NAZARA_VERSION_MINOR 3
|
||||
#define NAZARA_VERSION_PATCH 0
|
||||
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -5102,10 +5102,14 @@ namespace Nz
|
|||
*/
|
||||
String String::FormatVA(const char* format, va_list args)
|
||||
{
|
||||
// Copy va_list to use it twice
|
||||
va_list args2;
|
||||
va_copy(args2, args);
|
||||
|
||||
std::size_t length = std::vsnprintf(nullptr, 0, format, args);
|
||||
|
||||
auto str = std::make_shared<SharedString>(length);
|
||||
std::vsnprintf(str->string.get(), length + 1, format, args);
|
||||
std::vsnprintf(str->string.get(), length + 1, format, args2);
|
||||
|
||||
return String(std::move(str));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,8 +117,7 @@ namespace Nz
|
|||
*/
|
||||
std::size_t AbstractSocket::QueryReceiveBufferSize() const
|
||||
{
|
||||
if (m_handle == SocketImpl::InvalidHandle)
|
||||
return 0;
|
||||
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first");
|
||||
|
||||
return SocketImpl::QueryReceiveBufferSize(m_handle);
|
||||
}
|
||||
|
|
@ -129,8 +128,7 @@ namespace Nz
|
|||
*/
|
||||
std::size_t AbstractSocket::QuerySendBufferSize() const
|
||||
{
|
||||
if (m_handle == SocketImpl::InvalidHandle)
|
||||
return 0;
|
||||
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first");
|
||||
|
||||
return SocketImpl::QuerySendBufferSize(m_handle);
|
||||
}
|
||||
|
|
@ -142,7 +140,8 @@ namespace Nz
|
|||
*/
|
||||
void AbstractSocket::SetReceiveBufferSize(std::size_t size)
|
||||
{
|
||||
if (m_handle != SocketImpl::InvalidHandle)
|
||||
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first");
|
||||
|
||||
SocketImpl::SetReceiveBufferSize(m_handle, size);
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +152,8 @@ namespace Nz
|
|||
*/
|
||||
void AbstractSocket::SetSendBufferSize(std::size_t size)
|
||||
{
|
||||
if (m_handle != SocketImpl::InvalidHandle)
|
||||
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first");
|
||||
|
||||
SocketImpl::SetSendBufferSize(m_handle, size);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@
|
|||
#include <Nazara/Network/Posix/SocketImpl.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <Nazara/Network/Posix/IpAddressImpl.hpp>
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
|
|
@ -463,6 +465,9 @@ namespace Nz
|
|||
if (byteRead == SOCKET_ERROR)
|
||||
{
|
||||
int errorCode = GetLastErrorCode();
|
||||
if (errorCode == EAGAIN)
|
||||
errorCode = EWOULDBLOCK;
|
||||
|
||||
switch (errorCode)
|
||||
{
|
||||
case EWOULDBLOCK:
|
||||
|
|
@ -512,6 +517,9 @@ namespace Nz
|
|||
if (byteRead == SOCKET_ERROR)
|
||||
{
|
||||
int errorCode = GetLastErrorCode();
|
||||
if (errorCode == EAGAIN)
|
||||
errorCode = EWOULDBLOCK;
|
||||
|
||||
switch (errorCode)
|
||||
{
|
||||
case EWOULDBLOCK:
|
||||
|
|
@ -560,12 +568,26 @@ namespace Nz
|
|||
|
||||
int byteSent = send(handle, reinterpret_cast<const char*>(buffer), length, 0);
|
||||
if (byteSent == SOCKET_ERROR)
|
||||
{
|
||||
int errorCode = GetLastErrorCode();
|
||||
if (errorCode == EAGAIN)
|
||||
errorCode = EWOULDBLOCK;
|
||||
|
||||
switch (errorCode)
|
||||
{
|
||||
case EWOULDBLOCK:
|
||||
byteSent = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
if (error)
|
||||
*error = TranslateErrnoToResolveError(GetLastErrorCode());
|
||||
*error = TranslateErrnoToResolveError(errorCode);
|
||||
|
||||
return false; //< Error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sent)
|
||||
*sent = byteSent;
|
||||
|
|
@ -576,6 +598,60 @@ namespace Nz
|
|||
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 msgHdr;
|
||||
std::memset(&msgHdr, 0, sizeof(msgHdr));
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
msgHdr.msg_namelen = IpAddressImpl::ToSockAddr(to, nameBuffer.data());
|
||||
msgHdr.msg_name = nameBuffer.data();
|
||||
msgHdr.msg_iov = sysBuffers;
|
||||
msgHdr.msg_iovlen = static_cast<int>(bufferCount);
|
||||
|
||||
int byteSent = sendmsg(handle, &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)
|
||||
{
|
||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||
|
|
@ -586,12 +662,26 @@ namespace Nz
|
|||
|
||||
int byteSent = sendto(handle, reinterpret_cast<const char*>(buffer), length, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength);
|
||||
if (byteSent == SOCKET_ERROR)
|
||||
{
|
||||
int errorCode = GetLastErrorCode();
|
||||
if (errorCode == EAGAIN)
|
||||
errorCode = EWOULDBLOCK;
|
||||
|
||||
switch (errorCode)
|
||||
{
|
||||
case EWOULDBLOCK:
|
||||
byteSent = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
if (error)
|
||||
*error = TranslateErrnoToResolveError(GetLastErrorCode());
|
||||
*error = TranslateErrnoToResolveError(errorCode);
|
||||
|
||||
return false; //< Error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sent)
|
||||
*sent = byteSent;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <Nazara/Network/SocketHandle.hpp>
|
||||
#include <Nazara/Network/Enums.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <Nazara/Network/NetBuffer.hpp>
|
||||
|
||||
#define NAZARA_NETWORK_POLL_SUPPORT 1
|
||||
|
||||
|
|
@ -64,6 +65,7 @@ namespace Nz
|
|||
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 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 SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
||||
|
|
|
|||
|
|
@ -353,6 +353,45 @@ namespace Nz
|
|||
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
|
||||
* \return true If packet sent
|
||||
|
|
|
|||
|
|
@ -17,6 +17,12 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \ingroup network
|
||||
* \class Nz::UdpSocket
|
||||
* \brief Network class that represents a UDP socket, allowing for sending/receiving datagrams.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Binds a specific IpAddress
|
||||
* \return State of the socket
|
||||
|
|
@ -93,7 +99,18 @@ namespace Nz
|
|||
|
||||
int read;
|
||||
if (!SocketImpl::ReceiveFrom(m_handle, buffer, static_cast<int>(size), from, &read, &m_lastError))
|
||||
{
|
||||
switch (m_lastError)
|
||||
{
|
||||
case SocketError_ConnectionClosed:
|
||||
m_lastError = SocketError_NoError;
|
||||
read = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (received)
|
||||
*received = read;
|
||||
|
|
@ -179,6 +196,31 @@ namespace Nz
|
|||
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
|
||||
* \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"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Network/Win32/SocketImpl.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <Nazara/Network/Win32/IpAddressImpl.hpp>
|
||||
|
||||
#if defined(NAZARA_COMPILER_MINGW) && __GNUC__ < 5
|
||||
|
|
@ -592,12 +593,25 @@ namespace Nz
|
|||
|
||||
int byteSent = send(handle, reinterpret_cast<const char*>(buffer), length, 0);
|
||||
if (byteSent == SOCKET_ERROR)
|
||||
{
|
||||
int errorCode = WSAGetLastError();
|
||||
switch (errorCode)
|
||||
{
|
||||
case WSAEWOULDBLOCK:
|
||||
{
|
||||
byteSent = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if (error)
|
||||
*error = TranslateWSAErrorToSocketError(WSAGetLastError());
|
||||
*error = TranslateWSAErrorToSocketError(errorCode);
|
||||
|
||||
return false; //< Error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sent)
|
||||
*sent = byteSent;
|
||||
|
|
@ -608,6 +622,53 @@ namespace Nz
|
|||
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)
|
||||
{
|
||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||
|
|
@ -618,12 +679,25 @@ namespace Nz
|
|||
|
||||
int byteSent = sendto(handle, reinterpret_cast<const char*>(buffer), length, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength);
|
||||
if (byteSent == SOCKET_ERROR)
|
||||
{
|
||||
int errorCode = WSAGetLastError();
|
||||
switch (errorCode)
|
||||
{
|
||||
case WSAEWOULDBLOCK:
|
||||
{
|
||||
byteSent = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if (error)
|
||||
*error = TranslateWSAErrorToSocketError(WSAGetLastError());
|
||||
*error = TranslateWSAErrorToSocketError(errorCode);
|
||||
|
||||
return false; //< Error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sent)
|
||||
*sent = byteSent;
|
||||
|
|
@ -719,7 +793,7 @@ namespace Nz
|
|||
{
|
||||
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 (error)
|
||||
|
|
@ -738,7 +812,7 @@ namespace Nz
|
|||
{
|
||||
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 (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"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
|
|
@ -7,9 +7,10 @@
|
|||
#ifndef NAZARA_SOCKETIMPL_HPP
|
||||
#define NAZARA_SOCKETIMPL_HPP
|
||||
|
||||
#include <Nazara/Network/SocketHandle.hpp>
|
||||
#include <Nazara/Network/Enums.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <Nazara/Network/NetBuffer.hpp>
|
||||
#include <Nazara/Network/SocketHandle.hpp>
|
||||
#include <winsock2.h>
|
||||
|
||||
#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 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 SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
||||
|
|
|
|||
Loading…
Reference in New Issue