protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) { return(Tap.Run(callback, state, async() => { try { var ct = GetCancellationTokenForTimeout(timeout); base.InitializeSocket(await BrokeredServiceClient.ConnectAsync(Via.PathAndQuery, ct)); } catch (SocketException socketException) { throw ConvertSocketException(socketException, "Connect"); } })); }
protected override IAsyncResult OnBeginAcceptChannel(TimeSpan timeout, AsyncCallback callback, object state) { return(Tap.Run(callback, state, () => Task.Run(() => { try { var dataSocket = acceptQueue.Take(); 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, () => Task.Run(() => { try { channel.SendMessage(encodedBytes.Array, encodedBytes.Offset, encodedBytes.Count); } catch (SocketException socketException) { throw ConvertSocketException(socketException, "Receive"); } }))); }
public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state) { base.ThrowIfDisposedOrNotOpen(); return(Tap.Run(callback, state, () => ReceiveAsync(timeout))); }