Esempio n. 1
0
        public void DoAsyncRead()
        {
            lock (SyncRoot)  // don't want this to be called by multiple people at the same time
            {
                if (Client != null && Client.Connected)
                {
                    try
                    {
                        byte[] bData = null;
                        if (m_BufferPool != null)
                        {
                            bData = m_BufferPool.Checkout(4096);
                        }
                        else
                        {
                            bData = new byte[4096];
                        }

                        SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                        args.SetBuffer(bData, 0, bData.Length);
                        args.Completed += new EventHandler <SocketAsyncEventArgs>(ReceiveComplete);
                        Client.ReceiveAsync(args);
                    }
                    catch (System.Net.Sockets.SocketException sock)
                    {
                        if (m_Logger != null)
                        {
                            m_Logger.LogError(ToString(), MessageImportance.Highest, sock.ToString());
                        }
                        System.Threading.Thread.Sleep(0);
                        OnDisconnect(sock.ToString());
                    }
                    catch (System.IO.IOException e)
                    {
                        if (m_Logger != null)
                        {
                            m_Logger.LogError(ToString(), MessageImportance.Highest, e.ToString());
                        }
                        System.Threading.Thread.Sleep(0);
                        OnDisconnect(e.ToString());
                    }
                    catch (System.ObjectDisposedException e2)
                    {
                        if (m_Logger != null)
                        {
                            m_Logger.LogError(ToString(), MessageImportance.Highest, e2.ToString());
                        }
                        OnDisconnect(e2.ToString());
                    }
                    catch (System.InvalidOperationException e3)
                    {
                        if (m_Logger != null)
                        {
                            m_Logger.LogError(ToString(), MessageImportance.Highest, e3.ToString());
                        }
                        OnDisconnect(e3.ToString());
                    }
                    catch (System.Exception e4)
                    {
                        if (m_Logger != null)
                        {
                            m_Logger.LogError(ToString(), MessageImportance.Highest, e4.ToString());
                        }
                        OnDisconnect(e4.ToString());
                    }
                }
            }
        }
Esempio n. 2
0
        public void DoAsyncRead()
        {
            lock (SyncRoot)  // don't want this to be called by multiple people at the same time
            {
                if (Client != null && Client.Connected)
                {
                    try
                    {
                        byte[] bData = null;
                        if (m_BufferPool != null)
                        {
                            bData = m_BufferPool.Checkout();
                        }
                        else
                        {
                            bData = new byte[4096];
                        }

                        if (SslStream != null)
                        {
                            IAsyncResult result = SslStream.BeginRead(bData, 0, bData.Length - 1, new AsyncCallback(OnRecvDataAll), bData);
                            if (result.CompletedSynchronously == true)
                            {
                                System.Threading.Thread.Sleep(0);
                            }
                        }
                        else
                        {
                            IAsyncResult result = NetworkStream.BeginRead(bData, 0, bData.Length - 1, new AsyncCallback(OnRecvDataAll), bData);
                            if (result.CompletedSynchronously == true)
                            {
                                System.Threading.Thread.Sleep(0);
                            }
                        }
                        //System.Net.Sockets.NetworkStream networkStream = GetStream();
                        //networkStream.BeginRead(m_bData, 0, m_bData.Length -1, m_AsyncRecv, networkStream);
                    }
                    catch (System.Net.Sockets.SocketException sock)
                    {
                        if (m_Logger != null)
                        {
                            m_Logger.LogError(ToString(), MessageImportance.Highest, sock.ToString());
                        }
                        System.Threading.Thread.Sleep(0);
                        OnDisconnect(sock.ToString());
                    }
                    catch (System.IO.IOException e)
                    {
                        if (m_Logger != null)
                        {
                            m_Logger.LogError(ToString(), MessageImportance.Highest, e.ToString());
                        }
                        System.Threading.Thread.Sleep(0);
                        OnDisconnect(e.ToString());
                    }
                    catch (System.ObjectDisposedException e2)
                    {
                        if (m_Logger != null)
                        {
                            m_Logger.LogError(ToString(), MessageImportance.Highest, e2.ToString());
                        }
                        OnDisconnect(e2.ToString());
                    }
                    catch (System.InvalidOperationException e3)
                    {
                        if (m_Logger != null)
                        {
                            m_Logger.LogError(ToString(), MessageImportance.Highest, e3.ToString());
                        }
                        OnDisconnect(e3.ToString());
                    }
                    catch (Exception ex)
                    {
                        if (m_Logger != null)
                        {
                            m_Logger.LogError(ToString(), MessageImportance.Highest, ex.ToString());
                        }
                        OnDisconnect(ex.ToString());
                    }
                }
            }
        }