Exemplo n.º 1
0
        public unsafe void Execute(TcpSocketSendResult target)
        {
            target.Pin(buffer.Data);

            Overlapped overlapped = new Overlapped {
                AsyncResult = target
            };
            NativeOverlapped *native    = overlapped.UnsafePack(null, null);
            IntPtr            reference = Marshal.UnsafeAddrOfPinnedArrayElement(buffer.Data, buffer.Offset);

            TcpSocketInterop.WSABuffer data = new TcpSocketInterop.WSABuffer
            {
                length = buffer.Count,
                buffer = reference
            };

            int  written;
            uint result = TcpSocketInterop.WSASend(handle, &data, 1, out written, 0, native, IntPtr.Zero);
            uint error  = TcpSocketInterop.WSAGetLastError();

            if (result != 0 && error != 997)
            {
                target.Fail(error);
            }
        }
Exemplo n.º 2
0
        public void Send(SocketBuffer buffer, TcpSocketSendCallback callback)
        {
            TcpSocketSendRoutine routine = new TcpSocketSendRoutine(handle, buffer);
            TcpSocketSendResult  result  = new TcpSocketSendResult
            {
                Socket = this,
                Buffer = buffer,
                OnSent = callback
            };

            routine.Execute(result);
        }
Exemplo n.º 3
0
        public Task <TcpSocketSend> Send(SocketBuffer buffer)
        {
            TcpSocketSendResult result = new TcpSocketSendResult
            {
                Socket = this,
                Buffer = buffer,
                Event  = new ManualResetEvent(false)
            };

            Task <TcpSocketSend> task    = Task.Factory.FromAsync(result, ar => ((TcpSocketSendResult)ar).CreateData());
            TcpSocketSendRoutine routine = new TcpSocketSendRoutine(handle, buffer);

            routine.Execute(result);
            return(task);
        }