Esempio n. 1
0
 public NetworkProtocol.Packet Read()
 {
     lock (this)
     {
         NetworkProtocol.Packet ret = null;
         TryRead(out ret);
         return(ret);
     }
 }
Esempio n. 2
0
 public NetworkProtocol.Packet Read()
 {
     if (_cancelation.IsCancellationRequested)
     {
         return(null);
     }
     NetworkProtocol.Packet pack = null;
     _packetQueue.TryDequeue(out pack);
     return(pack);
 }
Esempio n. 3
0
        public void Intercept(IInvocation invocation)
        {
#pragma warning disable CC0008 // Use object initializer
            var packet = new NetworkProtocol.Packet();
            packet.Name       = invocation.Method.Name;
            packet.Parameters = invocation.Method.GetParameters()
                                .Select(x => new NetworkProtocol.MethodParameter {
                Name  = x.Name,
                Value = invocation.GetArgumentValue(x.Position)
            })
                                .Where(x => x.Value != null)
                                .ToArray();
            _socket.Write(packet);
#pragma warning restore CC0008 // Use object initializer
        }
Esempio n. 4
0
 private bool TryWrite(NetworkProtocol.Packet packet)
 {
     try
     {
         if (_socket == null)
         {
             return(false);
         }
         _socket.Write(packet);
         return(true);
     }
     catch
     {
     }
     return(false);
 }
Esempio n. 5
0
 private bool TryRead(out NetworkProtocol.Packet packet)
 {
     packet = null;
     try
     {
         if (_socket == null)
         {
             return(false);
         }
         packet = _socket.Read();
         return(true);
     }
     catch
     {
     }
     return(false);
 }
Esempio n. 6
0
 public void Write(NetworkProtocol.Packet packet)
 {
     lock (this)
     {
         if (_writeTask == null)
         {
             if (_socket == null || !TryWrite(packet))
             {
                 _queue.Enqueue(packet);
                 _writeTask = Task.Run(() => WriteTaskRun());
             }
         }
         else
         {
             _queue.Enqueue(packet);
         }
     }
 }
Esempio n. 7
0
 private void WriteTaskRun()
 {
     while (!_disposed)
     {
         NetworkProtocol.Packet pack = null;
         lock (this)
         {
             if (_queue.Count == 0)
             {
                 _writeTask = null;
                 return;
             }
             pack = _queue.Peek();
             if (TryWrite(pack))
             {
                 _queue.Dequeue();
             }
         }
     }
 }
Esempio n. 8
0
 public void Write(NetworkProtocol.Packet packet)
 {
     _protocol.WritePacket(packet);
 }