1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-19 00:26:30 +09:00

Better NetSendResult when trying to send on an unconnected connection

This commit is contained in:
lidgren
2012-01-16 09:27:56 +00:00
parent 4cd624c42c
commit 61ec7e3add
4 changed files with 10 additions and 8 deletions

View File

@@ -128,7 +128,7 @@ namespace Lidgren.Network
if (serverConnection == null) if (serverConnection == null)
{ {
LogWarning("Cannot send message, no server connection!"); LogWarning("Cannot send message, no server connection!");
return NetSendResult.Failed; return NetSendResult.FailedNotConnected;
} }
return serverConnection.SendMessage(msg, method, 0); return serverConnection.SendMessage(msg, method, 0);
@@ -143,7 +143,7 @@ namespace Lidgren.Network
if (serverConnection == null) if (serverConnection == null)
{ {
LogWarning("Cannot send message, no server connection!"); LogWarning("Cannot send message, no server connection!");
return NetSendResult.Failed; return NetSendResult.FailedNotConnected;
} }
return serverConnection.SendMessage(msg, method, sequenceChannel); return serverConnection.SendMessage(msg, method, sequenceChannel);

View File

@@ -292,6 +292,9 @@ namespace Lidgren.Network
// called by SendMessage() and NetPeer.SendMessage; ie. may be user thread // called by SendMessage() and NetPeer.SendMessage; ie. may be user thread
internal NetSendResult EnqueueMessage(NetOutgoingMessage msg, NetDeliveryMethod method, int sequenceChannel) internal NetSendResult EnqueueMessage(NetOutgoingMessage msg, NetDeliveryMethod method, int sequenceChannel)
{ {
if (m_status != NetConnectionStatus.Connected)
return NetSendResult.FailedNotConnected;
NetMessageType tp = (NetMessageType)((int)method + sequenceChannel); NetMessageType tp = (NetMessageType)((int)method + sequenceChannel);
msg.m_messageType = tp; msg.m_messageType = tp;

View File

@@ -55,6 +55,8 @@ namespace Lidgren.Network
else else
{ {
// message must be fragmented! // message must be fragmented!
if (recipient.m_status != NetConnectionStatus.Connected)
return NetSendResult.FailedNotConnected;
SendFragmentedMessage(msg, new NetConnection[] { recipient }, method, sequenceChannel); SendFragmentedMessage(msg, new NetConnection[] { recipient }, method, sequenceChannel);
return NetSendResult.Queued; // could be different for each connection; Queued is "most true" return NetSendResult.Queued; // could be different for each connection; Queued is "most true"
} }
@@ -110,13 +112,10 @@ namespace Lidgren.Network
continue; continue;
} }
NetSendResult res = conn.EnqueueMessage(msg, method, sequenceChannel); NetSendResult res = conn.EnqueueMessage(msg, method, sequenceChannel);
if (res == NetSendResult.Dropped) if (res != NetSendResult.Queued && res != NetSendResult.Sent)
{
LogDebug(msg + " dropped immediately due to full queues");
Interlocked.Decrement(ref msg.m_recyclingCount); Interlocked.Decrement(ref msg.m_recyclingCount);
} }
} }
}
else else
{ {
// message must be fragmented! // message must be fragmented!

View File

@@ -8,9 +8,9 @@ namespace Lidgren.Network
public enum NetSendResult public enum NetSendResult
{ {
/// <summary> /// <summary>
/// Message failed to enqueue; for example if there's no connection in place /// Message failed to enqueue because there is no connection
/// </summary> /// </summary>
Failed = 0, FailedNotConnected = 0,
/// <summary> /// <summary>
/// Message was immediately sent /// Message was immediately sent