コード例 #1
0
 public void Receive(Buffer buffer, ConnectionIoCallback callback)
 {
     if (ReceiveAction != null)
     {
         ReceiveAction(buffer, callback);
     }
 }
コード例 #2
0
ファイル: IOState.cs プロジェクト: zofuthan/peer2net
        internal static IOState Create(BufferManager.Buffer buffer, int bytes, IConnection connection, IBandwidthController bandwidthController, SuccessCallback onSuccess, FailureCallback onFailure)
        {
            var state = Pool.Count > 0 ? Pool.Dequeue() : new IOState();

            state._buffer              = buffer;
            state._bytes               = bytes;
            state._pendingBytes        = state._bytes;
            state._connection          = connection;
            state._bandwidthController = bandwidthController;
            state._onSuccess           = onSuccess;
            state._onFailure           = onFailure;
            return(state);
        }
コード例 #3
0
        public void Send(BufferManager.Buffer buffer, ConnectionIoCallback callback)
        {
            if (CheckDisconnectedOrDisposed(callback))
            {
                return;
            }

            var sendAsyncEventArgs = SendRecvSaeaPool.Take();

            sendAsyncEventArgs.UserToken  = callback;
            sendAsyncEventArgs.BufferList = buffer.ToArraySegmentList();
            var async = _socket.SendAsync(sendAsyncEventArgs);

            if (!async)
            {
                SendRecvCompleted(null, sendAsyncEventArgs);
            }
        }
コード例 #4
0
 public void Send(Buffer buffer, ConnectionIoCallback callback)
 {
 }
コード例 #5
0
 public void Free(Buffer segments)
 {
 }
コード例 #6
0
 public void Send(byte[] data, IConnection connection, IBandwidthController bandwidthController,
                         SuccessCallback onSuccess, FailureCallback onFailure)
 {
     var buffer = new Buffer(data);
     SendInternal(IOState.Create(buffer, buffer.Size, connection, bandwidthController, onSuccess, onFailure));
 }
コード例 #7
0
 public void Send(Buffer buffer, ConnectionIoCallback callback)
 {
 }
コード例 #8
0
 public void Receive(Buffer buffer, ConnectionIoCallback callback)
 {
     if(ReceiveAction!=null) ReceiveAction(buffer, callback);
 }
コード例 #9
0
 public void Free(Buffer segments)
 {
 }
コード例 #10
0
ファイル: ConnectionTests.cs プロジェクト: jpalmero9/peer2net
        public void ShouldSendData()
        {
            var localConnectionWaiter = new ManualResetEvent(false);
            var remoteConnectionWaiter = new ManualResetEvent(false);

            Connection remoteConnection = null;
            _remote.ConnectionRequested += (sender, args) => {
                remoteConnection = new Connection(args.Socket);
                remoteConnectionWaiter.Set();
            };

            var localConnection = new Connection(new IPEndPoint(IPAddress.Loopback, 9999));
            localConnection.Connect(c => localConnectionWaiter.Set());
            WaitHandle.WaitAll(new WaitHandle[] { localConnectionWaiter, remoteConnectionWaiter });
            localConnectionWaiter.Reset();
            remoteConnectionWaiter.Reset();

            var remoteBuffer = new Buffer(new byte[1]);
            remoteConnection.Receive(remoteBuffer, (i, b) => remoteConnectionWaiter.Set());
            localConnection.Send(new Buffer(new byte[] { 0xf1 }), (i, b) => localConnectionWaiter.Set());
            WaitHandle.WaitAll(new WaitHandle[] { localConnectionWaiter, remoteConnectionWaiter });

            Assert.AreEqual(0xf1, remoteBuffer.Segment.Array[0]);
        }