Procházet zdrojové kódy

Exposed various kNet connection stats.

Lasse Öörni před 10 roky
rodič
revize
7da3eb5616

+ 12 - 0
Source/Urho3D/LuaScript/pkgs/Network/Connection.pkg

@@ -42,6 +42,12 @@ class Connection : public Object
     bool GetLogStatistics() const;
     bool GetLogStatistics() const;
     String GetAddress() const;
     String GetAddress() const;
     unsigned short GetPort() const;
     unsigned short GetPort() const;
+    float GetRoundTripTime() const;
+    float GetLastHeardTime() const;
+    float GetBytesInPerSec() const;
+    float GetBytesOutPerSec() const;
+    float GetPacketsInPerSec() const;
+    float GetPacketsOutPerSec() const;
     String ToString() const;
     String ToString() const;
     unsigned GetNumDownloads() const;
     unsigned GetNumDownloads() const;
     const String GetDownloadName() const;
     const String GetDownloadName() const;
@@ -60,6 +66,12 @@ class Connection : public Object
     tolua_property__get_set bool logStatistics;
     tolua_property__get_set bool logStatistics;
     tolua_readonly tolua_property__get_set String address;
     tolua_readonly tolua_property__get_set String address;
     tolua_readonly tolua_property__get_set unsigned short port;
     tolua_readonly tolua_property__get_set unsigned short port;
+    tolua_readonly tolua_property__get_set float roundTripTime;
+    tolua_readonly tolua_property__get_set float lastHeardTime;
+    tolua_readonly tolua_property__get_set float bytesInPerSec;
+    tolua_readonly tolua_property__get_set float bytesOutPerSec;
+    tolua_readonly tolua_property__get_set float packetsInPerSec;
+    tolua_readonly tolua_property__get_set float packetsOutPerSec;
     tolua_readonly tolua_property__get_set unsigned numDownloads;
     tolua_readonly tolua_property__get_set unsigned numDownloads;
     tolua_readonly tolua_property__get_set String downloadName;
     tolua_readonly tolua_property__get_set String downloadName;
     tolua_readonly tolua_property__get_set float downloadProgress;
     tolua_readonly tolua_property__get_set float downloadProgress;

+ 30 - 0
Source/Urho3D/Network/Connection.cpp

@@ -996,6 +996,36 @@ bool Connection::IsConnected() const
     return connection_->GetConnectionState() == kNet::ConnectionOK;
     return connection_->GetConnectionState() == kNet::ConnectionOK;
 }
 }
 
 
+float Connection::GetRoundTripTime() const
+{
+    return connection_->RoundTripTime();
+}
+
+float Connection::GetLastHeardTime() const
+{
+    return connection_->LastHeardTime();
+}
+
+float Connection::GetBytesInPerSec() const
+{
+    return connection_->BytesInPerSec();
+}
+
+float Connection::GetBytesOutPerSec() const
+{
+    return connection_->BytesOutPerSec();
+}
+
+float Connection::GetPacketsInPerSec() const
+{
+    return connection_->PacketsInPerSec();
+}
+
+float Connection::GetPacketsOutPerSec() const
+{
+    return connection_->PacketsOutPerSec();
+}
+
 String Connection::ToString() const
 String Connection::ToString() const
 {
 {
     return GetAddress() + ":" + String(GetPort());
     return GetAddress() + ":" + String(GetPort());

+ 18 - 0
Source/Urho3D/Network/Connection.h

@@ -191,6 +191,24 @@ public:
     /// Return remote port.
     /// Return remote port.
     unsigned short GetPort() const { return port_; }
     unsigned short GetPort() const { return port_; }
 
 
+    /// Return the connection's round trip time in milliseconds.
+    float GetRoundTripTime() const;
+
+    /// Return the time since last received data from the remote host in milliseconds.
+    float GetLastHeardTime() const;
+
+    /// Return bytes received per second.
+    float GetBytesInPerSec() const;
+
+    /// Return bytes sent per second.
+    float GetBytesOutPerSec() const;
+
+    /// Return packets received per second.
+    float GetPacketsInPerSec() const;
+
+    /// Return packets sent per second.
+    float GetPacketsOutPerSec() const;
+
     /// Return an address:port string.
     /// Return an address:port string.
     String ToString() const;
     String ToString() const;
     /// Return number of package downloads remaining.
     /// Return number of package downloads remaining.

+ 6 - 0
Source/Urho3D/Script/NetworkAPI.cpp

@@ -73,6 +73,12 @@ static void RegisterConnection(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Connection", "bool get_sceneLoaded() const", asMETHOD(Connection, IsSceneLoaded), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "bool get_sceneLoaded() const", asMETHOD(Connection, IsSceneLoaded), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "String get_address() const", asMETHOD(Connection, GetAddress), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "String get_address() const", asMETHOD(Connection, GetAddress), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "uint16 get_port() const", asMETHOD(Connection, GetPort), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "uint16 get_port() const", asMETHOD(Connection, GetPort), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Connection", "float get_roundTripTime() const", asMETHOD(Connection, GetRoundTripTime), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Connection", "float get_lastHeardTime() const", asMETHOD(Connection, GetLastHeardTime), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Connection", "float get_bytesInPerSec() const", asMETHOD(Connection, GetBytesInPerSec), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Connection", "float get_bytesOutPerSec() const", asMETHOD(Connection, GetBytesOutPerSec), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Connection", "float get_packetsInPerSec() const", asMETHOD(Connection, GetPacketsInPerSec), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Connection", "float get_packetsOutPerSec() const", asMETHOD(Connection, GetPacketsOutPerSec), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "uint get_numDownloads() const", asMETHOD(Connection, GetNumDownloads), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "uint get_numDownloads() const", asMETHOD(Connection, GetNumDownloads), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "const String& get_downloadName() const", asMETHOD(Connection, GetDownloadName), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "const String& get_downloadName() const", asMETHOD(Connection, GetDownloadName), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "float get_downloadProgress() const", asMETHOD(Connection, GetDownloadProgress), asCALL_THISCALL);
     engine->RegisterObjectMethod("Connection", "float get_downloadProgress() const", asMETHOD(Connection, GetDownloadProgress), asCALL_THISCALL);