Hi
I'm about to kill myself over windows stability issues. I'm using windows CE 5.0 client side, which proved a total disaster and now I'm facing win2008 hell.
Following code works fine, except on win2008:
private void Produce() { while (running) { try { Socket client = tcpl.Accept(); int wi = writeind[trdid]; client.SendTimeout = 2000 + wi * 100; // Debug.WriteLine("SOCK " + client.SendTimeout); queue[trdid][wi] = client; if (++wi == queuelength) wi = 0; writeind[trdid] = wi; arearr[trdid].Set(); if (++trdid == numthreads) trdid = 0; } catch (SocketException) { Thread.Sleep(100); } } } private void Consume(object obj) { int trdnum = (int)obj; AutoResetEvent are = arearr[trdnum]; Socket[] tcpq = queue[trdnum]; int ri = 0; int riasync = 0; while (running) { are.WaitOne(1000); while (ri != writeind[trdnum]) { Socket sock = tcpq[ri]; try { // Debug.WriteLine("REQUEST RECEIVED"); sock.ReceiveTimeout = 2000; sock.SendTimeout = 2000; try { if (false)//true)//sock.Poll(10000, SelectMode.SelectRead)) { // Debug.WriteLine("SYNC"); ConsumeSocket(sock, trdnum, data[trdnum]); } else { // async receive! // Debug.WriteLine("ASYNC"); AsyncObject ao = new AsyncObject(); ao.tid = trdnum; ao.sock = sock; sock.BeginReceive(ao.buf, 0, ao.buf.Length, SocketFlags.None, AsyncReceive, ao); } } catch (SocketException se) { Debug.WriteLine("caught exception " + se.Message); } } catch (Exception ex) { Debug.WriteLine("Exception occured in socketlistener: " + ex.Message); try { sock.Close(); } catch (Exception) { } } if (++ri == queuelength) ri = 0; } } } public class AsyncObject { public byte[] buf = new byte[1000]; public Socket sock; public List<byte> fullbuf = new List<byte>(); public int contentlength = -1; public int bodypos = -1; public int tid; }
So I'm doing a synchronous accept and an async receive, which is how I believe a multithreaded socket server should be implemented. It works ok on win7 (64) but on *** win2008 (r2 64), for some blackboxed reason it's giving 100% cpu whenever beginreceive is called multiple times (*I think*) on -different- incoming sockets. The application keeps working btw, it's just eating away one of my (2) cores. The sync routine is working without issues, but obviously is slower/not scalable.
I found some other posts from people with this exact same issue but no acceptable solutions. Is it at all possible to implement an async socket server on windows 2008, cause I'll do it, whatever mountain I have to climb/demons to slay.
Now seriously, I'm losing all credibility here. People are depending on this application, it's their daily hell and it shouldn't go 100%cpu on stuff that's just supposed to work.
I can accept/respect the 'we bugged it on purpose' answer, pm me if this is the case. Thanks!