rev |
line source |
nuclear@0
|
1 /************************************************************************************
|
nuclear@0
|
2
|
nuclear@0
|
3 PublicHeader: n/a
|
nuclear@0
|
4 Filename : OVR_PacketizedTCPSocket.cpp
|
nuclear@0
|
5 Content : TCP with automated message framing.
|
nuclear@0
|
6 Created : June 10, 2014
|
nuclear@0
|
7 Authors : Kevin Jenkins
|
nuclear@0
|
8
|
nuclear@0
|
9 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
|
nuclear@0
|
10
|
nuclear@0
|
11 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
|
nuclear@0
|
12 you may not use the Oculus VR Rift SDK except in compliance with the License,
|
nuclear@0
|
13 which is provided at the time of installation or download, or which
|
nuclear@0
|
14 otherwise accompanies this software in either electronic or hard copy form.
|
nuclear@0
|
15
|
nuclear@0
|
16 You may obtain a copy of the License at
|
nuclear@0
|
17
|
nuclear@0
|
18 http://www.oculusvr.com/licenses/LICENSE-3.2
|
nuclear@0
|
19
|
nuclear@0
|
20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
nuclear@0
|
21 distributed under the License is distributed on an "AS IS" BASIS,
|
nuclear@0
|
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
nuclear@0
|
23 See the License for the specific language governing permissions and
|
nuclear@0
|
24 limitations under the License.
|
nuclear@0
|
25
|
nuclear@0
|
26 ************************************************************************************/
|
nuclear@0
|
27
|
nuclear@0
|
28 #ifndef OVR_PacketizedTCPSocket_h
|
nuclear@0
|
29 #define OVR_PacketizedTCPSocket_h
|
nuclear@0
|
30
|
nuclear@0
|
31 #include "OVR_Socket.h"
|
nuclear@0
|
32 #include "../Kernel/OVR_Allocator.h"
|
nuclear@0
|
33 #include "../Kernel/OVR_Atomic.h"
|
nuclear@0
|
34
|
nuclear@0
|
35 #ifdef OVR_OS_WIN32
|
nuclear@0
|
36 #include "OVR_Win32_Socket.h"
|
nuclear@0
|
37 #else
|
nuclear@0
|
38 #include "OVR_Unix_Socket.h"
|
nuclear@0
|
39 #endif
|
nuclear@0
|
40
|
nuclear@0
|
41 namespace OVR { namespace Net {
|
nuclear@0
|
42
|
nuclear@0
|
43
|
nuclear@0
|
44 //-----------------------------------------------------------------------------
|
nuclear@0
|
45 // NetworkPlugin
|
nuclear@0
|
46
|
nuclear@0
|
47 // Packetized TCP base socket
|
nuclear@0
|
48 class PacketizedTCPSocketBase : public TCPSocket
|
nuclear@0
|
49 {
|
nuclear@0
|
50 public:
|
nuclear@0
|
51 PacketizedTCPSocketBase() {}
|
nuclear@0
|
52 PacketizedTCPSocketBase(SocketHandle _sock, bool isListenSocket) : TCPSocket(_sock, isListenSocket) {}
|
nuclear@0
|
53 };
|
nuclear@0
|
54
|
nuclear@0
|
55
|
nuclear@0
|
56 //-----------------------------------------------------------------------------
|
nuclear@0
|
57 // PacketizedTCPSocket
|
nuclear@0
|
58
|
nuclear@0
|
59 // Uses TCP but is message aligned rather than stream aligned
|
nuclear@0
|
60 // Alternative to reliable UDP
|
nuclear@0
|
61 class PacketizedTCPSocket : public PacketizedTCPSocketBase
|
nuclear@0
|
62 {
|
nuclear@0
|
63 public:
|
nuclear@0
|
64 PacketizedTCPSocket();
|
nuclear@0
|
65 PacketizedTCPSocket(SocketHandle _sock, bool isListenSocket);
|
nuclear@0
|
66 virtual ~PacketizedTCPSocket();
|
nuclear@0
|
67
|
nuclear@0
|
68 public:
|
nuclear@0
|
69 virtual int Send(const void* pData, int bytes);
|
nuclear@0
|
70 virtual int SendAndConcatenate(const void** pDataArray, int *dataLengthArray, int arrayCount);
|
nuclear@0
|
71
|
nuclear@0
|
72 protected:
|
nuclear@0
|
73 virtual void OnRecv(SocketEvent_TCP* eventHandler, uint8_t* pData, int bytesRead);
|
nuclear@0
|
74
|
nuclear@0
|
75 int BytesFromStream(uint8_t* pData, int bytesRead);
|
nuclear@0
|
76
|
nuclear@0
|
77 Lock sendLock;
|
nuclear@0
|
78 Lock recvBuffLock;
|
nuclear@0
|
79
|
nuclear@0
|
80 uint8_t* pRecvBuff; // Queued receive buffered data
|
nuclear@0
|
81 int pRecvBuffSize; // Size of receive queue in bytes
|
nuclear@0
|
82 };
|
nuclear@0
|
83
|
nuclear@0
|
84
|
nuclear@0
|
85 }} // OVR::Net
|
nuclear@0
|
86
|
nuclear@0
|
87 #endif
|