private void DataSent(IAsyncResult res) { try { if (!IsConnected()) { Disconnect(); return; } var sent = ((Socket)res.AsyncState).EndSend(res); if (sent < 0) { Sock.Shutdown(SocketShutdown.Both); Sock.Close(); return; } var data = new DataEventArgs(this, new byte[] { }, sent); OnDataSent(this, data); } catch (Exception ex) { #if DEBUG Console.WriteLine(ex.ToString()); #endif } }
public void Close() { // 중복 수행을 막는다. if (Interlocked.CompareExchange(ref this.IsClosed, 1, 0) == 1) { return; } if (CurrentState == STATE_CLOSED) { // already closed. return; } CurrentState = STATE_CLOSED; ReserveClosingMillSec = 0; Sock.Close(); Sock = null; SendEventArgs.UserToken = null; ReceiveEventArgs.UserToken = null; SendingList.Clear(); OnSessionClosed(this); var msg = new Packet(this, (UInt16)NetworkDefine.SYS_NTF_CLOSED); Dispatcher.IncomingPacket(true, this, msg); }
public void Close() { // 중복 수행을 막는다. if (Interlocked.CompareExchange(ref this.IsClosed, 1, 0) == 1) { return; } if (CurrentState == STATE_CLOSED) { // already closed. return; } CurrentState = STATE_CLOSED; ReserveClosingMillSec = 0; Sock.Close(); Sock = null; SendEventArgs.UserToken = null; ReceiveEventArgs.UserToken = null; SendingList.Clear(); RefMsgResolver.ClearBuffer(); OnSessionClosed(this); var msg = Packet.Create((short)NetworkDefine.SYS_NTF_CLOSED); Dispatcher.IncomingPacket(true, this, new ArraySegment <byte>(msg.Buffer, 0, msg.Position)); }
public void Close() { if (Interlocked.CompareExchange(ref this.IsClosed, 1, 0) == 1) { return; } if (CurrentState == State.Closed) { return; } CurrentState = State.Closed; Sock.Close(); Sock = null; SendEventArgs.UserToken = null; ReceiveEventArgs.UserToken = null; SendingList.Clear(); MsgResolver.ClearBuffer(); if (Peer != null) { var msg = Packet.Create((short)-1); Dispatcher.IncomingPacket(this, new ArraySegment <byte>(msg.Buffer, 0, msg.Position)); } }
public void Dispose() { try { OnClosed(Guid); Stream.Close(); Stream.Dispose(); Sock.Close(); Sock.Dispose(); clientThread.Abort(); clientThread.Join(); } catch (ThreadAbortException ex) { string exMsg = string.Empty; exMsg = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + ex.StackTrace + Environment.NewLine + System.Reflection.MethodBase.GetCurrentMethod().Name + "():" + ex.Message; Console.WriteLine("THREAD ABORT ERROR :: " + exMsg); } catch (Exception ex) { string exMsg = string.Empty; exMsg = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name + ":" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + ex.StackTrace + Environment.NewLine + System.Reflection.MethodBase.GetCurrentMethod().Name + "():" + ex.Message; Console.WriteLine("Dispose ERROR :: " + exMsg); } }
public void Dispose() { Reader.Dispose(); Stream.Dispose(); Sock.Close(); Sock.Dispose(); Lock.Dispose(); }
public void Stop() { Closing = true; Stream.Close(); Sock.Close(); Stream.Dispose(); Sock.Dispose(); }
public void Disconnect() { if (IsConnected()) { _disposed = true; OnClientDisconnected(this, new ClientEventArgs(this)); Sock.Close(); Dispose(); } }
public void Dispose() { lock (_socketLocker) { if (IsDisposed) { return; } Sock.Close(); IsDisposed = true; } }
public void Dispose(bool disposing) { if (Sock != null && Sock.Connected) { try { Sock.Shutdown(SocketShutdown.Both); Sock.Close(); Sock = null; } catch { } } }
public void Close() { // Release the socket. Sock.Shutdown(SocketShutdown.Both); Sock.Close(); }