SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RakNetSocket.cpp
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
16 /*
17 #include "slikenet/socket.h"
18 #include "slikenet/memoryoverride.h"
19
20 using namespace SLNet;
21
22 #if defined(__native_client__)
23 using namespace pp;
24 #endif
25
26 RakNetSocket::RakNetSocket() {
27 #if !defined(WINDOWS_STORE_RT)
28 s = 0;
29 #endif
30 remotePortRakNetWasStartedOn_PS3_PSP2 = 0;
31 userConnectionSocketIndex = (unsigned int) -1;
32 socketFamily = 0;
33 blockingSocket = 0;
34 extraSocketOptions = 0;
35 chromeInstance = 0;
36
37 #if defined (_WIN32) && defined(USE_WAIT_FOR_MULTIPLE_EVENTS)
38 recvEvent=INVALID_HANDLE_VALUE;
39 #endif
40
41 #ifdef __native_client__
42 s = 0;
43 sendInProgress = false;
44 nextSendSize = 0;
45 #endif
46 }
47 RakNetSocket::~RakNetSocket()
48 {
49 #ifdef __native_client__
50 if(s != 0)
51 ((PPB_UDPSocket_Private_0_4*) pp::Module::Get()->GetBrowserInterface(PPB_UDPSOCKET_PRIVATE_INTERFACE_0_4))->Close(s);
52 #elif defined(WINDOWS_STORE_RT)
53 WinRTClose(s);
54 #else
55 if ((__UDPSOCKET__)s != 0)
56 closesocket__(s);
57 #endif
58
59
60 #if defined (_WIN32) && defined(USE_WAIT_FOR_MULTIPLE_EVENTS)
61 if (recvEvent!=INVALID_HANDLE_VALUE)
62 {
63 CloseHandle( recvEvent );
64 recvEvent = INVALID_HANDLE_VALUE;
65 }
66 #endif
67 }
68 //
69 // void RakNetSocket::Accept(
70 // struct sockaddr *addr,
71 // int *addrlen)
72 // {
73 // accept__(s, addr, addrlen);
74 // }
75
76 //
77 // void RakNetSocket::Close( void )
78 // {
79 // closesocket__(s);
80 // }
81
82 RakNetSocket* RakNetSocket::Create
83 #ifdef __native_client__
84 (_PP_Instance_ _chromeInstance)
85 #else
86 (int af,
87 int type,
88 int protocol)
89 #endif
90 {
91 __UDPSOCKET__ sock;
92
93 #ifndef __native_client__
94 RakAssert(type==SOCK_DGRAM);
95 #endif
96
97 #ifdef __native_client__
98 sock = ((PPB_UDPSocket_Private_0_4*) Module::Get()->GetBrowserInterface(PPB_UDPSOCKET_PRIVATE_INTERFACE_0_4))->Create(_chromeInstance);
99 #elif defined(SN_TARGET_PSP2)
100 sock = sceNetSocket( "RakNetSocket::Create", SCE_NET_AF_INET, SCE_NET_SOCK_DGRAM_P2P, 0 );
101 #elif defined(WINDOWS_STORE_RT)
102 sock = WinRTCreateDatagramSocket(af,type,protocol);
103 #elif defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3) || defined(_PS4)
104 sock = socket__( AF_INET, SOCK_DGRAM_P2P, 0 );
105 #else
106 sock = socket__(af, type, protocol);
107 #endif
108
109 #if !defined(WINDOWS_STORE_RT)
110 if (sock<0)
111 return 0;
112 #endif
113 RakNetSocket *rns = SLNet::OP_NEW<RakNetSocket>(_FILE_AND_LINE_);
114 rns->s = sock;
115 #ifdef __native_client__
116 rns->chromeInstance = _chromeInstance;
117 #endif
118 return rns;
119 }
120
121 int RakNetSocket::Bind(
122 const struct sockaddr *addr,
123 int namelen)
124 {
125 return bind__(s,addr,namelen);
126 }
127
128 int RakNetSocket::IOCTLSocket(
129 long cmd,
130 unsigned long *argp)
131 {
132 #if defined(_WIN32)
133 return ioctlsocket__(s,cmd,argp);
134 #else
135 return 0;
136 #endif
137 }
138
139 int RakNetSocket::Listen (
140 int backlog)
141 {
142 return listen__(s,backlog);
143 }
144
145 int RakNetSocket::SetSockOpt(
146 int level,
147 int optname,
148 const char * optval,
149 int optlen)
150 {
151 return setsockopt__(s,level,optname,optval,optlen);
152 }
153
154 int RakNetSocket::Shutdown(
155 int how)
156 {
157 #ifndef SN_TARGET_PSP2
158 return shutdown__(s,how);
159 #else
160 return 0;
161 #endif
162 }
163 */