nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: PublicHeader: n/a nuclear@0: Filename : OVR_PacketizedTCPSocket.cpp nuclear@0: Content : TCP with automated message framing. nuclear@0: Created : June 10, 2014 nuclear@0: Authors : Kevin Jenkins nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: ************************************************************************************/ nuclear@0: nuclear@0: #ifndef OVR_PacketizedTCPSocket_h nuclear@0: #define OVR_PacketizedTCPSocket_h nuclear@0: nuclear@0: #include "OVR_Socket.h" nuclear@0: #include "../Kernel/OVR_Allocator.h" nuclear@0: #include "../Kernel/OVR_Atomic.h" nuclear@0: nuclear@0: #ifdef OVR_OS_WIN32 nuclear@0: #include "OVR_Win32_Socket.h" nuclear@0: #else nuclear@0: #include "OVR_Unix_Socket.h" nuclear@0: #endif nuclear@0: nuclear@0: namespace OVR { namespace Net { nuclear@0: nuclear@0: nuclear@0: //----------------------------------------------------------------------------- nuclear@0: // NetworkPlugin nuclear@0: nuclear@0: // Packetized TCP base socket nuclear@0: class PacketizedTCPSocketBase : public TCPSocket nuclear@0: { nuclear@0: public: nuclear@0: PacketizedTCPSocketBase() {} nuclear@0: PacketizedTCPSocketBase(SocketHandle _sock, bool isListenSocket) : TCPSocket(_sock, isListenSocket) {} nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: //----------------------------------------------------------------------------- nuclear@0: // PacketizedTCPSocket nuclear@0: nuclear@0: // Uses TCP but is message aligned rather than stream aligned nuclear@0: // Alternative to reliable UDP nuclear@0: class PacketizedTCPSocket : public PacketizedTCPSocketBase nuclear@0: { nuclear@0: public: nuclear@0: PacketizedTCPSocket(); nuclear@0: PacketizedTCPSocket(SocketHandle _sock, bool isListenSocket); nuclear@0: virtual ~PacketizedTCPSocket(); nuclear@0: nuclear@0: public: nuclear@0: virtual int Send(const void* pData, int bytes); nuclear@0: virtual int SendAndConcatenate(const void** pDataArray, int *dataLengthArray, int arrayCount); nuclear@0: nuclear@0: protected: nuclear@0: virtual void OnRecv(SocketEvent_TCP* eventHandler, uint8_t* pData, int bytesRead); nuclear@0: nuclear@0: int BytesFromStream(uint8_t* pData, int bytesRead); nuclear@0: nuclear@0: Lock sendLock; nuclear@0: Lock recvBuffLock; nuclear@0: nuclear@0: uint8_t* pRecvBuff; // Queued receive buffered data nuclear@0: int pRecvBuffSize; // Size of receive queue in bytes nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: }} // OVR::Net nuclear@0: nuclear@0: #endif