Esempio n. 1
0
        internal void ProcessSend(SocketAsyncEventArgs Args)
        {
            T Session = (T)Args.UserToken;

            if (Args.SocketError == SocketError.Success)
            {
                Session.SendBytesRemainingCount = Session.SendBytesRemainingCount - Args.BytesTransferred;

                if (Session.SendBytesRemainingCount == 0)
                {
                    SendPool.Push(Args);
                }
                else
                {
                    Session.BytesSentAlreadyCount += Args.BytesTransferred;
                    StartSend(Args);
                }

                if (DataSent != null)
                {
                    DataSent.Invoke(new SocketSentEventArgs <T>(Session, Session.DataToSend, Args.BytesTransferred));
                }
            }
            else
            {
                CloseClientSocket(Args);
                SendPool.Push(Args);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to send data to the client of a connection.
        /// </summary>
        /// <param name="session">The session sending data.</param>
        /// <param name="bytes">The data to be sent.</param>
        public void SendBytes(T session, byte[] bytes)
        {
            SocketAsyncEventArgs args;

            if (SendPool.TryPop(out args))
            {
                args.UserToken     = session;
                session.DataToSend = bytes;
                session.SendBytesRemainingCount = bytes.Length;
                args.AcceptSocket = session.Socket;

                StartSend(args);
            }
        }