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
49namespace Photon
50{
51 enum class SOCKET_FLAG : std::int64_t
52 {
55 };
56} // namespace Photon
57
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>
#define FIOASYNC
Definition Socket.hpp:45
#define FIONBIO
Definition Socket.hpp:44
Definition Socket.hpp:70
Socket(const Socket &)=default
Socket & operator=(const Socket &)=default
type
Definition core.h:681
#define PHOTON_API
Definition Config.hpp:64
auto ptr(T p) -> const void *
Definition format.h:4568
Definition Socket.hpp:59
uintptr_t CSocket
Definition Socket.hpp:67
SOCKET_TYPE
Definition Socket.hpp:61
This file is also about defining core js concepts.
Definition BasePhotonWindow.hpp:22
SOCKET_FLAG
Definition Socket.hpp:52
Definition uuid.h:926
template
Definition tag_strings.h:13