public static void Write(Stream stream, Bcp.Finish packet) { try { stream.WriteByte(Bcp.Finish.HeadByte); } catch { stream.Close(); } }
private void EnqueueFinish(Connection connection) { if (!connection.isFinishSent) { Bcp.Finish finishPacket = new Bcp.Finish(); connection.unconfirmedPackets.Enqueue(finishPacket); Stream stream = connection.stream; BcpIO.Write(stream, finishPacket); stream.Flush(); connection.isFinishSent = true; } }
private void CleanUp(uint connectionId, Connection connection) { Debug.WriteLine("Cleaning up connectionId: " + connectionId); RemoveOpenConnection(connection); if (!connection.isFinishSent) { var finishPacket = new Bcp.Finish(); connection.unconfirmedPackets.Enqueue(finishPacket); connection.isFinishSent = true; } Close(connection); var stream = connection.stream; connection.stream = null; if (stream != null) { var heartBeatTimer = connection.heartBeatTimer; connection.heartBeatTimer = null; if (heartBeatTimer != null) { heartBeatTimer.Change(Timeout.Infinite, Timeout.Infinite); heartBeatTimer.Dispose(); heartBeatTimer = null; } } var packId = connection.numAcknowledgeReceivedForData; foreach (Bcp.IAcknowledgeRequired packet in connection.unconfirmedPackets) { if (packet is Bcp.Data) { var oldPacket = (Bcp.Data)packet; var newPacket = new Bcp.RetransmissionData(connectionId, packId, oldPacket.Buffers); Enqueue(newPacket); packId += 1; } else if (packet is Bcp.Finish) { var newPacket = new Bcp.RetransmissionFinish(connectionId, packId); Enqueue(newPacket); packId += 1; } else { Enqueue(packet); } } connection.unconfirmedPackets = new Queue <Bcp.IAcknowledgeRequired>(); CheckConnectionFinish(connectionId, connection); }