Exemplo n.º 1
0
        public ContextGroupTimeout(Dispatcher dispatcher, ContextGroup contextGroup, std::chrono.nanoseconds timeout)
        {
            this.workingContextGroup = dispatcher;
            this.timeoutTimer        = dispatcher;
//C++ TO C# CONVERTER TODO TASK: Only lambda expressions having all locals passed by reference can be converted to C#:
//ORIGINAL LINE: workingContextGroup.spawn([&, timeout]
            workingContextGroup.spawn(() =>
            {
                try
                {
                    timeoutTimer.sleep(timeout);
                    contextGroup.interrupt();
                }
                catch (InterruptedException)
                {
                }
            });
        }
Exemplo n.º 2
0
        public OperationTimeout(Dispatcher dispatcher, T @object, std::chrono.nanoseconds timeout)
        {
            this.@object      = @object;
            this.timerContext = dispatcher;
            this.timeoutTimer = dispatcher;
//C++ TO C# CONVERTER TODO TASK: Only lambda expressions having all locals passed by reference can be converted to C#:
//ORIGINAL LINE: timerContext.spawn([this, timeout]()
            timerContext.spawn(() =>
            {
                try
                {
                    timeoutTimer.sleep(timeout);
                    timerContext.interrupt();
                }
                catch
                {
                }
            });
        }
Exemplo n.º 3
0
        public void sleep(std::chrono.nanoseconds duration)
        {
            Debug.Assert(dispatcher != null);
            Debug.Assert(context == null);
            if (dispatcher.interrupted())
            {
                throw InterruptedException();
            }

            if (duration.count() == 0)
            {
                dispatcher.yield();
            }
            else
            {
                timer = dispatcher.getTimer();

                var        seconds = std::chrono.duration_cast <std::chrono.seconds>(duration);
                itimerspec expires = new itimerspec();
                expires.it_interval.tv_nsec = expires.it_interval.tv_sec = 0;
                expires.it_value.tv_sec     = seconds.count();
                expires.it_value.tv_nsec    = std::chrono.duration_cast <std::chrono.nanoseconds>(duration - seconds).count();
                timerfd_settime(timer, 0, expires, null);

                ContextPair      contextPair  = new ContextPair();
                OperationContext timerContext = new OperationContext();
                timerContext.interrupted = false;
                timerContext.context     = dispatcher.getCurrentContext();
                contextPair.writeContext = null;
                contextPair.readContext  = timerContext;

                epoll_event timerEvent = new epoll_event();
                timerEvent.events   = EPOLLIN | EPOLLONESHOT;
                timerEvent.data.ptr = contextPair;

                if (epoll_ctl(dispatcher.getEpoll(), EPOLL_CTL_MOD, timer, timerEvent) == -1)
                {
                    throw new System.Exception("Timer::sleep, epoll_ctl failed, " + lastErrorMessage());
                }
                dispatcher.getCurrentContext().interruptProcedure = () =>
                {
                    Debug.Assert(dispatcher != null);
                    Debug.Assert(context != null);
                    OperationContext timerContext = (OperationContext)context;
                    if (!timerContext.interrupted)
                    {
                        uint64_t value = 0;
                        if (global::read(timer, value, sizeof(uint64_t)) == -1)
                        {
                            //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                            //#pragma GCC diagnostic push
                            //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                            //#pragma GCC diagnostic ignored "-Wlogical-op"
                            if (errno == EAGAIN || errno == EWOULDBLOCK)
                            {
                                //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                                //#pragma GCC diagnostic pop
                                timerContext.interrupted = true;
                                dispatcher.pushContext(timerContext.context);
                            }
                            else
                            {
                                throw new System.Exception("Timer::sleep, interrupt procedure, read failed, " + lastErrorMessage());
                            }
                        }
                        else
                        {
                            Debug.Assert(value > 0);
                            dispatcher.pushContext(timerContext.context);
                        }

                        epoll_event timerEvent = new epoll_event();
                        timerEvent.events   = EPOLLONESHOT;
                        timerEvent.data.ptr = null;

                        if (epoll_ctl(dispatcher.getEpoll(), EPOLL_CTL_MOD, timer, timerEvent) == -1)
                        {
                            throw new System.Exception("Timer::sleep, interrupt procedure, epoll_ctl failed, " + lastErrorMessage());
                        }
                    }
                };

                context = timerContext;
                dispatcher.dispatch();
                dispatcher.getCurrentContext().interruptProcedure = null;
                Debug.Assert(dispatcher != null);
                Debug.Assert(timerContext.context == dispatcher.getCurrentContext());
                Debug.Assert(contextPair.writeContext == null);
                Debug.Assert(context == &timerContext);
                context = null;
                timerContext.context = null;
                dispatcher.pushTimer(timer);
                if (timerContext.interrupted)
                {
                    throw InterruptedException();
                }
            }
        }
Exemplo n.º 4
0
//C++ TO C# CONVERTER TODO TASK: 'rvalue references' have no equivalent in C#:
        public P2pContext(Dispatcher dispatcher, TcpConnection && conn, bool isIncoming, NetworkAddress remoteAddress, std::chrono.nanoseconds timedSyncInterval, CORE_SYNC_DATA timedSyncData)
        {
            this.incoming      = isIncoming;
            this.remoteAddress = new NetworkAddress(remoteAddress);
            this.dispatcher    = dispatcher;
            this.contextGroup  = dispatcher;
            this.timeStarted   = Clock.now();
//C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
//ORIGINAL LINE: this.timedSyncInterval = timedSyncInterval;
            this.timedSyncInterval.CopyFrom(timedSyncInterval);
            this.timedSyncData     = new CryptoNote.CORE_SYNC_DATA(timedSyncData);
            this.timedSyncTimer    = dispatcher;
            this.timedSyncFinished = dispatcher;
            this.connection        = new System.TcpConnection(std::move(conn));
            this.writeEvent        = dispatcher;
            this.readEvent         = dispatcher;
            writeEvent.set();
            readEvent.set();
//C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
//ORIGINAL LINE: lastReadTime = timeStarted;
            lastReadTime.CopyFrom(timeStarted); // use current time
            contextGroup.spawn(std::bind(this.timedSyncLoop, this));
        }
Exemplo n.º 5
0
        public void setConnectTimeout(std::chrono.nanoseconds timeout)
        {
//C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
//ORIGINAL LINE: connectTimeout = timeout;
            connectTimeout.CopyFrom(timeout);
        }
Exemplo n.º 6
0
        // setters

        // setters

        public void setTimedSyncInterval(std::chrono.nanoseconds interval)
        {
//C++ TO C# CONVERTER TODO TASK: The following line was determined to be a copy assignment (rather than a reference assignment) - this should be verified and a 'CopyFrom' method should be created:
//ORIGINAL LINE: timedSyncInterval = interval;
            timedSyncInterval.CopyFrom(interval);
        }