Exemplo n.º 1
0
        private static void OnIoCompleted(object sender, SocketAsyncEventArgs args)
        {
            var operation = (SocketChannelAsyncOperation)args;
            AbstractSocketChannel channel = operation.Channel;

            switch (args.LastOperation)
            {
            case SocketAsyncOperation.Connect:
                channel.FinishConnect(operation);
                break;

            case SocketAsyncOperation.Receive:
            case SocketAsyncOperation.ReceiveFrom:
                channel.FinishRead(operation);
                break;

            case SocketAsyncOperation.Send:
            case SocketAsyncOperation.SendTo:
                channel.FinishWrite(operation);
                break;

            default:
                // todo: think of a better way to comm exception
                throw new ArgumentException("The last operation completed on the socket was not expected");
            }
        }
Exemplo n.º 2
0
        public SocketChannelAsyncOperation(AbstractSocketChannel channel, bool setEmptyBuffer)
        {
            Contract.Requires(channel != null);

            this.Channel    = channel;
            this.Completed += AbstractSocketChannel.IoCompletedCallback;
            if (setEmptyBuffer == false)
            {
                this.SetBuffer(new byte[MaxAllocBufferSize], 0, MaxAllocBufferSize);
            }
            else
            {
                this.SetBuffer(ArrayExtensions.ZeroBytes, 0, 0);
            }
        }