You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 15:46:33 +09:00
NetPeerConfiguration.AutoFlushSendQueue added. When set to false; application must call NetPeer.FlushSendQueue manually.
This commit is contained in:
@@ -225,13 +225,16 @@ namespace Lidgren.Network
|
|||||||
//
|
//
|
||||||
// send queued messages
|
// send queued messages
|
||||||
//
|
//
|
||||||
for (int i = m_sendChannels.Length - 1; i >= 0; i--) // Reverse order so reliable messages are sent first
|
if (m_peer.m_executeFlushSendQueue)
|
||||||
{
|
{
|
||||||
var channel = m_sendChannels[i];
|
for (int i = m_sendChannels.Length - 1; i >= 0; i--) // Reverse order so reliable messages are sent first
|
||||||
NetException.Assert(m_sendBufferWritePtr < 1 || m_sendBufferNumMessages > 0);
|
{
|
||||||
if (channel != null)
|
var channel = m_sendChannels[i];
|
||||||
channel.SendQueuedMessages(now);
|
NetException.Assert(m_sendBufferWritePtr < 1 || m_sendBufferNumMessages > 0);
|
||||||
NetException.Assert(m_sendBufferWritePtr < 1 || m_sendBufferNumMessages > 0);
|
if (channel != null)
|
||||||
|
channel.SendQueuedMessages(now);
|
||||||
|
NetException.Assert(m_sendBufferWritePtr < 1 || m_sendBufferNumMessages > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace Lidgren.Network
|
|||||||
|
|
||||||
internal readonly NetPeerStatistics m_statistics;
|
internal readonly NetPeerStatistics m_statistics;
|
||||||
internal long m_uniqueIdentifier;
|
internal long m_uniqueIdentifier;
|
||||||
|
internal bool m_executeFlushSendQueue;
|
||||||
|
|
||||||
private AutoResetEvent m_messageReceivedEvent = new AutoResetEvent(false);
|
private AutoResetEvent m_messageReceivedEvent = new AutoResetEvent(false);
|
||||||
private List<NetTuple<SynchronizationContext, SendOrPostCallback>> m_receiveCallbacks;
|
private List<NetTuple<SynchronizationContext, SendOrPostCallback>> m_receiveCallbacks;
|
||||||
@@ -280,9 +281,13 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
SendDelayedPackets();
|
SendDelayedPackets();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// update m_executeFlushSendQueue
|
||||||
|
if (m_configuration.m_autoFlushSendQueue)
|
||||||
|
m_executeFlushSendQueue = true;
|
||||||
|
|
||||||
// do connection heartbeats
|
// do connection heartbeats
|
||||||
lock (m_connections)
|
lock (m_connections)
|
||||||
{
|
{
|
||||||
@@ -300,6 +305,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_executeFlushSendQueue = false;
|
||||||
|
|
||||||
// send unsent unconnected messages
|
// send unsent unconnected messages
|
||||||
NetTuple<IPEndPoint, NetOutgoingMessage> unsent;
|
NetTuple<IPEndPoint, NetOutgoingMessage> unsent;
|
||||||
@@ -472,6 +478,14 @@ namespace Lidgren.Network
|
|||||||
} while (m_socket.Available > 0);
|
} while (m_socket.Available > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If NetPeerConfiguration.AutoFlushSendQueue() is false; you need to call this to send all messages queued using SendMessage()
|
||||||
|
/// </summary>
|
||||||
|
public void FlushSendQueue()
|
||||||
|
{
|
||||||
|
m_executeFlushSendQueue = true;
|
||||||
|
}
|
||||||
|
|
||||||
internal void HandleIncomingDiscoveryRequest(double now, IPEndPoint senderEndpoint, int ptr, int payloadByteLength)
|
internal void HandleIncomingDiscoveryRequest(double now, IPEndPoint senderEndpoint, int ptr, int payloadByteLength)
|
||||||
{
|
{
|
||||||
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryRequest))
|
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryRequest))
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ namespace Lidgren.Network
|
|||||||
internal bool m_useMessageRecycling;
|
internal bool m_useMessageRecycling;
|
||||||
internal float m_connectionTimeout;
|
internal float m_connectionTimeout;
|
||||||
internal bool m_enableUPnP;
|
internal bool m_enableUPnP;
|
||||||
|
internal bool m_autoFlushSendQueue;
|
||||||
|
|
||||||
internal NetIncomingMessageType m_disabledTypes;
|
internal NetIncomingMessageType m_disabledTypes;
|
||||||
internal int m_port;
|
internal int m_port;
|
||||||
@@ -86,6 +87,7 @@ namespace Lidgren.Network
|
|||||||
m_useMessageRecycling = true;
|
m_useMessageRecycling = true;
|
||||||
m_resendHandshakeInterval = 3.0f;
|
m_resendHandshakeInterval = 3.0f;
|
||||||
m_maximumHandshakeAttempts = 5;
|
m_maximumHandshakeAttempts = 5;
|
||||||
|
m_autoFlushSendQueue = true;
|
||||||
|
|
||||||
// Maximum transmission unit
|
// Maximum transmission unit
|
||||||
// Ethernet can take 1500 bytes of payload, so lets stay below that.
|
// Ethernet can take 1500 bytes of payload, so lets stay below that.
|
||||||
@@ -258,6 +260,15 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enables or disables automatic flushing of the send queue. If disabled, you must manully call NetPeer.FlushSendQueue() to flush sent messages to network.
|
||||||
|
/// </summary>
|
||||||
|
public bool AutoFlushSendQueue
|
||||||
|
{
|
||||||
|
get { return m_autoFlushSendQueue; }
|
||||||
|
set { m_autoFlushSendQueue = value; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the local ip address to bind to. Defaults to IPAddress.Any. Cannot be changed once NetPeer is initialized.
|
/// Gets or sets the local ip address to bind to. Defaults to IPAddress.Any. Cannot be changed once NetPeer is initialized.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace ChatClient
|
|||||||
s_form = new Form1();
|
s_form = new Form1();
|
||||||
|
|
||||||
NetPeerConfiguration config = new NetPeerConfiguration("chat");
|
NetPeerConfiguration config = new NetPeerConfiguration("chat");
|
||||||
|
config.AutoFlushSendQueue = false;
|
||||||
s_client = new NetClient(config);
|
s_client = new NetClient(config);
|
||||||
|
|
||||||
s_client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
|
s_client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
|
||||||
@@ -95,6 +96,7 @@ namespace ChatClient
|
|||||||
NetOutgoingMessage om = s_client.CreateMessage(text);
|
NetOutgoingMessage om = s_client.CreateMessage(text);
|
||||||
s_client.SendMessage(om, NetDeliveryMethod.ReliableOrdered);
|
s_client.SendMessage(om, NetDeliveryMethod.ReliableOrdered);
|
||||||
Output("Sending '" + text + "'");
|
Output("Sending '" + text + "'");
|
||||||
|
s_client.FlushSendQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// called by the UI
|
// called by the UI
|
||||||
|
|||||||
Reference in New Issue
Block a user