public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state)
        {
            try
            {
                base.ThrowIfDisposedOrNotOpen();

                return(Tap.Run(callback, state, () => ReceiveAsync()));
            }
            catch (Exception exp)
            {
                return(null);
            }
        }
Esempio n. 2
0
 protected override IAsyncResult OnBeginAcceptChannel(TimeSpan timeout, AsyncCallback callback, object state)
 {
     return(Tap.Run(callback, state, async() =>
     {
         try
         {
             var dataSocket = await listenSocket.AcceptAsync();
             return (IDuplexSessionChannel) new ServerDuplexSessionChannel(this.encoderFactory, this.bufferManager, this.maxBufferSize, dataSocket, new EndpointAddress(this.Uri), this);
         }
         catch (SocketException ex) when(ex.SocketErrorCode == SocketError.OperationAborted)
         {
             return null;
         }
     }));
 }
        public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state)
        {
            base.ThrowIfDisposedOrNotOpen();
            var encodedBytes = this.EncodeMessage(message);

            return(Tap.Run(callback, state, async() =>
            {
                try
                {
                    await WriteDataAsync(encodedBytes);
                }
                catch (SocketException socketException)
                {
                    throw ConvertSocketException(socketException, "Receive");
                }
            }));
        }
Esempio n. 4
0
        protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
        {
            return(Tap.Run(callback, state, async() =>
            {
                var targetAddress = HyperVSocketEndPoint.Parse(Via);
                try
                {
                    var socket = new Socket(AF_HYPERV, SocketType.Stream, HV_PROTOCOL_RAW);
                    await socket.ConnectAsync(targetAddress);

                    base.InitializeSocket(socket);
                }
                catch (SocketException socketException)
                {
                    throw ConvertSocketException(socketException, "Connect");
                }
            }));
        }
        public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state)
        {
            base.ThrowIfDisposedOrNotOpen();

            return(Tap.Run(callback, state, () => ReceiveAsync()));
        }