예제 #1
0
파일: Client.cs 프로젝트: xiataosky/proxy
        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);
        }
예제 #3
0
        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));
        }
예제 #4
0
        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));
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
 public void Dispose()
 {
     Reader.Dispose();
     Stream.Dispose();
     Sock.Close();
     Sock.Dispose();
     Lock.Dispose();
 }
예제 #7
0
        public void Stop()
        {
            Closing = true;
            Stream.Close();
            Sock.Close();

            Stream.Dispose();
            Sock.Dispose();
        }
예제 #8
0
파일: Client.cs 프로젝트: xiataosky/proxy
 public void Disconnect()
 {
     if (IsConnected())
     {
         _disposed = true;
         OnClientDisconnected(this, new ClientEventArgs(this));
         Sock.Close();
         Dispose();
     }
 }
예제 #9
0
 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
         {
         }
     }
 }
예제 #11
0
 public void Close()
 {
     // Release the socket.
     Sock.Shutdown(SocketShutdown.Both);
     Sock.Close();
 }