예제 #1
0
        public void Udp()
        {
            this.closeCount = 0;

            var anyEndPoint = new IPEndPoint(IPAddress.Any, Port);
            Udp udp         = this.loop
                              .CreateUdp()
                              .ReceiveStart(anyEndPoint, this.OnReceive);

            this.server = udp;

            IPEndPoint localEndPoint = udp.GetLocalEndPoint();

            Assert.NotNull(localEndPoint);
            Assert.Equal(anyEndPoint.Address, localEndPoint.Address);
            Assert.Equal(Port, localEndPoint.Port);

            Udp client = this.loop.CreateUdp();

            var remoteEndPoint = new IPEndPoint(IPAddress.Loopback, Port);

            byte[] data = Encoding.UTF8.GetBytes("PING");
            client.QueueSend(data, remoteEndPoint, this.OnSendCompleted);

            this.loop.RunDefault();

            Assert.Equal(1, this.connectedCount);
            Assert.Equal(1, this.connectionCount);
            Assert.Equal(2, this.closeCount);
        }
예제 #2
0
        public void Add(
            long afterTime,
            ScheduleHandle handle,
            long slot)
        {
            lock (this)
            {
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().QScheduleAdd(_currentTime, afterTime, handle, slot);
                }

                if (_handleSetMap.ContainsKey(handle))
                {
                    Remove(handle, slot);
                }

                var triggerOnTime = _currentTime + afterTime;
                AddTrigger(slot, handle, triggerOnTime);

                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().AScheduleAdd();
                }
            }
        }
예제 #3
0
        public void Remove(ScheduleHandle handle, long slot)
        {
            lock (this)
            {
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().QScheduleRemove(handle, slot);
                }

                var handleSet = _handleSetMap.Get(handle);
                if (handleSet == null)
                {
                    // If it already has been removed then that's fine;
                    // Such could be the case when 2 timers fireStatementStopped at the same time, and one stops the other
                    return;
                }

                handleSet.Remove(slot);
                _handleSetMap.Remove(handle);

                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().AScheduleRemove();
                }
            }
        }
예제 #4
0
 public void ScheduleRemove(
     AgentInstanceContext agentInstanceContext,
     ScheduleHandle scheduleHandle,
     ScheduleObjectType type,
     string name)
 {
 }
예제 #5
0
 public void QScheduleAdd(
     long currentTime,
     long afterMSec,
     ScheduleHandle handle,
     long slot)
 {
 }
예제 #6
0
        public EchoServer(HandleType handleType)
        {
            this.Loop = new Loop();

            switch (handleType)
            {
            case HandleType.Udp:
                this.server = this.Loop
                              .CreateUdp()
                              .Bind(TestHelper.AnyEndPoint)
                              .ReceiveStart(OnReceive);
                break;

            case HandleType.Tcp:
                this.server = this.Loop
                              .CreateTcp()
                              .SimultaneousAccepts(true)
                              .Listen(TestHelper.LoopbackEndPoint, this.OnConnection, MaximumBacklogSize);
                break;

            case HandleType.Pipe:
                this.server = this.Loop
                              .CreatePipe()
                              .Listen(TestHelper.LocalPipeName, this.OnConnection, MaximumBacklogSize);
                break;

            default:
                throw new InvalidOperationException($"{handleType} not supported.");
            }
        }
예제 #7
0
 /// <summary>Ctor. </summary>
 /// <param name="time">of schedule</param>
 /// <param name="slot">slot</param>
 /// <param name="handle">handle to use</param>
 public ScheduleSetEntry(long time,
                         ScheduleSlot slot,
                         ScheduleHandle handle)
 {
     Time   = time;
     Slot   = slot;
     Handle = handle;
 }
예제 #8
0
 public void ScheduleAdd(
     long nextScheduledTime,
     AgentInstanceContext agentInstanceContext,
     ScheduleHandle scheduleHandle,
     ScheduleObjectType type,
     string name)
 {
 }
예제 #9
0
파일: AsyncTests.cs 프로젝트: heng83/NetUV
        void OnClose(ScheduleHandle handle)
        {
            handle.Dispose();
            this.closeCount++;

            if (!this.resetEvent.IsSet)
            {
                this.resetEvent.Set();
            }
        }
