Esempio n. 1
0
        private async Task startEventTask()
        {
            bool wasKilled = false;

            try {
                while (!(wasKilled && waitingEvents.IsEmpty))
                {
                    await waitingEventsSignal.Task.ConfigureAwait(false);

                    waitingEventsSignal.Reset();

                    WatcherSetEventPair @event;
                    while (waitingEvents.TryDequeue(out @event))
                    {
                        if (@event == eventOfDeath)
                        {
                            wasKilled = true;
                        }
                        else
                        {
                            await processEvent(@event).ConfigureAwait(false);
                        }
                    }
                }
            } catch (Exception e) {
                LOG.warn("Exception occurred in EventTask", e);
            }
            LOG.info("EventTask shut down for session: 0x" +
                     getSessionId().ToHexString());
        }
Esempio n. 2
0
        internal override async Task doTransport(int waitTimeOut)
        {
            var delay = Task.Delay(waitTimeOut < 0 ? 0 : waitTimeOut);
            await Task.WhenAny(somethingIsPending.Task, SocketAsyncEventTask, delay).ConfigureAwait(false);

            somethingIsPending.Reset();

            // Everything below and until we get back to the select is
            // non blocking, so time is effectively a constant. That is
            // Why we just have to do this once, here
            updateNow();

            if (SocketAsyncEventTask.IsCompleted && SocketAsyncEventTask.Result == SocketAsyncOperation.Connect)
            {
                updateLastSendAndHeard();
                clientCnxn.primeConnection();
                SocketAsyncEventTask = SocketActionAsync(socket.ReceiveAsync);
            }

            doIO();

            if (clientCnxn.getState().isConnected())
            {
                lock (clientCnxn.outgoingQueue)
                {
                    if (findSendablePacket() != null)
                    {
                        enableWrite();
                    }
                }
            }
        }
Esempio n. 3
0
        internal override async Task doTransport(int waitTimeOut)
        {
            await Task.WhenAny(somethingIsPending.Task, Task.Delay(waitTimeOut < 0 ? 0 : waitTimeOut)).ConfigureAwait(false);

            somethingIsPending.Reset();

            // Everything below and until we get back to the select is
            // non blocking, so time is effectively a constant. That is
            // Why we just have to do this once, here
            updateNow();

            if (Connectable)
            {
                if (connectEventArgs.SocketError == SocketError.Success)
                {
                    updateLastSendAndHeard();
                    clientCnxn.primeConnection();
                }
                else
                {
                    throw new SocketException((int)connectEventArgs.SocketError);
                }
            }

            doIO();

            if (pendingIncomingDataNotifierState.TrySetValue(NOTRUNNING, RUNNING))
            {
                if (socket.ReceiveAsync(receiveEventArgs) == false)
                {
                    ReceiveCompleted();
                }
            }

            if (receiveEventArgs.SocketError != SocketError.Success)
            {
                throw new SocketException((int)receiveEventArgs.SocketError);
            }

            if (clientCnxn.getState().isConnected())
            {
                lock (clientCnxn.outgoingQueue)
                {
                    if (findSendablePacket() != null)
                    {
                        enableWrite();
                    }
                }
            }
        }