forked from facebookarchive/RakNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakNetSocket.h
194 lines (155 loc) · 5.36 KB
/
RakNetSocket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* Copyright (c) 2014, Oculus VR, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
/*
#ifndef __RAKNET_SOCKET_H
#define __RAKNET_SOCKET_H
#include "RakNetTypes.h"
#include "RakNetDefines.h"
#include "Export.h"
#include "SocketIncludes.h"
#include "RakAssert.h"
#include "SocketDefines.h"
#include "MTUSize.h"
namespace RakNet
{
struct RAK_DLL_EXPORT RakNetSocket
{
public:
RakNetSocket();
~RakNetSocket();
// void Accept(
// struct sockaddr *addr,
// int *addrlen);
inline int Connect(
const struct sockaddr *name,
int namelen) {return connect__(s,name,namelen);}
static RakNetSocket* Create
#ifdef __native_client__
(_PP_Instance_ _chromeInstance);
#else
(int af,
int type,
int protocol);
#endif
int Bind(
const struct sockaddr *addr,
int namelen);
inline int GetSockName(
struct sockaddr *name,
socklen_t * namelen) {return getsockname__(s,name,namelen);}
inline int GetSockOpt (
int level,
int optname,
char * optval,
socklen_t *optlen) {return getsockopt__(s,level,optname,optval,optlen);}
int IOCTLSocket(
long cmd,
unsigned long *argp);
int Listen (
int backlog);
inline int Recv(
char * buf,
int len,
int flags) {return recv__(s,buf,len,flags);}
inline int RecvFrom(
char * buf,
int len,
int flags,
struct sockaddr * from,
socklen_t * fromlen) {return recvfrom__(s,buf,len,flags,from,fromlen);}
// inline int Select(
// int nfds,
// fd_set *readfds,
// fd_set *writefds,
// fd_set *exceptfds,
// struct timeval *timeout) {return select__(nfds,readfds,writefds,exceptfds,timeout);}
inline int Send(
const char * buf,
int len,
int flags) {return send__(s,buf,len,flags);}
inline int SendTo(
const char * buf,
int len,
int flags,
const struct sockaddr *to,
int tolen) {return sendto__(s,buf,len,flags,to,tolen);}
#ifdef _WIN32
#elif defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3) || defined(_PS4) || defined(SN_TARGET_PSP2)
#else
inline int Fcntl(int cmd, int arg) {return fcntl(s,cmd,arg);}
#endif
#if defined(_WIN32) && !defined(WINDOWS_STORE_RT)
inline int _WSASendTo(
LPWSABUF lpBuffers,
DWORD dwBufferCount,
LPDWORD lpNumberOfBytesSent,
DWORD dwFlags,
const struct sockaddr FAR * lpTo,
int iTolen,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
)
{ return WSASendTo(s,lpBuffers,dwBufferCount,lpNumberOfBytesSent,dwFlags,lpTo,iTolen,lpOverlapped,lpCompletionRoutine);}
#endif
int SetSockOpt(
int level,
int optname,
const char * optval,
int optlen);
int Shutdown(
int how);
inline void SetRemotePortRakNetWasStartedOn(unsigned short i) {remotePortRakNetWasStartedOn_PS3_PSP2=i;}
inline void SetUserConnectionSocketIndex(unsigned int i) {userConnectionSocketIndex=i;}
inline void SetBoundAddress(SystemAddress i) {boundAddress=i;}
inline void SetSocketFamily(unsigned short i) {socketFamily=i;}
inline void SetBlockingSocket(bool i) {blockingSocket=i;}
inline void SetExtraSocketOptions(unsigned int i) {extraSocketOptions=i;}
inline void SetChromeInstance(_PP_Instance_ i) {chromeInstance=i;}
inline void SetBoundAddressToLoopback(unsigned char ipVersion) {boundAddress.SetToLoopback(ipVersion);}
inline SystemAddress GetBoundAddress(void) const {return boundAddress;}
inline unsigned short GetRemotePortRakNetWasStartedOn(void) const {return remotePortRakNetWasStartedOn_PS3_PSP2;}
inline bool GetBlockingSocket(void) {return blockingSocket;}
inline unsigned int GetExtraSocketOptions(void) const {return extraSocketOptions;}
inline unsigned short GetSocketFamily(void) const {return socketFamily;}
inline _PP_Instance_ GetChromeInstance(void) const {return chromeInstance;}
inline unsigned int GetUserConnectionSocketIndex(void) const {
RakAssert(userConnectionSocketIndex!=(unsigned int)-1);
return userConnectionSocketIndex;}
#ifdef __native_client__
// Flag indicating if a SendTo is currently in progress
bool sendInProgress;
// Data for next queued packet to send, if nextSendSize > 0
char nextSendBuffer[MAXIMUM_MTU_SIZE];
// Size of next queued packet to send, or 0 if no queued packet
int nextSendSize;
// Destination address of queued packet
PP_NetAddress_Private nextSendAddr;
#endif
__UDPSOCKET__ s;
protected:
#if defined (_WIN32) && defined(USE_WAIT_FOR_MULTIPLE_EVENTS)
void* recvEvent;
#endif
#if defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3) || defined(_PS4) || defined(SN_TARGET_PSP2)
/// PS3: Set for the PS3, when using signaling.
/// PS3: Connect with the port returned by signaling. Set this to whatever port RakNet was actually started on
/// PSP2: Set non-zero to use SCE_NET_SOCK_DGRAM_P2P. This should be done for ad-hoc or with
#endif
unsigned short remotePortRakNetWasStartedOn_PS3_PSP2;
unsigned int userConnectionSocketIndex;
SystemAddress boundAddress;
unsigned short socketFamily;
bool blockingSocket;
unsigned int extraSocketOptions;
_PP_Instance_ chromeInstance;
};
} // namespace RakNet
#endif
*/