Ejemplo n.º 1
0
        private void onDataSent(object sender, EventArgs e)
        {
            int index = clients.IndexOf((ServerClient)sender);

            if (index < 0)
            {
                return;
            }

            ClientDataSent?.Invoke(this, new ListEventArgs(index));
        }
Ejemplo n.º 2
0
        private void ProcessSend(SocketAsyncEventArgs e)
        {
            ClientToken clientToken = (ClientToken)e.UserToken;

            if (e.SocketError != SocketError.Success)
            {
                //Fire DataSentError event
                if (ClientDataSendError != null)
                {
                    if (CallClientDataSendErrorAsync)
                    {
                        ClientDataSendError.BeginInvoke(this, clientToken.Id, e.SocketError,
                                                        r => ClientDataSendError.EndInvoke(r), null);
                    }
                    else
                    {
                        ClientDataSendError(this, clientToken.Id, e.SocketError);
                    }
                }

                if (!clientToken.Closed && !clientToken.Socket.DisconnectAsync(e))
                {
                    CloseClientSocket(clientToken);
                }

                return;
            }

            clientToken.SendBytesRemaining = clientToken.SendBytesRemaining - e.BytesTransferred;
            if (clientToken.SendBytesRemaining == 0)
            {
                //Fire DataSent event
                if (ClientDataSent != null)
                {
                    if (CallClientDataSentAsync)
                    {
                        ClientDataSent.BeginInvoke(this, clientToken.Id, r => ClientDataSent.EndInvoke(r), null);
                    }
                    else
                    {
                        ClientDataSent(this, clientToken.Id);
                    }
                }

                clientToken.ResetSend();
            }
            else
            {
                clientToken.BytesSentAlready += e.BytesTransferred;
                StartSend(clientToken);
            }
        }