Просмотр исходного кода

服务端websocket收消息使用ValueWebSocketReceiveResult减少gc

tanghai 7 лет назад
Родитель
Сommit
b1f5e6cd48

+ 1 - 1
Unity/Assets/Scripts/Module/AssetsBundle/BundleDownloaderComponent.cs

@@ -51,7 +51,7 @@ namespace ETModel
 			}
 			catch (Exception e)
 			{
-				throw new Exception($"url: {versionUrl}");
+				throw new Exception($"url: {versionUrl}", e);
 			}
 
 			// 获取streaming目录的Version.txt

+ 7 - 2
Unity/Assets/Scripts/Module/Message/Network/WebSocket/WChannel.cs

@@ -172,7 +172,12 @@ namespace ETModel
                 {
                     try
                     {
-                        var receiveResult = await this.webSocket.ReceiveAsync(new ArraySegment<byte>(this.Stream.GetBuffer(), 0, this.Stream.Capacity), cancellationTokenSource.Token);
+#if SERVER
+                        ValueWebSocketReceiveResult receiveResult = await this.webSocket.ReceiveAsync(new Memory<byte>(this.Stream.GetBuffer(), 0, this.Stream.Capacity), cancellationTokenSource.Token);
+#else
+                        WebSocketReceiveResult receiveResult = await this.webSocket.ReceiveAsync(new ArraySegment<byte>(this.Stream.GetBuffer(), 0, this.Stream.Capacity), cancellationTokenSource.Token);
+#endif
+                        
                         if (this.IsDisposed)
                         {
                             return;
@@ -193,7 +198,7 @@ namespace ETModel
                         this.Stream.SetLength(receiveResult.Count);
                         this.OnRead(this.Stream);
                     }
-                    catch (Exception e)
+                    catch (Exception)
                     {
                         this.OnError(ErrorCode.ERR_WebsocketRecvError);
                         return;

+ 2 - 1
Unity/Assets/Scripts/Module/Message/OpcodeTypeComponent.cs

@@ -68,8 +68,9 @@ namespace ETModel
 #if SERVER
 			Type type = this.GetType(opcode);
 			return Activator.CreateInstance(type);
-#endif
+#else
 			return this.typeMessages[opcode];
+#endif
 		}
 
 		public override void Dispose()