ovr_sdk

view LibOVR/Src/Net/OVR_PacketizedTCPSocket.h @ 0:1b39a1b46319

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