39 lines
1.0 KiB
C++
39 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include "global.h"
|
|
#include "Socket.h"
|
|
#include "Core/Base/RingBuffer.hpp"
|
|
|
|
#include <system_error>
|
|
|
|
namespace Psc::asio_socket {
|
|
|
|
#ifndef PSC_ASIO_STREAM_RING_BUFFER
|
|
#define PSC_ASIO_STREAM_RING_BUFFER StreamRingBuffer_ST
|
|
#endif
|
|
|
|
#ifndef PSC_ASIO_PACKET_RING_BUFFER
|
|
#define PSC_ASIO_PACKET_RING_BUFFER RingBuffer_ST
|
|
#endif
|
|
|
|
using ASIO_StreamRingBuffer = PSC_ASIO_STREAM_RING_BUFFER;
|
|
using ASIO_PacketRingBuffer = PSC_ASIO_PACKET_RING_BUFFER;
|
|
|
|
inline Socket_FD socket_id(const void* ptr) {
|
|
return static_cast<Socket_FD>(reinterpret_cast<std::uintptr_t>(ptr));
|
|
}
|
|
|
|
inline Sockaddr_In endpoint_to_sockaddr(const asio::ip::tcp::endpoint& endpoint) {
|
|
return {endpoint.address().to_string(), endpoint.port()};
|
|
}
|
|
|
|
inline Sockaddr_In endpoint_to_sockaddr(const asio::ip::udp::endpoint& endpoint) {
|
|
return {endpoint.address().to_string(), endpoint.port()};
|
|
}
|
|
|
|
inline bool would_block(const asio::error_code& ec) {
|
|
return ec == asio::error::would_block || ec == asio::error::try_again;
|
|
}
|
|
|
|
} // namespace Psc::asio_socket
|