public void Cancel_SendFirst() { var task = connection.SendAsync(requests.Encode(), 0, requests.ByteLength); connection.Dispose(); Assert.CatchAsync <OperationCanceledException> (() => task); }
public void RecieveFirst() { byte[] buffer = new byte[1024 * 1024 * 3]; IAsyncResult receiveResult = connection.BeginReceive(buffer, 0, 4, null, null); IAsyncResult sendResult = connection.BeginSend(requests.Encode(), 0, requests.ByteLength, null, null); amountSent = requests.ByteLength; CompleteSendOrReceiveFirst(buffer, receiveResult, sendResult); }
public async Task RecieveFirst() { byte[] buffer = new byte[1024 * 1024 * 3]; var receiveTask = NetworkIO.ReceiveAsync(connection, buffer, 0, 4, null, null, null); var task = Send(requests.Encode(), 0, requests.ByteLength); await CompleteSendOrReceiveFirst(buffer, receiveTask.ContinueWith(t => 4)); await task; }
public void ChunkedRequest() { if (requests.Messages.Count != 0) { rig.Manager.PieceManager.Picker.CancelRequests(id); } requests = rig.Manager.PieceManager.Picker.PickPiece(id, new List <PeerId>(), 256); byte[] sendBuffer = requests.Encode(); int offset = 0; amountSent = Math.Min(sendBuffer.Length - offset, 2048); IAsyncResult sendResult = connection.BeginSend(sendBuffer, offset, amountSent, null, null); while (sendResult.AsyncWaitHandle.WaitOne(10, true)) { Assert.AreEqual(amountSent, connection.EndSend(sendResult), "#1." + amountSent); offset += amountSent; amountSent = Math.Min(sendBuffer.Length - offset, 2048); if (amountSent == 0) { Assert.Fail("This should never happen"); } sendResult = connection.BeginSend(sendBuffer, offset, amountSent, null, null); } byte[] buffer = new byte[1024 * 1024 * 3]; IAsyncResult receiveResult = connection.BeginReceive(buffer, 0, 4, null, null); CompleteSendOrReceiveFirst(buffer, receiveResult, sendResult); }
public void ChunkedRequest() { if (requests.Messages.Count != 0) { rig.Manager.PieceManager.Picker.CancelRequests(id); } requests = rig.Manager.PieceManager.Picker.PickPiece(id, new List <PeerId>(), 256); byte[] sendBuffer = requests.Encode(); var sendTask = Send(sendBuffer, 0, sendBuffer.Length, 1); Assert.ThrowsAsync <ArgumentException>(() => sendTask); }
public void AddConnectionToStoppedManager() { MessageBundle bundle = new MessageBundle(); // Create the handshake and bitfield message bundle.Messages.Add(new HandshakeMessage(rig.Manager.InfoHash, "11112222333344445555", VersionInfo.ProtocolStringV100)); bundle.Messages.Add(new BitfieldMessage(rig.Torrent.Pieces.Count)); byte[] data = bundle.Encode(); // Add the 'incoming' connection to the engine and send our payload rig.Listener.Add(rig.Manager, conn.Incoming); conn.Outgoing.EndSend(conn.Outgoing.BeginSend(data, 0, data.Length, null, null)); try { var received = conn.Outgoing.EndReceive(conn.Outgoing.BeginReceive(data, 0, data.Length, null, null)); Assert.AreEqual(received, 0); } catch { Assert.IsFalse(conn.Incoming.Connected, "#1"); } }