Esempio n. 1
0
 private void ReceiveAsync(ServerClientStateObjectApm state)
 {
     if ((_state & RECEIVE_FLAG) == RECEIVE_FLAG)
     {
         try
         {
             state.Socket.BeginReceive(
                 state.BufferWrite, 0, state.BufferWrite.Length, SocketFlags.None, ReceiveDataCallback,
                 state);
         }
         catch (ObjectDisposedException)
         {
             InvokeClientDisconnect(state.Socket, DisconnectReason.Aborted);
             state.Dispose();
         }
         catch (SocketException)
         {
             InvokeClientDisconnect(state.Socket, DisconnectReason.Error);
             state.Dispose();
         }
         catch
         {
             InvokeClientDisconnect(state.Socket, DisconnectReason.Unspecified);
             state.Dispose();
         }
     }
 }
Esempio n. 2
0
        private void ReceiveDataCallback(IAsyncResult iar)
        {
            ServerClientStateObjectApm state = (ServerClientStateObjectApm)iar.AsyncState !;
            int bytesTransferred;

            try
            {
                if ((bytesTransferred = state.Socket.EndReceive(iar)) <= 0)
                {
                    InvokeClientDisconnect(state.Socket, DisconnectReason.Graceful);
                    state.Dispose();
                    return;
                }
            }
            catch (ObjectDisposedException)
            {
                InvokeClientDisconnect(state.Socket, DisconnectReason.Aborted);
                state.Dispose();
                return;
            }
            catch (SocketException)
            {
                InvokeClientDisconnect(state.Socket, DisconnectReason.Error);
                state.Dispose();
                return;
            }
            catch
            {
                InvokeClientDisconnect(state.Socket, DisconnectReason.Unspecified);
                state.Dispose();
                return;
            }

            Receive(state.Socket, state.BufferWrite, bytesTransferred, state);
            ReceiveAsync(state);
        }