المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : C# Server running in mono on linux



C# Programming
02-03-2010, 10:53 PM
I have this simple code running on my windows server just fine, but when I run it in mono after a couple days I start getting only OutOfMemory exceptions.

public static byte [] TryReceive (Socket sock, out int nLength)
{
nLength = 0;
try {
int size = sizeof(int);
byte [] data;
int recv = 0;
int offset = 0;

data = new byte [size];
while (size > 0) {
recv = sock.Receive(data, offset, size, SocketFlags.None);
if (recv == 0)
return null;
offset += recv;
size -= recv;
} // Makes sure I read the correct number of bytes for an integer

//Gets the size of the entire packet
size = BitConverter.ToInt32(data, 0);
offset = 0;
data = new byte [size];

while (size > 0) {
recv = sock.Receive(data, offset, size, SocketFlags.None);
offset += recv;
size -= recv;
} // Reads in the entire packet
nLength = data.Length;
byte [] dataGraph = new byte [data.Length - 1];
Array.Copy(data, 1, dataGraph, 0, dataGraph.Length);
//First byte is boolean specifying if it's compressed
if (BitConverter.ToBoolean(data, 0))
dataGraph = DecompressBytes(dataGraph);
return dataGraph;
}
catch (OutOfMemoryException) { ObeServer.log.Log(1, "OutOfMemory when receiving packet."); return null; }
//This error occurs after running for a a couple days on mono
}

Could someone please see something that might be causing this?
TIA