public NetPeer(ulong id, INetProxy proxy, ISerializer serializer) { this.Id = id; this.Proxy = proxy ?? throw new ArgumentNullException("Socket proxy can't be null!"); this.Serializer = serializer ?? throw new ArgumentNullException("Serializer can't be null!"); this.sendBuffer = this.storage.Alloc(BUFFER_SIZE); this.recvBuffer = this.storage.Alloc(BUFFER_SIZE); this.sendThread = new Thread(new ThreadStart(DoSendAsync)); this.sendThread.Start(); this.recvThread = new Thread(new ThreadStart(DoRecvAsync)); this.recvThread.Start(); }
public void Close(Exception ex = null) { this.OnClosed?.Invoke(this, ex); this.OnClosed = null; this.OnMessage = null; this.closed = true; if (this.Proxy != null) { this.Proxy.Close(); this.Proxy = null; } this.storage.Dispose(); this.sendBuffer = null; this.recvBuffer = null; }