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(); } } }
protected override void AioCallback(IntPtr argument) { var res = Unit.Ok; switch (State) { case AsyncState.Recv: res = Aio.GetResult(); if (res.IsErr()) { State = AsyncState.Init; tcs.TrySetNngError(res.Err()); return; } State = AsyncState.Init; var msg = Aio.GetMsg(); var message = Factory.CreateMessage(msg); State = AsyncState.Init; tcs.TrySetNngResult(message); break; case AsyncState.Init: default: tcs.TrySetException(new Exception(State.ToString())); break; } }
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); } }
protected override void AioCallback(IntPtr argument) { var res = Unit.Ok; switch (State) { case AsyncState.Init: init(); break; case AsyncState.Recv: res = Aio.GetResult(); if (res.IsErr()) { asyncMessage.requestTcs.TrySetNngError(res.Err()); State = AsyncState.Recv; return; } State = AsyncState.Wait; nng_msg msg = Aio.GetMsg(); var message = Factory.CreateMessage(msg); asyncMessage.requestTcs.SetNngResult(message); break; case AsyncState.Wait: break; case AsyncState.Send: res = Aio.GetResult(); if (res.IsErr()) { HandleFailedSend(); asyncMessage.replyTcs.TrySetNngError(res.Err()); } var currentReq = asyncMessage; init(); currentReq.replyTcs.SetNngResult(); break; } }
protected override void AioCallback(IntPtr argument) { var res = Unit.Ok; switch (State) { case AsyncState.Send: res = Aio.GetResult(); if (res.IsErr()) { HandleFailedSend(); State = AsyncState.Init; sendTcs.TrySetNngError(res.Err()); return; } State = AsyncState.Init; sendTcs.TrySetNngResult(); break; case AsyncState.Recv: res = Aio.GetResult(); if (res.IsErr()) { State = AsyncState.Init; receiveTcs.TrySetNngError(res.Err()); return; } State = AsyncState.Init; nng_msg msg = Aio.GetMsg(); var message = Factory.CreateMessage(msg); receiveTcs.TrySetNngResult(message); break; case AsyncState.Init: default: Console.Error.WriteLine("SendReceive::AioCallback: " + State); State = AsyncState.Init; break; } }