diff options
Diffstat (limited to 'LibOVR/Src/Net')
-rw-r--r-- | LibOVR/Src/Net/OVR_BitStream.cpp | 14 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_BitStream.h | 12 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_MessageIDTypes.h | 6 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_NetworkPlugin.cpp | 6 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_NetworkPlugin.h | 6 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_NetworkTypes.h | 6 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_PacketizedTCPSocket.cpp | 61 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_PacketizedTCPSocket.h | 6 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_RPC1.cpp | 10 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_RPC1.h | 6 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_Session.cpp | 39 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_Session.h | 35 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_Socket.cpp | 11 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_Socket.h | 10 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_Unix_Socket.cpp | 18 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_Unix_Socket.h | 6 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_Win32_Socket.cpp | 36 | ||||
-rw-r--r-- | LibOVR/Src/Net/OVR_Win32_Socket.h | 6 |
18 files changed, 182 insertions, 112 deletions
diff --git a/LibOVR/Src/Net/OVR_BitStream.cpp b/LibOVR/Src/Net/OVR_BitStream.cpp index b66e9f2..b565f22 100644 --- a/LibOVR/Src/Net/OVR_BitStream.cpp +++ b/LibOVR/Src/Net/OVR_BitStream.cpp @@ -5,16 +5,16 @@ Content : A generic serialization toolkit for packing data to a binary str Created : June 10, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, @@ -696,9 +696,11 @@ void BitStream::AddBitsAndReallocate( const BitSize_t numberOfBitsToWrite ) { data = ( unsigned char* ) OVR_ALLOC( (size_t) amountToAllocate); OVR_ASSERT(data); - - // need to copy the stack data over to our new memory area too - memcpy ((void *)data, (void *)stackData, (size_t) BITS_TO_BYTES( numberOfBitsAllocated )); + if (data) + { + // need to copy the stack data over to our new memory area too + memcpy ((void *)data, (void *)stackData, (size_t) BITS_TO_BYTES( numberOfBitsAllocated )); + } } } else diff --git a/LibOVR/Src/Net/OVR_BitStream.h b/LibOVR/Src/Net/OVR_BitStream.h index 0c7c7b4..f46269f 100644 --- a/LibOVR/Src/Net/OVR_BitStream.h +++ b/LibOVR/Src/Net/OVR_BitStream.h @@ -6,16 +6,16 @@ Content : A generic serialization toolkit for packing data to a binary str Created : June 10, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, @@ -796,13 +796,11 @@ public: private: - BitStream( const BitStream &invalid) { - (void) invalid; + BitStream( const BitStream & /*invalid*/) : numberOfBitsUsed(0), numberOfBitsAllocated(0), readOffset(0),data(NULL), copyData(false) { OVR_ASSERT(0); } - BitStream& operator = ( const BitStream& invalid ) { - (void) invalid; + BitStream& operator = ( const BitStream& /*invalid*/ ) { OVR_ASSERT(0); static BitStream i; return i; diff --git a/LibOVR/Src/Net/OVR_MessageIDTypes.h b/LibOVR/Src/Net/OVR_MessageIDTypes.h index c4fbd20..849f63a 100644 --- a/LibOVR/Src/Net/OVR_MessageIDTypes.h +++ b/LibOVR/Src/Net/OVR_MessageIDTypes.h @@ -5,16 +5,16 @@ Content : Enumeration list indicating what type of message is being sent Created : July 3, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, diff --git a/LibOVR/Src/Net/OVR_NetworkPlugin.cpp b/LibOVR/Src/Net/OVR_NetworkPlugin.cpp index b20c38a..a693499 100644 --- a/LibOVR/Src/Net/OVR_NetworkPlugin.cpp +++ b/LibOVR/Src/Net/OVR_NetworkPlugin.cpp @@ -5,16 +5,16 @@ Content : Base class for an extension to the network objects. Created : June 10, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, diff --git a/LibOVR/Src/Net/OVR_NetworkPlugin.h b/LibOVR/Src/Net/OVR_NetworkPlugin.h index b5675b6..b03b86c 100644 --- a/LibOVR/Src/Net/OVR_NetworkPlugin.h +++ b/LibOVR/Src/Net/OVR_NetworkPlugin.h @@ -6,16 +6,16 @@ Content : Base class for an extension to the network objects. Created : June 10, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, diff --git a/LibOVR/Src/Net/OVR_NetworkTypes.h b/LibOVR/Src/Net/OVR_NetworkTypes.h index 81110e3..401f53a 100644 --- a/LibOVR/Src/Net/OVR_NetworkTypes.h +++ b/LibOVR/Src/Net/OVR_NetworkTypes.h @@ -6,16 +6,16 @@ Content : Shared header for network types Created : June 12, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, diff --git a/LibOVR/Src/Net/OVR_PacketizedTCPSocket.cpp b/LibOVR/Src/Net/OVR_PacketizedTCPSocket.cpp index 815792f..6352480 100644 --- a/LibOVR/Src/Net/OVR_PacketizedTCPSocket.cpp +++ b/LibOVR/Src/Net/OVR_PacketizedTCPSocket.cpp @@ -5,16 +5,16 @@ Content : TCP with automated message framing. Created : June 10, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, @@ -120,8 +120,8 @@ int PacketizedTCPSocket::SendAndConcatenate(const void** pDataArray, int* dataLe void PacketizedTCPSocket::OnRecv(SocketEvent_TCP* eventHandler, uint8_t* pData, int bytesRead) { - uint8_t* dataSource; - int dataSourceSize; + uint8_t* dataSource = NULL; + int dataSourceSize = 0; recvBuffLock.DoLock(); @@ -132,11 +132,24 @@ void PacketizedTCPSocket::OnRecv(SocketEvent_TCP* eventHandler, uint8_t* pData, } else { - pRecvBuff = (uint8_t*)OVR_REALLOC(pRecvBuff, bytesRead + pRecvBuffSize); - memcpy(pRecvBuff + pRecvBuffSize, pData, bytesRead); + uint8_t* pRecvBuffNew = (uint8_t*)OVR_REALLOC(pRecvBuff, bytesRead + pRecvBuffSize); + if (!pRecvBuffNew) + { + OVR_FREE(pRecvBuff); + pRecvBuff = NULL; + pRecvBuffSize = 0; + recvBuffLock.Unlock(); + return; + } + else + { + pRecvBuff = pRecvBuffNew; + + memcpy(pRecvBuff + pRecvBuffSize, pData, bytesRead); - dataSourceSize = pRecvBuffSize + bytesRead; - dataSource = pRecvBuff; + dataSourceSize = pRecvBuffSize + bytesRead; + dataSource = pRecvBuff; + } } int bytesReadFromStream; @@ -154,15 +167,27 @@ void PacketizedTCPSocket::OnRecv(SocketEvent_TCP* eventHandler, uint8_t* pData, if (dataSourceSize > 0) { - if (pRecvBuff == NULL) - { - pRecvBuff = (uint8_t*)OVR_ALLOC(dataSourceSize); - memcpy(pRecvBuff, dataSource, dataSourceSize); - } - else - { - memmove(pRecvBuff, dataSource, dataSourceSize); - } + if (dataSource != NULL) + { + if (pRecvBuff == NULL) + { + pRecvBuff = (uint8_t*)OVR_ALLOC(dataSourceSize); + if (!pRecvBuff) + { + pRecvBuffSize = 0; + recvBuffLock.Unlock(); + return; + } + else + { + memcpy(pRecvBuff, dataSource, dataSourceSize); + } + } + else + { + memmove(pRecvBuff, dataSource, dataSourceSize); + } + } } else { diff --git a/LibOVR/Src/Net/OVR_PacketizedTCPSocket.h b/LibOVR/Src/Net/OVR_PacketizedTCPSocket.h index e6f346d..8052bd3 100644 --- a/LibOVR/Src/Net/OVR_PacketizedTCPSocket.h +++ b/LibOVR/Src/Net/OVR_PacketizedTCPSocket.h @@ -6,16 +6,16 @@ Content : TCP with automated message framing. Created : June 10, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, diff --git a/LibOVR/Src/Net/OVR_RPC1.cpp b/LibOVR/Src/Net/OVR_RPC1.cpp index 477884c..12afb09 100644 --- a/LibOVR/Src/Net/OVR_RPC1.cpp +++ b/LibOVR/Src/Net/OVR_RPC1.cpp @@ -5,16 +5,16 @@ Content : A network plugin that provides remote procedure call functionali Created : June 10, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, @@ -123,6 +123,10 @@ bool RPC1::CallBlocking( OVR::String uniqueID, OVR::Net::BitStream* bitStream, P callBlockingWait.Wait(&callBlockingMutex); } } + else + { + return false; + } if (returnData) { diff --git a/LibOVR/Src/Net/OVR_RPC1.h b/LibOVR/Src/Net/OVR_RPC1.h index d24f26c..6104ccf 100644 --- a/LibOVR/Src/Net/OVR_RPC1.h +++ b/LibOVR/Src/Net/OVR_RPC1.h @@ -6,16 +6,16 @@ Content : A network plugin that provides remote procedure call functionali Created : June 10, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, diff --git a/LibOVR/Src/Net/OVR_Session.cpp b/LibOVR/Src/Net/OVR_Session.cpp index db370b4..508f0c9 100644 --- a/LibOVR/Src/Net/OVR_Session.cpp +++ b/LibOVR/Src/Net/OVR_Session.cpp @@ -5,16 +5,16 @@ Content : One network session that provides connection/disconnection event Created : June 10, 2014 Authors : Kevin Jenkins, Chris Taylor -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, @@ -243,12 +243,9 @@ SessionResult Session::ListenPTCP(OVR::Net::BerkleyBindParameters *bbp) return Listen(&bld); } -SessionResult Session::ConnectPTCP(OVR::Net::BerkleyBindParameters* bbp, SockAddr* RemoteAddress, bool blocking) +SessionResult Session::ConnectPTCP(OVR::Net::BerkleyBindParameters* bbp, SockAddr* remoteAddress, bool blocking) { - ConnectParametersBerkleySocket cp; - cp.RemoteAddress = RemoteAddress; - cp.Transport = TransportType_PacketizedTCP; - cp.Blocking = blocking; + ConnectParametersBerkleySocket cp(NULL, remoteAddress, blocking, TransportType_PacketizedTCP); Ptr<PacketizedTCPSocket> connectSocket = *new PacketizedTCPSocket(); cp.BoundSocketToConnectWith = connectSocket.GetPtr(); @@ -341,9 +338,10 @@ void Session::Broadcast(BroadcastParameters *payload) } } } +// DO NOT CALL Poll() FROM MULTIPLE THREADS due to allBlockingTcpSockets being a member void Session::Poll(bool listeners) { - Array< Ptr< Net::TCPSocket > > allBlockingTcpSockets; + allBlockingTcpSockets.Clear(); if (listeners) { @@ -513,11 +511,14 @@ int Session::invokeSessionListeners(ReceivePayload* rp) void Session::TCP_OnRecv(Socket* pSocket, uint8_t* pData, int bytesRead) { - Lock::Locker locker(&ConnectionsLock); + // KevinJ: 9/2/2014 Fix deadlock - Watchdog calls Broadcast(), which locks ConnectionsLock(). + // Lock::Locker locker(&ConnectionsLock); // Look for the connection in the full connection list first int connIndex; - PacketizedTCPConnection* conn = findConnectionBySocket(AllConnections, pSocket, &connIndex); + ConnectionsLock.DoLock(); + Ptr<PacketizedTCPConnection> conn = findConnectionBySocket(AllConnections, pSocket, &connIndex); + ConnectionsLock.Unlock(); if (conn) { if (conn->State == State_Connected) @@ -553,7 +554,13 @@ void Session::TCP_OnRecv(Socket* pSocket, uint8_t* pData, int bytesRead) // Mark as connected conn->SetState(State_Connected); - FullConnections.PushBack(conn); + ConnectionsLock.DoLock(); + int connIndex2; + if (findConnectionBySocket(AllConnections, pSocket, &connIndex2)==conn && findConnectionBySocket(FullConnections, pSocket, &connIndex2)==NULL) + { + FullConnections.PushBack(conn); + } + ConnectionsLock.Unlock(); invokeSessionEvent(&SessionListener::OnConnectionRequestAccepted, conn); } } @@ -591,7 +598,13 @@ void Session::TCP_OnRecv(Socket* pSocket, uint8_t* pData, int bytesRead) // Mark as connected conn->SetState(State_Connected); - FullConnections.PushBack(conn); + ConnectionsLock.DoLock(); + int connIndex2; + if (findConnectionBySocket(AllConnections, pSocket, &connIndex2)==conn && findConnectionBySocket(FullConnections, pSocket, &connIndex2)==NULL) + { + FullConnections.PushBack(conn); + } + ConnectionsLock.Unlock(); invokeSessionEvent(&SessionListener::OnNewIncomingConnection, conn); } diff --git a/LibOVR/Src/Net/OVR_Session.h b/LibOVR/Src/Net/OVR_Session.h index 8bd0b24..c343980 100644 --- a/LibOVR/Src/Net/OVR_Session.h +++ b/LibOVR/Src/Net/OVR_Session.h @@ -6,16 +6,16 @@ Content : One network session that provides connection/disconnection event Created : June 10, 2014 Authors : Kevin Jenkins, Chris Taylor -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, @@ -304,7 +304,7 @@ public: struct ReceivePayload { Connection* pConnection; // Source connection - uint8_t* pData; // Pointer to data received + uint8_t* pData; // Pointer to data received int Bytes; // Number of bytes of data received }; @@ -371,16 +371,15 @@ struct ConnectParametersBerkleySocket : public ConnectParameters { SockAddr RemoteAddress; Ptr<BerkleySocket> BoundSocketToConnectWith; - bool Blocking; + bool Blocking; - ConnectParametersBerkleySocket() + ConnectParametersBerkleySocket(BerkleySocket* s, SockAddr* addr, bool blocking, + TransportType transport) : + RemoteAddress(*addr), + BoundSocketToConnectWith(s), + Blocking(blocking) { - } - - ConnectParametersBerkleySocket(Socket* s, SockAddr* addr) : - RemoteAddress(*addr) - { - BoundSocketToConnectWith = (BerkleySocket*)s; + Transport = transport; } }; @@ -407,6 +406,8 @@ enum ListenerReceiveResult class SessionListener { public: + virtual ~SessionListener(){} + // Data events virtual void OnReceive(ReceivePayload* pPayload, ListenerReceiveResult* lrrOut) { OVR_UNUSED2(pPayload, lrrOut); } @@ -441,6 +442,12 @@ public: // Interface for network events such as listening on a socket, sending data, connecting, and disconnecting. Works independently of the transport medium and also implements loopback class Session : public SocketEvent_TCP, public NewOverrideBase { + // Implement a policy to avoid releasing memory backing allBlockingTcpSockets + struct ArrayNoShrinkPolicy : ArrayDefaultPolicy + { + bool NeverShrinking() const { return 1; } + }; + public: Session() : HasLoopbackListener(false) @@ -448,12 +455,15 @@ public: } virtual ~Session() { + // Ensure memory backing the sockets array is released + allBlockingTcpSockets.ClearAndRelease(); } virtual SessionResult Listen(ListenerDescription* pListenerDescription); virtual SessionResult Connect(ConnectParameters* cp); virtual int Send(SendParameters* payload); virtual void Broadcast(BroadcastParameters* payload); + // DO NOT CALL Poll() FROM MULTIPLE THREADS due to allBlockingTcpSockets being a member virtual void Poll(bool listeners = true); virtual void AddSessionListener(SessionListener* se); virtual void RemoveSessionListener(SessionListener* se); @@ -482,6 +492,7 @@ protected: Array< Ptr<Connection> > AllConnections; // List of active connections stuck at the versioning handshake Array< Ptr<Connection> > FullConnections; // List of active connections past the versioning handshake Array< SessionListener* > SessionListeners; // List of session listeners + Array< Ptr< Net::TCPSocket >, ArrayNoShrinkPolicy > allBlockingTcpSockets; // Preallocated blocking sockets array // Tools Ptr<PacketizedTCPConnection> findConnectionBySocket(Array< Ptr<Connection> >& connectionArray, Socket* s, int *connectionIndex = NULL); // Call with ConnectionsLock held diff --git a/LibOVR/Src/Net/OVR_Socket.cpp b/LibOVR/Src/Net/OVR_Socket.cpp index 3390d8d..d0b4e77 100644 --- a/LibOVR/Src/Net/OVR_Socket.cpp +++ b/LibOVR/Src/Net/OVR_Socket.cpp @@ -5,16 +5,16 @@ Content : Socket common data shared between all platforms. Created : June 10, 2014 Authors : Kevin Jenkins, Chris Taylor -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, @@ -43,6 +43,7 @@ Socket::Socket() : BerkleyBindParameters::BerkleyBindParameters() : Port(0), + Address(), blockingTimeout(0x7fffffff) { } @@ -52,6 +53,8 @@ BerkleyBindParameters::BerkleyBindParameters() : BerkleySocket::BerkleySocket() : TheSocket(INVALID_SOCKET) + //TimeoutUsec(0) // Initialized by SetBlockingTimeout + //TimeoutSec(0) // " { SetBlockingTimeout(1000); } @@ -76,11 +79,13 @@ UDPSocketBase::UDPSocketBase() // TCPSocketBase TCPSocketBase::TCPSocketBase() + : IsListenSocket(false) { Transport = TransportType_TCP; } TCPSocketBase::TCPSocketBase(SocketHandle handle) + : IsListenSocket(false) { TheSocket = handle; } diff --git a/LibOVR/Src/Net/OVR_Socket.h b/LibOVR/Src/Net/OVR_Socket.h index b572e54..b02e038 100644 --- a/LibOVR/Src/Net/OVR_Socket.h +++ b/LibOVR/Src/Net/OVR_Socket.h @@ -6,16 +6,16 @@ Content : Socket common data shared between all platforms. Created : June 10, 2014 Authors : Kevin Jenkins, Chris Taylor -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, @@ -147,6 +147,8 @@ protected: class SocketEvent_UDP { public: + virtual ~SocketEvent_UDP(){} + virtual void UDP_OnRecv(Socket* pSocket, uint8_t* pData, uint32_t bytesRead, SockAddr* pSockAddr) { @@ -160,6 +162,8 @@ public: class SocketEvent_TCP { public: + virtual ~SocketEvent_TCP(){} + virtual void TCP_OnRecv (Socket* pSocket, uint8_t* pData, int bytesRead) diff --git a/LibOVR/Src/Net/OVR_Unix_Socket.cpp b/LibOVR/Src/Net/OVR_Unix_Socket.cpp index 6370671..6f2a678 100644 --- a/LibOVR/Src/Net/OVR_Unix_Socket.cpp +++ b/LibOVR/Src/Net/OVR_Unix_Socket.cpp @@ -5,16 +5,16 @@ Content : Berkley sockets networking implementation Created : July 1, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, @@ -119,7 +119,6 @@ void SockAddr::Set(const char* hostAddress, UInt16 port, int sockType) { memset(&Addr6, 0, sizeof(Addr6)); - struct addrinfo* servinfo = 0; // will point to the results struct addrinfo hints; // make sure the struct is empty @@ -138,6 +137,8 @@ void SockAddr::Set(const char* hostAddress, UInt16 port, int sockType) hints.ai_protocol = IPPROTO_TCP; } + struct addrinfo* servinfo = NULL; // will point to the results + char portStr[32]; OVR_itoa(port, portStr, sizeof(portStr), 10); int errcode = getaddrinfo(hostAddress, portStr, &hints, &servinfo); @@ -147,11 +148,14 @@ void SockAddr::Set(const char* hostAddress, UInt16 port, int sockType) OVR::LogError("getaddrinfo error: %s", gai_strerror(errcode)); } - OVR_ASSERT(0 != servinfo); + OVR_ASSERT(servinfo); - memcpy(&Addr6, servinfo->ai_addr, sizeof(Addr6)); + if (servinfo) + { + memcpy(&Addr6, servinfo->ai_addr, sizeof(Addr6)); - freeaddrinfo(servinfo); + freeaddrinfo(servinfo); + } } UInt16 SockAddr::GetPort() diff --git a/LibOVR/Src/Net/OVR_Unix_Socket.h b/LibOVR/Src/Net/OVR_Unix_Socket.h index faec464..90ee515 100644 --- a/LibOVR/Src/Net/OVR_Unix_Socket.h +++ b/LibOVR/Src/Net/OVR_Unix_Socket.h @@ -6,16 +6,16 @@ Content : Berkley sockets networking implementation Created : July 1, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, diff --git a/LibOVR/Src/Net/OVR_Win32_Socket.cpp b/LibOVR/Src/Net/OVR_Win32_Socket.cpp index 36b83ca..3d39a34 100644 --- a/LibOVR/Src/Net/OVR_Win32_Socket.cpp +++ b/LibOVR/Src/Net/OVR_Win32_Socket.cpp @@ -5,16 +5,16 @@ Content : Windows-specific socket-based networking implementation Created : June 10, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, @@ -178,7 +178,6 @@ void SockAddr::Set(const char* hostAddress, uint16_t port, int sockType) { memset(&Addr6, 0, sizeof(Addr6)); - struct addrinfo* servinfo = 0; // will point to the results struct addrinfo hints; // make sure the struct is empty @@ -194,6 +193,8 @@ void SockAddr::Set(const char* hostAddress, uint16_t port, int sockType) // now instead of introducing another variable. hints.ai_protocol = IPPROTO_IPV6; + struct addrinfo* servinfo = NULL; // will point to the results + char portStr[32]; OVR_itoa(port, portStr, sizeof(portStr), 10); int errcode = getaddrinfo(hostAddress, portStr, &hints, &servinfo); @@ -203,11 +204,14 @@ void SockAddr::Set(const char* hostAddress, uint16_t port, int sockType) OVR::LogError("{ERR-008w} getaddrinfo error: %s", gai_strerror(errcode)); } - OVR_ASSERT(0 != servinfo); + OVR_ASSERT(servinfo); - memcpy(&Addr6, servinfo->ai_addr, sizeof(Addr6)); + if (servinfo) + { + memcpy(&Addr6, servinfo->ai_addr, sizeof(Addr6)); - freeaddrinfo(servinfo); + freeaddrinfo(servinfo); + } } uint16_t SockAddr::GetPort() @@ -275,17 +279,17 @@ static bool SetSocketOptions(SocketHandle sock) int sock_opt; // This doubles the max throughput rate - sock_opt=1024*256; + sock_opt = 1024 * 256; result |= setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)& sock_opt, sizeof (sock_opt)); // Immediate hard close. Don't linger the socket, or recreating the socket quickly on Vista fails. - // Fail with voice - sock_opt=0; + // Fail with voice and xbox + sock_opt = 0; result |= setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)& sock_opt, sizeof (sock_opt)); // This doesn't make much difference: 10% maybe // Not supported on console 2 - sock_opt=1024*16; + sock_opt = 1024 * 16; result |= setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)& sock_opt, sizeof (sock_opt)); // If all the setsockopt() returned 0 there were no failures, so return true for success, else false @@ -294,10 +298,10 @@ static bool SetSocketOptions(SocketHandle sock) void _Ioctlsocket(SocketHandle sock, unsigned long nonblocking) { - ioctlsocket( sock, FIONBIO, &nonblocking ); + ioctlsocket(sock, FIONBIO, &nonblocking); } -static SocketHandle BindShared(int ai_family, int ai_socktype, BerkleyBindParameters *pBindParameters) +static SocketHandle BindShared(int ai_family, int ai_socktype, BerkleyBindParameters* pBindParameters) { SocketHandle sock; @@ -337,9 +341,9 @@ static SocketHandle BindShared(int ai_family, int ai_socktype, BerkleyBindParame return sock; } - closesocket(sock); - } - } + closesocket(sock); + } + } if (servinfo) { freeaddrinfo(servinfo); } return INVALID_SOCKET; diff --git a/LibOVR/Src/Net/OVR_Win32_Socket.h b/LibOVR/Src/Net/OVR_Win32_Socket.h index 6da8084..b0dd02f 100644 --- a/LibOVR/Src/Net/OVR_Win32_Socket.h +++ b/LibOVR/Src/Net/OVR_Win32_Socket.h @@ -6,16 +6,16 @@ Content : Windows-specific socket-based networking implementation Created : June 10, 2014 Authors : Kevin Jenkins -Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved. +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. -Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License"); +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at -http://www.oculusvr.com/licenses/LICENSE-3.1 +http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, |