예제 #10
0
 void OnCallback(ScheduleHandle handle)
 {
     if (this.IsShuttingDown)
     {
         this.ShuttingDown();
     }
     else
     {
         this.RunAllTasks(this.preciseBreakoutInterval);
     }
 }
예제 #11
0
        private void ModifyCreateProxy(ScheduleHandle handle)
        {
            if (!(handle is EPStatementHandleCallback))
            {
                return;
            }
            var callback = (EPStatementHandleCallback)handle;
            var sc       = (ScheduleHandleCallback)ScheduleHandleCallbackProxy.NewInstance(_engineUri, _statementName, callback.ScheduleCallback);

            callback.ScheduleCallback = sc;
        }
예제 #12
0
 private void AddTrigger(long slot, ScheduleHandle handle, long triggerTime)
 {
     var handleSet = _timeHandleMap.Get(triggerTime);
     if (handleSet == null)
     {
         handleSet = new SortedDictionary<long, ScheduleHandle>();
         _timeHandleMap.Put(triggerTime, handleSet);
     }
     handleSet.Put(slot, handle);
     _handleSetMap.Put(handle, handleSet);
 }
예제 #13
0
        public void Remove(ScheduleHandle handle, long scheduleSlot)
        {
            if (AuditPath.IsInfoEnabled)
            {
                StringWriter message = new StringWriter();
                message.Write("remove handle ");
                PrintHandle(message, handle);

                AuditPath.AuditLog(_engineUri, _statementName, AuditEnum.SCHEDULE, message.ToString());
            }
            _spi.Remove(handle, scheduleSlot);
        }
예제 #14
0
 private void PrintHandle(StringWriter message, ScheduleHandle handle)
 {
     if (handle is EPStatementHandleCallback)
     {
         var callback = (EPStatementHandleCallback)handle;
         TypeHelper.WriteInstance(message, callback.ScheduleCallback, true);
     }
     else
     {
         TypeHelper.WriteInstance(message, handle, true);
     }
 }
예제 #15
0
 public void ScheduleRemove(
     AgentInstanceContext agentInstanceContext,
     ScheduleHandle scheduleHandle,
     ScheduleObjectType objectType,
     string name)
 {
     ProcScheduleRemove?.Invoke(
         agentInstanceContext,
         scheduleHandle,
         objectType,
         name);
 }
예제 #16
0
 public void ScheduleAdd(
     long nextScheduledTime,
     AgentInstanceContext agentInstanceContext,
     ScheduleHandle scheduleHandle,
     ScheduleObjectType objectType,
     string name)
 {
     ProcScheduleAdd?.Invoke(
         nextScheduledTime,
         agentInstanceContext,
         scheduleHandle,
         objectType,
         name);
 }
예제 #17
0
        private void AddTrigger(ScheduleSlot slot, ScheduleHandle handle, long triggerTime)
        {
            var handleSet = _timeHandleMap.Get(triggerTime);

            if (handleSet == null)
            {
                handleSet = new NullableDictionary <ScheduleSlot, ScheduleHandle>(
                    new OrderedDictionary <ScheduleSlot, ScheduleHandle>());
                _timeHandleMap.Put(triggerTime, handleSet);
            }

            handleSet.Put(slot, handle);
            _handleSetMap.Put(handle, handleSet);
        }
예제 #18
0
        public void Add(long afterMSec, ScheduleHandle handle, long slot)
        {
            if (AuditPath.IsInfoEnabled)
            {
                StringWriter message = new StringWriter();
                message.Write("after ");
                message.Write(afterMSec);
                message.Write(" handle ");
                PrintHandle(message, handle);

                AuditPath.AuditLog(_engineUri, _statementName, AuditEnum.SCHEDULE, message.ToString());

                ModifyCreateProxy(handle);
            }
            _spi.Add(afterMSec, handle, slot);
        }
        public void Add(long afterTime, ScheduleHandle handle, long slot)
        {
            using (Instrument.With(
                       i => i.QScheduleAdd(_currentTime, afterTime, handle, slot),
                       i => i.AScheduleAdd()))
            {
                using (_uLock.Acquire())
                {
                    if (_handleSetMap.ContainsKey(handle))
                    {
                        Remove(handle, slot);
                    }

                    long triggerOnTime = _currentTime + afterTime;

                    AddTrigger(slot, handle, triggerOnTime);
                }
            }
        }
