ovr_sdk

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/Net/OVR_PacketizedTCPSocket.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,87 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +PublicHeader:   n/a
     1.7 +Filename    :   OVR_PacketizedTCPSocket.cpp
     1.8 +Content     :   TCP with automated message framing.
     1.9 +Created     :   June 10, 2014
    1.10 +Authors     :   Kevin Jenkins
    1.11 +
    1.12 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.13 +
    1.14 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.15 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.16 +which is provided at the time of installation or download, or which 
    1.17 +otherwise accompanies this software in either electronic or hard copy form.
    1.18 +
    1.19 +You may obtain a copy of the License at
    1.20 +
    1.21 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.22 +
    1.23 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.24 +distributed under the License is distributed on an "AS IS" BASIS,
    1.25 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.26 +See the License for the specific language governing permissions and
    1.27 +limitations under the License.
    1.28 +
    1.29 +************************************************************************************/
    1.30 +
    1.31 +#ifndef OVR_PacketizedTCPSocket_h
    1.32 +#define OVR_PacketizedTCPSocket_h
    1.33 +
    1.34 +#include "OVR_Socket.h"
    1.35 +#include "../Kernel/OVR_Allocator.h"
    1.36 +#include "../Kernel/OVR_Atomic.h"
    1.37 +
    1.38 +#ifdef OVR_OS_WIN32
    1.39 +#include "OVR_Win32_Socket.h"
    1.40 +#else
    1.41 +#include "OVR_Unix_Socket.h"
    1.42 +#endif
    1.43 +
    1.44 +namespace OVR { namespace Net {
    1.45 +
    1.46 +
    1.47 +//-----------------------------------------------------------------------------
    1.48 +// NetworkPlugin
    1.49 +
    1.50 +// Packetized TCP base socket
    1.51 +class PacketizedTCPSocketBase : public TCPSocket
    1.52 +{
    1.53 +public:
    1.54 +	PacketizedTCPSocketBase() {}
    1.55 +	PacketizedTCPSocketBase(SocketHandle _sock, bool isListenSocket) : TCPSocket(_sock, isListenSocket) {}
    1.56 +};
    1.57 +
    1.58 +
    1.59 +//-----------------------------------------------------------------------------
    1.60 +// PacketizedTCPSocket
    1.61 +
    1.62 +// Uses TCP but is message aligned rather than stream aligned
    1.63 +// Alternative to reliable UDP
    1.64 +class PacketizedTCPSocket : public PacketizedTCPSocketBase
    1.65 +{
    1.66 +public:
    1.67 +	PacketizedTCPSocket();
    1.68 +	PacketizedTCPSocket(SocketHandle _sock, bool isListenSocket);
    1.69 +	virtual ~PacketizedTCPSocket();
    1.70 +
    1.71 +public:
    1.72 +	virtual int Send(const void* pData, int bytes);
    1.73 +	virtual int SendAndConcatenate(const void** pDataArray, int *dataLengthArray, int arrayCount);
    1.74 +
    1.75 +protected:
    1.76 +	virtual void OnRecv(SocketEvent_TCP* eventHandler, uint8_t* pData, int bytesRead);
    1.77 +
    1.78 +	int BytesFromStream(uint8_t* pData, int bytesRead);
    1.79 +
    1.80 +    Lock   sendLock;
    1.81 +    Lock   recvBuffLock;
    1.82 +
    1.83 +	uint8_t* pRecvBuff;     // Queued receive buffered data
    1.84 +	int    pRecvBuffSize; // Size of receive queue in bytes
    1.85 +};
    1.86 +
    1.87 +
    1.88 +}} // OVR::Net
    1.89 +
    1.90 +#endif