Exemple #1
0
        private async void ReceiveAsyncInternal(SocketReceiveTask task)
        {
            if (tlsStreams != null)  //damn you sslstream
            {
                try {
                    byte[] byt = new byte[1];
                    int    ret = await tlsStreams.SslStream.ReadAsync(byt, 0, 1);

                    if (ret == 0)
                    {
                        Disconnect();
                        return;
                    }
                    else
                    {
                        readStream.Write(byt, 0, 1);
                    }
                }
                catch (Exception ex) {
                    OnException(ex);
                    return;
                }
            }
            task.Count      = SocketManager.BufferSize;//bufferSize?
            task.TlsStreams = tlsStreams;
            if (IsConnected)
            {
                Socket.QueueReceive(task);
            }
        }
Exemple #2
0
 public void Dispose()
 {
     Close();
     Formatter           = null;
     sendHandler         = null;
     recvTask.Completed -= ReceiveComplete;
     recvTask            = null;
 }
Exemple #3
0
 public AresUdpSocket(IPacketFormatter formatter)
 {
     Formatter           = formatter;
     Socket              = SocketManager.CreateUdp();
     Monitor             = new IOMonitor();
     recvTask            = new SocketReceiveTask(8192);
     recvTask.Completed += ReceiveComplete;
     sendHandler         = new EventHandler <IOTaskCompleteEventArgs <SocketSendTask> >(SendComplete);
 }
Exemple #4
0
 private void ReceiveAsyncInternal(SocketReceiveTask task)
 {
     State          = ReceiveStatus.Header;
     task.Count     = HeaderLength;
     task.SslStream = sslStream;
     if (IsConnected)
     {
         Socket.QueueReceive(task);
     }
 }
Exemple #5
0
        public void ReceiveAsync()
        {
            SocketReceiveTask task = new SocketReceiveTask(8192);

            task.Completed     += ReceiveComplete;
            task.RemoteEndPoint = receiveEp;

            if (Socket != null)
            {
                Socket.QueueReceive(task);
            }
        }
Exemple #6
0
        public virtual void ReceiveAsync()
        {
            if (receiving)
            {
                throw new InvalidOperationException("Socket is already receiving.");
            }
            receiving = true;

            var task = new SocketReceiveTask(HeaderLength);

            task.Completed += ReceiveCompleted;

            ReceiveAsyncInternal(task);
        }
Exemple #7
0
 public static void QueueReceive(this Socket socket, SocketReceiveTask task)
 {
     task.Socket    = socket ?? throw new ArgumentNullException("socket", "socket cannot be null");
     task.Exception = null;
     IO.QueueRead(task);
 }