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

Merge pull request #35 from Therzok/fixes

Different fixes caught by coverity
This commit is contained in:
lidgren
2015-09-06 11:14:20 +02:00
6 changed files with 48 additions and 13 deletions

View File

@@ -171,7 +171,7 @@ namespace Lidgren.Network
if (m_resentMessagesDueToDelay > 0) if (m_resentMessagesDueToDelay > 0)
bdr.AppendLine("Resent messages (delay): " + m_resentMessagesDueToDelay); bdr.AppendLine("Resent messages (delay): " + m_resentMessagesDueToDelay);
if (m_resentMessagesDueToDelay > 0) if (m_resentMessagesDueToHole > 0)
bdr.AppendLine("Resent messages (holes): " + m_resentMessagesDueToHole); bdr.AppendLine("Resent messages (holes): " + m_resentMessagesDueToHole);
int numUnsent = 0; int numUnsent = 0;

View File

@@ -244,12 +244,20 @@ namespace Lidgren.Network
Recycle(msg); Recycle(msg);
} }
static NetEndPoint GetNetEndPoint(string host, int port)
{
IPAddress address = NetUtility.Resolve(host);
if (address == null)
throw new NetException("Could not resolve host");
return new NetEndPoint(address, port);
}
/// <summary> /// <summary>
/// Create a connection to a remote endpoint /// Create a connection to a remote endpoint
/// </summary> /// </summary>
public NetConnection Connect(string host, int port) public NetConnection Connect(string host, int port)
{ {
return Connect(new NetEndPoint(NetUtility.Resolve(host), port), null); return Connect(GetNetEndPoint(host, port), null);
} }
/// <summary> /// <summary>
@@ -257,7 +265,7 @@ namespace Lidgren.Network
/// </summary> /// </summary>
public NetConnection Connect(string host, int port, NetOutgoingMessage hailMessage) public NetConnection Connect(string host, int port, NetOutgoingMessage hailMessage)
{ {
return Connect(new NetEndPoint(NetUtility.Resolve(host), port), hailMessage); return Connect(GetNetEndPoint(host, port), hailMessage);
} }
/// <summary> /// <summary>

View File

@@ -105,7 +105,14 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Gets the number of bytes in the recycled pool /// Gets the number of bytes in the recycled pool
/// </summary> /// </summary>
public int BytesInRecyclePool { get { return m_peer.m_storagePoolBytes; } } public int BytesInRecyclePool
{
get
{
lock (m_peer.m_storagePool)
return m_peer.m_storagePoolBytes;
}
}
#if !USE_RELEASE_STATISTICS #if !USE_RELEASE_STATISTICS
[Conditional("DEBUG")] [Conditional("DEBUG")]

View File

@@ -56,12 +56,29 @@ namespace Lidgren.Network
/// <summary> /// <summary>
/// Gets the number of items in the queue /// Gets the number of items in the queue
/// </summary> /// </summary>
public int Count { get { return m_size; } } public int Count {
get
{
m_lock.EnterReadLock();
int count = m_size;
m_lock.ExitReadLock();
return count;
}
}
/// <summary> /// <summary>
/// Gets the current capacity for the queue /// Gets the current capacity for the queue
/// </summary> /// </summary>
public int Capacity { get { return m_items.Length; } } public int Capacity
{
get
{
m_lock.EnterReadLock();
int capacity = m_items.Length;
m_lock.ExitReadLock();
return capacity;
}
}
/// <summary> /// <summary>
/// NetQueue constructor /// NetQueue constructor

View File

@@ -97,7 +97,9 @@ namespace Lidgren.Network
{ {
#endif #endif
XmlDocument desc = new XmlDocument(); XmlDocument desc = new XmlDocument();
desc.Load(WebRequest.Create(resp).GetResponse().GetResponseStream()); using (var response = WebRequest.Create(resp).GetResponse())
desc.Load(response.GetResponseStream());
XmlNamespaceManager nsMgr = new XmlNamespaceManager(desc.NameTable); XmlNamespaceManager nsMgr = new XmlNamespaceManager(desc.NameTable);
nsMgr.AddNamespace("tns", "urn:schemas-upnp-org:device-1-0"); nsMgr.AddNamespace("tns", "urn:schemas-upnp-org:device-1-0");
XmlNode typen = desc.SelectSingleNode("//tns:device/tns:deviceType/text()", nsMgr); XmlNode typen = desc.SelectSingleNode("//tns:device/tns:deviceType/text()", nsMgr);
@@ -263,11 +265,12 @@ namespace Lidgren.Network
r.ContentType = "text/xml; charset=\"utf-8\""; r.ContentType = "text/xml; charset=\"utf-8\"";
r.ContentLength = b.Length; r.ContentLength = b.Length;
r.GetRequestStream().Write(b, 0, b.Length); r.GetRequestStream().Write(b, 0, b.Length);
using (WebResponse wres = r.GetResponse()) {
XmlDocument resp = new XmlDocument(); XmlDocument resp = new XmlDocument();
WebResponse wres = r.GetResponse();
Stream ress = wres.GetResponseStream(); Stream ress = wres.GetResponseStream();
resp.Load(ress); resp.Load(ress);
return resp; return resp;
} }
} }
}
} }

View File

@@ -72,7 +72,7 @@ namespace Lidgren.Network
public static NetEndPoint Resolve(string ipOrHost, int port) public static NetEndPoint Resolve(string ipOrHost, int port)
{ {
var adr = Resolve(ipOrHost); var adr = Resolve(ipOrHost);
return new NetEndPoint(adr, port); return adr == null ? null : new NetEndPoint(adr, port);
} }
private static IPAddress s_broadcastAddress; private static IPAddress s_broadcastAddress;