Example #1
0
 protected override void SendInternal(PosList <ArraySegment <byte> > items)
 {
     SendInternalAsync(items);
 }
Example #2
0
 protected abstract void SendInternal(PosList <ArraySegment <byte> > items);
Example #3
0
        protected override void SendInternal(PosList <ArraySegment <byte> > items)
        {
            if (m_SocketEventArgsSend == null)
            {
                m_SocketEventArgsSend            = new SocketAsyncEventArgs();
                m_SocketEventArgsSend.Completed += new EventHandler <SocketAsyncEventArgs>(Sending_Completed);
            }

            bool raiseEvent;

            try
            {
                if (items.Count > 1)
                {
                    if (m_SocketEventArgsSend.Buffer != null)
                    {
                        m_SocketEventArgsSend.SetBuffer(null, 0, 0);
                    }

                    m_SocketEventArgsSend.BufferList = items;
                }
                else
                {
                    var currentItem = items[0];

                    try
                    {
                        if (m_SocketEventArgsSend.BufferList != null)
                        {
                            m_SocketEventArgsSend.BufferList = null;
                        }
                    }
                    catch//a strange NullReference exception
                    {
                    }

                    m_SocketEventArgsSend.SetBuffer(currentItem.Array, currentItem.Offset, currentItem.Count);
                }


                raiseEvent = Client.SendAsync(m_SocketEventArgsSend);
            }
            catch (SocketException exc)
            {
                int errorCode;

                errorCode = exc.ErrorCode;

                if (EnsureSocketClosed() && !IsIgnorableSocketError(errorCode))
                {
                    OnError(exc);
                }

                return;
            }
            catch (Exception e)
            {
                if (EnsureSocketClosed() && IsIgnorableException(e))
                {
                    OnError(e);
                }
                return;
            }

            if (!raiseEvent)
            {
                Sending_Completed(Client, m_SocketEventArgsSend);
            }
        }