void RPCClientCallback(object o) { Errno result = clientAio.Result(); if (result == Errno.ok) { Msg msg = clientAio.GetMsg(); req0.Receive(clientAio); // get ready to receive again byte[] data = msg.Header(); Array.Reverse(data); int c = BitConverter.ToInt32(data, 0); var cookie = cookieCollection.FirstOrDefault(x => x.cookie == c); if (cookie != null) { cookie.msg = msg; lock (cookie.thisLock) { System.Threading.Monitor.Pulse(cookie.thisLock); } cookieCollection.Remove(cookie); } else { Assert.Fail(); } } }
void Received(object o) { System.Threading.Interlocked.Increment(ref countReceived); int j = (int)o; Aio aio = receivers[j]; Errno errno = aio.Result(); if (errno != 0) { return; } Msg msg = aio.GetMsg(); sockets[j].Receive(receivers[j]); uint receivedValue2; msg.ChopU32(out receivedValue2); int receivedValue = (int)receivedValue2; bool valueHasChanged = false; for (;;) { int oldValue = potentials[j]; if (receivedValue + 1 < oldValue) { int beforeExchange = System.Threading.Interlocked.CompareExchange(ref potentials[j], receivedValue + 1, oldValue); if (beforeExchange == oldValue) { valueHasChanged = true; break; } } else { break; } } if (valueHasChanged) { msg.Clear(); msg.AppendU32((uint)potentials[j]); //sockets[j].Send(msg); lock (senders[j]) { senders[j].Wait(); senders[j].SetMsg(msg); sockets[j].Send(senders[j]); } } else { msg.Dispose(); } }
void Whatever(object o) { int j = (int)o; Aio aio = senders[j]; Errno errno = aio.Result(); if (errno != Errno.ok) { aio.GetMsg().Free(); } }
void RPCServerCallback(object o) { Errno result = serverAio.Result(); if (result == Errno.ok) { Msg msg = serverAio.GetMsg(); rep0.Receive(serverAio); // get ready to receive again uint ms; result = msg.TrimU32(out ms); // the actual work. Note that this doesn't need a running thread System.Threading.Thread.Sleep((int)ms); result = rep0.Send(msg, 0); } }