/// <summary> /// </summary> /// <param name="arg"></param> private async void SendOutgoingUdpMessages(object arg) { object[] args = (object[])arg; AsyncUdpSocketSender sender = (AsyncUdpSocketSender)args[0]; EventPoller <OutgoingUdpMessage> outgoingMessagePoller = (EventPoller <OutgoingUdpMessage>)args[1]; CancellationToken cancellation = (CancellationToken)args[2]; int eventsThisIteration = 0; while (!cancellation.IsCancellationRequested) { // poll for send events outgoingMessagePoller.Poll((m, s, eob) => { // Send udp message if (m.SendType == UdpSendType.SendTo) { sender.BeginSendTo(m.Buffer, 0, m.Size, m.Endpoint); } eventsThisIteration++; return(eventsThisIteration < MaxUdpMessageSendBeforeSleep); }); await Task.Delay(1, cancellation); } }
private PollState LoadNextValues(EventPoller <DataEvent> poller, BatchedData batch) { return(poller.Poll((ev, sequence, endOfBatch) => { var item = ev.CopyOfData(); return item != null && batch.AddDataItem(item); })); }
private static object GetNextValue(EventPoller <DataEvent <object> > poller) { var output = new object[1]; poller.Poll((ev, sequence, endOfBatch) => { output[0] = ev.CopyOfData(); return(false); }); return(output[0]); }
public void Run() { try { while (_running == 1) { if (PollState.Processing != _poller.Poll(_eventHandler)) { Thread.Sleep(0); } } } catch (Exception e) { Console.WriteLine(e); } }
public void Run() { try { while (running) { if (EventPoller <ValueEvent> .PollState.PROCESSING != poller.Poll(this)) { Thread.Yield(); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
// Update is called once per frame private void Update() { // Reset processed message count int msgEventThisFrame = 0; // Poll until max messages or no more messages to receive, copying the message data // into the batched events buffer _receivedMessagePoller.Poll((message, sequence, endOfBatch) => { _batchedEvents[msgEventThisFrame].Message = message; msgEventThisFrame++; return(msgEventThisFrame < MaxUdpMessagesPerFrame); }); // _BatchedEvents is filled with messages pulled off the wire, so process (react to) them // which will mutate the reactor state and then return a set of output events to be further handled for (int i = 0; i < msgEventThisFrame; i++) { RNetManager.React(_batchedEvents[i]); } // React to all of the output events with the a game server reactor _tempEvent.EventId = GameEvent.Event.NetEvent; while (RNetManager.NetEventsQueue.Count > 0) { _tempEvent.NetEvent = RNetManager.NetEventsQueue.Dequeue(); RGameReactor.React(_tempEvent); } _timeSinceLastUpdate += Time.deltaTime; if (_timeSinceLastUpdate < GameReactorUpdateTimeF) { return; } _timeSinceLastUpdate = 0; RGameReactor.React(_updateEvent); }