Esempio n. 1
0
        /// <summary>
        /// Send socket option message
        /// </summary>
        /// <param name="option"></param>
        /// <param name="value"></param>
        /// <param name="ct"></param>
        public async Task SetSocketOptionAsync(
            SocketOption option, ulong value, CancellationToken ct)
        {
            var response = await _socket.Provider.ControlChannel.CallAsync(Proxy,
                                                                           new Message(_socket.Id, RemoteId, new SetOptRequest(
                                                                                           new SocketOptionValue(option, value))), ct).ConfigureAwait(false);

            ProxySocket.ThrowIfFailed(response);
        }
Esempio n. 2
0
        /// <summary>
        /// Get socket option
        /// </summary>
        /// <param name="option"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task <ulong> GetSocketOptionAsync(
            SocketOption option, CancellationToken ct)
        {
            var response = await _socket.Provider.ControlChannel.CallAsync(Proxy,
                                                                           new Message(_socket.Id, RemoteId, new GetOptRequest(
                                                                                           option)), ct).ConfigureAwait(false);

            ProxySocket.ThrowIfFailed(response);
            return(((GetOptResponse)response.Content).OptionValue.Value);
        }
Esempio n. 3
0
        /// <summary>
        /// Receive a message
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        protected async Task <DataMessage> ReceiveAsync(
            CancellationToken ct)
        {
            Message message;

            while (!Socket.ReceiveQueue.TryDequeue(out message))
            {
                await Socket.ReceiveAsync(ct).ConfigureAwait(false);
            }
            ProxySocket.ThrowIfFailed(message);
            if (message.Error != (int)SocketError.Success)
            {
                throw new SocketException((SocketError)message.Error);
            }
            if (message.TypeId != MessageContent.Data)
            {
                throw new SocketException("No data message");
            }
            return(message.Content as DataMessage);
        }