summaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/Net
diff options
context:
space:
mode:
authorBrad Davis <[email protected]>2014-09-04 14:32:18 -0700
committerBrad Davis <[email protected]>2014-09-04 14:32:18 -0700
commit32dc394487af8e4fb1b43fb852f1d5448eaf7f31 (patch)
treebe53f49e96e8e2bba1dada04197cf508b60b4eaf /LibOVR/Src/Net
parent85d370840fa4d49a63331a203460fe763288d417 (diff)
Updating to windows 0.4.2
Diffstat (limited to 'LibOVR/Src/Net')
-rw-r--r--LibOVR/Src/Net/OVR_NetworkPlugin.h1
-rw-r--r--LibOVR/Src/Net/OVR_RPC1.cpp8
-rw-r--r--LibOVR/Src/Net/OVR_RPC1.h2
-rw-r--r--LibOVR/Src/Net/OVR_Session.cpp56
-rw-r--r--LibOVR/Src/Net/OVR_Session.h44
-rw-r--r--LibOVR/Src/Net/OVR_Win32_Socket.cpp34
6 files changed, 91 insertions, 54 deletions
diff --git a/LibOVR/Src/Net/OVR_NetworkPlugin.h b/LibOVR/Src/Net/OVR_NetworkPlugin.h
index c56eda3..b5675b6 100644
--- a/LibOVR/Src/Net/OVR_NetworkPlugin.h
+++ b/LibOVR/Src/Net/OVR_NetworkPlugin.h
@@ -32,6 +32,7 @@ limitations under the License.
namespace OVR { namespace Net { namespace Plugins {
+
//-----------------------------------------------------------------------------
// NetworkPlugin
diff --git a/LibOVR/Src/Net/OVR_RPC1.cpp b/LibOVR/Src/Net/OVR_RPC1.cpp
index 0568e2f..477884c 100644
--- a/LibOVR/Src/Net/OVR_RPC1.cpp
+++ b/LibOVR/Src/Net/OVR_RPC1.cpp
@@ -58,7 +58,7 @@ RPC1::~RPC1()
delete blockingReturnValue;
}
-void RPC1::RegisterSlot(OVR::String sharedIdentifier, OVR::Observer<RPCSlot> *rpcSlotObserver )
+void RPC1::RegisterSlot(OVR::String sharedIdentifier, OVR::Observer<RPCSlot>* rpcSlotObserver )
{
slotHash.AddObserverToSubject(sharedIdentifier, rpcSlotObserver);
}
@@ -77,7 +77,7 @@ void RPC1::UnregisterBlockingFunction(OVR::String uniqueID)
registeredBlockingFunctions.Remove(uniqueID);
}
-bool RPC1::CallBlocking( OVR::String uniqueID, OVR::Net::BitStream * bitStream, Ptr<Connection> pConnection, OVR::Net::BitStream *returnData )
+bool RPC1::CallBlocking( OVR::String uniqueID, OVR::Net::BitStream* bitStream, Ptr<Connection> pConnection, OVR::Net::BitStream* returnData )
{
// If invalid parameters,
if (!pConnection)
@@ -133,7 +133,7 @@ bool RPC1::CallBlocking( OVR::String uniqueID, OVR::Net::BitStream * bitStream,
return true;
}
-bool RPC1::Signal(OVR::String sharedIdentifier, OVR::Net::BitStream * bitStream, Ptr<Connection> pConnection)
+bool RPC1::Signal(OVR::String sharedIdentifier, OVR::Net::BitStream* bitStream, Ptr<Connection> pConnection)
{
OVR::Net::BitStream out;
out.Write((MessageID) OVRID_RPC1);
@@ -150,7 +150,7 @@ bool RPC1::Signal(OVR::String sharedIdentifier, OVR::Net::BitStream * bitStream,
int32_t bytesSent = pSession->Send(&sp);
return bytesSent == sp.Bytes;
}
-void RPC1::BroadcastSignal(OVR::String sharedIdentifier, OVR::Net::BitStream * bitStream)
+void RPC1::BroadcastSignal(OVR::String sharedIdentifier, OVR::Net::BitStream* bitStream)
{
OVR::Net::BitStream out;
out.Write((MessageID) OVRID_RPC1);
diff --git a/LibOVR/Src/Net/OVR_RPC1.h b/LibOVR/Src/Net/OVR_RPC1.h
index 2e5b1db..d24f26c 100644
--- a/LibOVR/Src/Net/OVR_RPC1.h
+++ b/LibOVR/Src/Net/OVR_RPC1.h
@@ -44,7 +44,7 @@ typedef Delegate2<void, BitStream*, ReceivePayload*> RPCSlot;
// typedef void ( *Slot ) ( OVR::Net::BitStream *userData, OVR::Net::ReceivePayload *pPayload );
/// NetworkPlugin that maps strings to function pointers. Can invoke the functions using blocking calls with return values, or signal/slots. Networked parameters serialized with BitStream
-class RPC1 : public NetworkPlugin
+class RPC1 : public NetworkPlugin, public NewOverrideBase
{
public:
RPC1();
diff --git a/LibOVR/Src/Net/OVR_Session.cpp b/LibOVR/Src/Net/OVR_Session.cpp
index 29c96e6..db370b4 100644
--- a/LibOVR/Src/Net/OVR_Session.cpp
+++ b/LibOVR/Src/Net/OVR_Session.cpp
@@ -55,10 +55,17 @@ bool RPC_C2S_Hello::Validate()
HelloString.CompareNoCase(OfficialHelloString) == 0;
}
-void RPC_S2C_Authorization::Generate(Net::BitStream* bs)
+void RPC_S2C_Authorization::Generate(Net::BitStream* bs, String errorString)
{
RPC_S2C_Authorization auth;
- auth.AuthString = OfficialAuthorizedString;
+ if (errorString.IsEmpty())
+ {
+ auth.AuthString = OfficialAuthorizedString;
+ }
+ else
+ {
+ auth.AuthString = errorString;
+ }
auth.MajorVersion = RPCVersion_Major;
auth.MinorVersion = RPCVersion_Minor;
auth.PatchVersion = RPCVersion_Patch;
@@ -169,17 +176,25 @@ SessionResult Session::Connect(ConnectParameters *cp)
AllConnections.PushBack(c);
}
-
+
if (cp2->Blocking)
{
c->WaitOnConnecting();
+ }
- if (c->State == State_Connected)
- return SessionResult_OK;
- else
- return SessionResult_ConnectFailure;
+ if (c->State == State_Connected)
+ {
+ return SessionResult_OK;
}
- }
+ else if (c->State == Client_Connecting)
+ {
+ return SessionResult_ConnectInProgress;
+ }
+ else
+ {
+ return SessionResult_ConnectFailure;
+ }
+ }
else if (cp->Transport == TransportType_Loopback)
{
if (HasLoopbackListener)
@@ -284,8 +299,10 @@ int Session::Send(SendParameters *payload)
rp.pData = (uint8_t*)payload->pData; // FIXME
ListenerReceiveResult lrr = LRR_CONTINUE;
sl->OnReceive(&rp, &lrr);
- if (lrr==LRR_RETURN)
- return payload->Bytes;
+ if (lrr == LRR_RETURN)
+ {
+ return payload->Bytes;
+ }
else if (lrr == LRR_BREAK)
{
break;
@@ -522,11 +539,10 @@ void Session::TCP_OnRecv(Socket* pSocket, uint8_t* pData, int bytesRead)
if (!auth.Deserialize(&bsIn) ||
!auth.Validate())
{
+ LogError("{ERR-001} [Session] REJECTED: OVRService did not authorize us: %s", auth.AuthString.ToCStr());
+
conn->SetState(State_Zombie);
invokeSessionEvent(&SessionListener::OnIncompatibleProtocol, conn);
-
- LogError("[Session] REJECTED: Server did not respond with a valid authorization message");
- AllConnections.RemoveAtUnordered(connIndex);
}
else
{
@@ -550,13 +566,16 @@ void Session::TCP_OnRecv(Socket* pSocket, uint8_t* pData, int bytesRead)
if (!hello.Deserialize(&bsIn) ||
!hello.Validate())
{
- conn->SetState(State_Zombie);
- invokeSessionEvent(&SessionListener::OnIncompatibleProtocol, conn);
-
- LogError("[Session] REJECTED: Rift application is using an incompatible version %d.%d.%d (my version=%d.%d.%d)",
+ LogError("{ERR-002} [Session] REJECTED: Rift application is using an incompatible version %d.%d.%d (my version=%d.%d.%d)",
hello.MajorVersion, hello.MinorVersion, hello.PatchVersion,
RPCVersion_Major, RPCVersion_Minor, RPCVersion_Patch);
- AllConnections.RemoveAtUnordered(connIndex);
+
+ conn->SetState(State_Zombie);
+
+ // Send auth response
+ BitStream bsOut;
+ RPC_S2C_Authorization::Generate(&bsOut, "Incompatible protocol version. Please make sure your OVRService and SDK are both up to date.");
+ conn->pSocket->Send(bsOut.GetData(), bsOut.GetNumberOfBytesUsed());
}
else
{
@@ -612,6 +631,7 @@ void Session::TCP_OnClosed(TCPSocket* s)
invokeSessionEvent(&SessionListener::OnHandshakeAttemptFailed, conn);
break;
case State_Connected:
+ case State_Zombie:
invokeSessionEvent(&SessionListener::OnDisconnected, conn);
break;
default:
diff --git a/LibOVR/Src/Net/OVR_Session.h b/LibOVR/Src/Net/OVR_Session.h
index 8f709eb..8bd0b24 100644
--- a/LibOVR/Src/Net/OVR_Session.h
+++ b/LibOVR/Src/Net/OVR_Session.h
@@ -44,11 +44,13 @@ class Session;
// Based on Semantic Versioning ( http://semver.org/ )
//
// Please update changelog below:
-// 1.0.0 - Initial DK2 release version (July 21, 2014) -catid
+// 1.0.0 - [SDK 0.4.0] Initial version (July 21, 2014)
+// 1.1.0 - Add Get/SetDriverMode_1, HMDCountUpdate_1
+// Version mismatch results (July 28, 2014)
//-----------------------------------------------------------------------------
static const uint16_t RPCVersion_Major = 1; // MAJOR version when you make incompatible API changes,
-static const uint16_t RPCVersion_Minor = 0; // MINOR version when you add functionality in a backwards-compatible manner, and
+static const uint16_t RPCVersion_Minor = 1; // MINOR version when you add functionality in a backwards-compatible manner, and
static const uint16_t RPCVersion_Patch = 0; // PATCH version when you make backwards-compatible bug fixes.
// Client starts communication by sending its version number.
@@ -118,7 +120,7 @@ struct RPC_S2C_Authorization
return bs->Read(PatchVersion);
}
- static void Generate(Net::BitStream* bs);
+ static void Generate(Net::BitStream* bs, String errorString = "");
bool Validate();
};
@@ -132,6 +134,7 @@ enum SessionResult
SessionResult_BindFailure,
SessionResult_ListenFailure,
SessionResult_ConnectFailure,
+ SessionResult_ConnectInProgress,
SessionResult_AlreadyConnected,
};
@@ -196,28 +199,37 @@ protected:
}
public:
- virtual void SetState(EConnectionState s) {
- if (s==State)
- return;
+ virtual void SetState(EConnectionState s)
+ {
+ if (s != State)
+ {
+ Mutex::Locker locker(&StateMutex);
- Mutex::Locker locker(&StateMutex);
- State = s;
- if (State != Client_Connecting)
- ConnectingWait.NotifyAll();
+ if (s != State)
+ {
+ State = s;
+
+ if (State != Client_Connecting)
+ {
+ ConnectingWait.NotifyAll();
+ }
+ }
+ }
}
- void WaitOnConnecting() {
+ void WaitOnConnecting()
+ {
+ Mutex::Locker locker(&StateMutex);
+
while (State == Client_Connecting)
{
- Mutex::Locker locker(&StateMutex);
ConnectingWait.Wait(&StateMutex);
}
}
- SockAddr Address;
-
- OVR::Mutex StateMutex;
- OVR::WaitCondition ConnectingWait;
+ SockAddr Address;
+ Mutex StateMutex;
+ WaitCondition ConnectingWait;
};
diff --git a/LibOVR/Src/Net/OVR_Win32_Socket.cpp b/LibOVR/Src/Net/OVR_Win32_Socket.cpp
index e2705fe..36b83ca 100644
--- a/LibOVR/Src/Net/OVR_Win32_Socket.cpp
+++ b/LibOVR/Src/Net/OVR_Win32_Socket.cpp
@@ -65,7 +65,7 @@ void WSAStartupSingleton::AddRef()
// If an error code is returned
if (errCode != 0)
{
- LogError("[Socket] Unable to initialize Winsock %d", errCode);
+ LogError("{ERR-007w} [Socket] Unable to initialize Winsock %d", errCode);
}
}
}
@@ -135,6 +135,9 @@ BitStream& operator>>(BitStream& in, SockAddr& out)
SockAddr::SockAddr()
{
WSAStartupSingleton::AddRef();
+
+ // Zero out the address to squelch static analysis tools
+ ZeroMemory(&Addr6, sizeof(Addr6));
}
SockAddr::SockAddr(SockAddr* address)
@@ -197,7 +200,7 @@ void SockAddr::Set(const char* hostAddress, uint16_t port, int sockType)
if (0 != errcode)
{
- OVR::LogError("getaddrinfo error: %s", gai_strerror(errcode));
+ OVR::LogError("{ERR-008w} getaddrinfo error: %s", gai_strerror(errcode));
}
OVR_ASSERT(0 != servinfo);
@@ -266,25 +269,29 @@ bool SockAddr::operator<( const SockAddr& right ) const
return memcmp(&Addr6, &right.Addr6, sizeof(Addr6)) < 0;
}
-
-static void SetSocketOptions(SocketHandle sock)
+static bool SetSocketOptions(SocketHandle sock)
{
+ int result = 0;
int sock_opt;
// This doubles the max throughput rate
sock_opt=1024*256;
- setsockopt(sock, SOL_SOCKET, SO_RCVBUF, ( char * ) & sock_opt, sizeof ( sock_opt ) );
+ 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;
- setsockopt(sock, SOL_SOCKET, SO_LINGER, ( char * ) & sock_opt, sizeof ( sock_opt ) );
+ 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;
- setsockopt(sock, SOL_SOCKET, SO_SNDBUF, ( char * ) & sock_opt, sizeof ( sock_opt ) );
+ 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
+ return result == 0;
}
+
void _Ioctlsocket(SocketHandle sock, unsigned long nonblocking)
{
ioctlsocket( sock, FIONBIO, &nonblocking );
@@ -311,7 +318,7 @@ static SocketHandle BindShared(int ai_family, int ai_socktype, BerkleyBindParame
if (0 != errcode)
{
- OVR::LogError("getaddrinfo error: %s", gai_strerror(errcode));
+ OVR::LogError("{ERR-020w} getaddrinfo error: %s", gai_strerror(errcode));
}
for (aip = servinfo; aip != NULL; aip = aip->ai_next)
@@ -319,10 +326,9 @@ static SocketHandle BindShared(int ai_family, int ai_socktype, BerkleyBindParame
// Open socket. The address type depends on what
// getaddrinfo() gave us.
sock = socket(aip->ai_family, aip->ai_socktype, aip->ai_protocol);
- if (sock != 0)
+ if (sock != INVALID_SOCKET)
{
- int ret = bind( sock, aip->ai_addr, (int) aip->ai_addrlen );
- if (ret>=0)
+ if (bind(sock, aip->ai_addr, (int)aip->ai_addrlen) != SOCKET_ERROR)
{
// The actual socket is always non-blocking
// I control blocking or not using WSAEventSelect
@@ -330,12 +336,10 @@ static SocketHandle BindShared(int ai_family, int ai_socktype, BerkleyBindParame
freeaddrinfo(servinfo);
return sock;
}
- else
- {
+
closesocket(sock);
}
}
- }
if (servinfo) { freeaddrinfo(servinfo); }
return INVALID_SOCKET;
@@ -583,7 +587,7 @@ void TCPSocketPollState::HandleEvent(TCPSocket* tcpSocket, SocketEvent_TCP* even
socklen_t sockAddrSize = sizeof(sockAddr);
SocketHandle newSock = accept(handle, (sockaddr*)&sockAddr, (socklen_t*)&sockAddrSize);
- if (newSock > 0)
+ if (newSock != INVALID_SOCKET)
{
SockAddr sa(&sockAddr);
eventHandler->TCP_OnAccept(tcpSocket, &sa, newSock);