예제 #20
0
        void OnConnectionClosed(ScheduleHandle handle)
        {
            var context = (ConnectionContext)handle.UserToken;

            context.OpenHandles--;

            if (context.OpenHandles > 0)
            {
                return;
            }

            if (this.deplux ||
                context.IsServerConnection)
            {
                if (context.Receive == TransferBytes)
                {
                    this.closedConnections++;
                }
            }
            else
            {
                if (context.Receive == 0)
                {
                    this.closedConnections++;
                }
            }

            if (this.deplux ||
                !context.IsServerConnection)
            {
                if (context.Sent == TransferBytes)
                {
                    this.closedConnections++;
                }
                else
                {
                    if (context.Sent == 0)
                    {
                        this.closedConnections++;
                    }
                }
            }
        }
 public void Remove(ScheduleHandle handle, long scheduleSlot)
 {
     using (Instrument.With(
                i => i.QScheduleRemove(handle, scheduleSlot),
                i => i.AScheduleRemove()))
     {
         using (_uLock.Acquire())
         {
             var handleSet = _handleSetMap.Get(handle);
             if (handleSet == null)
             {
                 // If it already has been removed then that's fine;
                 // Such could be the case when 2 timers fireStatementStopped at the same time, and one stops the other
                 return;
             }
             handleSet.Remove(scheduleSlot);
             _handleSetMap.Remove(handle);
         }
     }
 }
예제 #22
0
        public void Tcp()
        {
            this.closeCount      = 0;
            this.connectedCount  = 0;
            this.connectionCount = 0;

            var anyEndPoint = new IPEndPoint(IPAddress.Loopback, Port);
            Tcp tcpServer   = this.loop.CreateTcp();

            tcpServer.Listen(anyEndPoint, this.OnConnection);
            this.server = tcpServer;

            IPEndPoint localEndPoint = tcpServer.GetLocalEndPoint();

            Assert.NotNull(localEndPoint);
            Assert.Equal(anyEndPoint.Address, localEndPoint.Address);
            Assert.Equal(Port, localEndPoint.Port);

            var error = Assert.Throws <OperationException>(() => tcpServer.GetPeerEndPoint());

            Assert.Equal(ErrorCode.ENOTCONN, error.ErrorCode);

            var remoteEndPoint = new IPEndPoint(IPAddress.Loopback, Port);
            Tcp client         = this.loop.CreateTcp().ConnectTo(remoteEndPoint, this.OnConnected);

            IPEndPoint endPoint = client.GetLocalEndPoint();

            Assert.NotNull(endPoint);
            Assert.Equal(anyEndPoint.AddressFamily, endPoint.AddressFamily);
            Assert.True(endPoint.Port > 0);

            this.loop.RunDefault();

            Assert.Equal(1, this.connectedCount);
            Assert.Equal(1, this.connectionCount);
            Assert.Equal(3, this.closeCount);
        }
예제 #23
0
 static void OnClose(ScheduleHandle handle) => handle.Dispose();
 public bool IsScheduled(ScheduleHandle handle)
 {
     return(_handleSetMap.ContainsKey(handle));
 }
예제 #25
0
 void OnClose(ScheduleHandle handle)
 {
     handle.Dispose();
     this.closeCount++;
 }
예제 #26
0
 public void QScheduleRemove(ScheduleHandle handle, long slot)
 {
 }
예제 #27
0
 public void Remove(ScheduleHandle callback, ScheduleSlot slot)
 {
     Log.Debug(".remove Not implemented, callback=" + callback.GetType().Name);
 }
예제 #28
0
 public void Add(long afterMSec, ScheduleHandle callback, ScheduleSlot slot)
 {
     Log.Debug(".add Not implemented, afterMSec=" + afterMSec + " callback=" + callback.GetType().Name);
     _added.Put(afterMSec, callback);
 }
예제 #29
0
 public bool IsScheduled(ScheduleHandle scheduleHandle)
 {
     return(false);     //To change body of implemented methods use File | Settings | File Templates.
 }
예제 #30
0
 public void QScheduleRemove(ScheduleHandle handle, ScheduleSlot slot)
 {
 }