Photon
1.0.0
Loading...
Searching...
No Matches
Socket.hpp
Go to the documentation of this file.
1
/*
2
* =====================================================================
3
*
4
* Photon
5
* Copyright Amlal EL Mahrouss, all rights reserved.
6
*
7
* =====================================================================
8
*/
9
10
#pragma once
11
12
#include <
Core.hpp
>
13
#include <fcntl.h>
14
15
#ifdef PHOTON_WINDOWS
16
17
#define PHOTON_SOCKET socket
18
#define PHOTON_CLOSE closesocket
19
#define PHOTON_SHUTDOWN shutdown
20
#define PHOTON_ACCEPT accept
21
#define PHOTON_CONNECT connect
22
#define PHOTON_IOCTL ioctlsocket
23
24
#else
25
26
#ifndef PHOTON_WINDOWS
27
#define SOCKET_ERROR -1
28
#define WSAECONNRESET ECONNRESET
29
#define WSAEWOULDBLOCK EWOULDBLOCK
30
#define WSAGetLastError() errno
31
#endif
32
33
#ifdef _WIN32
34
#define s_addr S_un.S_addr
35
#endif
36
37
#define PHOTON_SOCKET socket
38
#define PHOTON_CLOSE close
39
#define PHOTON_SHUTDOWN shutdown
40
#define PHOTON_ACCEPT accept
41
#define PHOTON_CONNECT connect
42
#define PHOTON_IOCTL ioctl
43
44
#define FIONBIO FNONBLOCK
45
#define FIOASYNC FASYNC
46
47
#endif
// PHOTON_WINDOWS
48
49
namespace
Photon
50
{
51
enum class
SOCKET_FLAG
: std::int64_t
52
{
53
NON_BLOCKING
=
FIONBIO
,
54
ASYNC
=
FIOASYNC
,
55
};
56
}
// namespace Photon
57
58
namespace
Photon::Network
59
{
60
enum class
SOCKET_TYPE
61
{
62
TCP
,
63
UDP
,
64
COUNT
,
65
};
66
67
using
CSocket
= uintptr_t;
68
69
class
PHOTON_API
Socket
final
70
{
71
public
:
72
explicit
Socket
(
const
SOCKET_TYPE
type
);
73
~Socket
();
74
75
Socket
&
operator=
(
const
Socket
&) =
default
;
76
Socket
(
const
Socket
&) =
default
;
77
78
public
:
79
operator
bool() noexcept;
80
81
public:
82
template
<typename Data,
size_t
Size = sizeof(Data)>
void
send(Data
ptr
,
std
::
size_t
sz = 0);
83
84
template
<typename Data,
size_t
Size = sizeof(Data)>
void
recv(Data
ptr
,
std
::
size_t
sz = 0);
85
86
public:
87
CSocket
PublicSocket;
88
};
89
}
// namespace Photon::Network
90
91
#include <Socket.inl>
Core.hpp
FIOASYNC
#define FIOASYNC
Definition
Socket.hpp:45
FIONBIO
#define FIONBIO
Definition
Socket.hpp:44
Photon::Network::Socket
Definition
Socket.hpp:70
Photon::Network::Socket::Socket
Socket(const Socket &)=default
Photon::Network::Socket::operator=
Socket & operator=(const Socket &)=default
type
type
Definition
core.h:681
PHOTON_API
#define PHOTON_API
Definition
Config.hpp:64
ptr
auto ptr(T p) -> const void *
Definition
format.h:4568
Photon::Network
Definition
Socket.hpp:59
Photon::Network::CSocket
uintptr_t CSocket
Definition
Socket.hpp:67
Photon::Network::SOCKET_TYPE
SOCKET_TYPE
Definition
Socket.hpp:61
Photon::Network::SOCKET_TYPE::COUNT
@ COUNT
Photon::Network::SOCKET_TYPE::TCP
@ TCP
Photon::Network::SOCKET_TYPE::UDP
@ UDP
Photon
This file is also about defining core js concepts.
Definition
BasePhotonWindow.hpp:22
Photon::SOCKET_FLAG
SOCKET_FLAG
Definition
Socket.hpp:52
Photon::SOCKET_FLAG::NON_BLOCKING
@ NON_BLOCKING
Photon::SOCKET_FLAG::ASYNC
@ ASYNC
std
Definition
uuid.h:926
template
template
Definition
tag_strings.h:13
dev
core
Socket.hpp
Generated by
1.9.8