public SmppInternalConnection(SmppSettings Settings) {
   TcpConnection = new SockClient();
   PendingResponse = new ListDictionary();
   PendingQueue = new ArrayList(15);
   PendingBind = new ArrayList(10);
   ReleasedDateTime = DateTime.Now;
   LastReceptionTime = DateTime.Now;
   ClientGuid = Guid.NewGuid();
   this.Settings = Settings;
   TcpConnection.DataReceived += TcpConnection_DataReceived;
   TcpConnection.CloseConnection += TcpConnection_CloseConnection;
 }
 void TcpConnection_DataReceived(object sender, SockClient.DataReceivedEventArgs e) {
   LastReceptionTime = DateTime.Now;
   while (TcpConnection.ReadSize() >= 0x10) {
     int bytes = SmppConverter.FromByteArrayToInt32(TcpConnection.PeekBytes(4));
     if (bytes > Settings.MaxPduSize) {
       TcpConnection.Disconnect();
       return;
     }
     if (bytes > TcpConnection.ReadSize())
       break;
     var bb = new ByteBuilder(TcpConnection.ReadByteArray(bytes, 0));
     var header = new SmppHeader(bb);
     SmppAsyncObject asyncObject = FindAsyncObject(header.SequenceNumber);
     if (asyncObject != null) {
       asyncObject.PduRes = bb;
       if (asyncObject.mre != null)
         asyncObject.mre.Set();
       else if (asyncObject.Callback != null)
         new SmppCompletionCallbackHandler(ProcessAsyncPdu).BeginInvoke(asyncObject,
                                                                        SmppAsyncObject.SmppAsyncCompleted.Response,
                                                                        null, null);
     } else
       ProcessPdu(bb);
   }
 }
 void TcpConnection_CloseConnection(object sender, SockClient.CloseConnectionEventArgs e) {
   try {
     lock (TcpConnection) {
       ConsecutiveTimeouts = 0;
       lock (PendingResponse.SyncRoot) {
         foreach (DictionaryEntry entry in PendingResponse) {
           var asyncObject = (SmppAsyncObject) entry.Value;
           if (asyncObject.mre != null) {
             asyncObject.mre.Set();
             PendingResponse.Remove(entry.Key);
             continue;
           }
           new SmppCompletionCallbackHandler(ProcessAsyncPdu).BeginInvoke(asyncObject,
                                                                          SmppAsyncObject.SmppAsyncCompleted.
                                                                            Disconnection, null, null);
         }
         lock (PendingQueue.SyncRoot) {
           for (int i = 0; i < PendingQueue.Count; i++) {
             var obj3 = PendingQueue[i] as SmppAsyncObject;
             new SmppCompletionCallbackHandler(ProcessAsyncPdu).BeginInvoke(obj3,
                                                                            SmppAsyncObject.SmppAsyncCompleted.
                                                                              Disconnection, null,
                                                                            null);
           }
         }
       }
     }
   } catch {}
   if (ConnectionSuccess)
     RaiseUnBindReq(new SmppUnBindEventArgs(ClientGuid, new SmppUnBindReq()));
   ConnectionSuccess = false;
 }