Exemple #1
0
        protected Listener(IPEndPoint endpoint)
        {
#if !DISABLE_NAT
            this.natManager = new MonoTorrent.Nat.NatManager();
#endif
            this.status   = ListenerStatus.NotListening;
            this.endpoint = endpoint;
        }
 public void Dispose()
 {
     if (_tcpListener != null)
     {
         _twitterHandler.Dispose();
         _tcpListener.Stop();
     }
     _listenerStatus = ListenerStatus.Stopped;
 }
Exemple #3
0
 public void Stop()
 {
     Status = ListenerStatus.Stopped;
     if (Listener != null)
     {
         Listener.Close();
         Listener = null;
     }
 }
        internal static string ToSerializedValue(this ListenerStatus value)
        {
            switch (value)
            {
            case ListenerStatus.Uninitialized:
                return("Uninitialized");

            case ListenerStatus.Active:
                return("Active");

            case ListenerStatus.Stopped:
                return("Stopped");
            }
            return(null);
        }
        public void Start()
        {
            try
            {
                Listener = CreateSocket();
                _status = ListenerStatus.Listening;

                Listen();
            }
            catch (SocketException)
            {
                if (Listener == null) return;
                Stop();
                throw;
            }
        }
Exemple #6
0
        public void Start()
        {
            try {
                Listener = CreateSocket();
                Status   = ListenerStatus.Listening;

                Listen();
            } catch (SocketException) {
                if (Listener == null)
                {
                    return;
                }
                Stop();
                throw;
            }
        }
        // 初期化
        void init(int port, AcceptProc acceptProc, object acceptParam, bool localOnly, bool getHostName)
        {
            this.lockObj         = new object();
            this.port            = port;
            this.acceptProc      = acceptProc;
            this.acceptParam     = acceptParam;
            this.status          = ListenerStatus.Trying;
            this.eventObj        = new Event();
            this.halt            = false;
            this.localOnly       = localOnly;
            this.getHostName     = getHostName;
            this.listenRetryTime = ListenRetryTimeDefault;

            // スレッドの作成
            ThreadObj thread = new ThreadObj(new ThreadProc(ListenerThread));

            thread.WaitForInit();
        }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the Listener class.
 /// </summary>
 /// <param name="status">Possible values include: 'Uninitialized',
 /// 'Active', 'Stopped'</param>
 public Listener(string name, string guid, string description, string bindAddress, int bindPort, string connectAddress, int profileId, int listenerTypeId, ListenerStatus status, int?id = default(int?), Profile profile = default(Profile), ListenerType listenerType = default(ListenerType), string covenantToken = default(string), System.DateTime?startTime = default(System.DateTime?))
 {
     Id             = id;
     Name           = name;
     Guid           = guid;
     Description    = description;
     BindAddress    = bindAddress;
     BindPort       = bindPort;
     ConnectAddress = connectAddress;
     ProfileId      = profileId;
     Profile        = profile;
     ListenerTypeId = listenerTypeId;
     ListenerType   = listenerType;
     Status         = status;
     CovenantToken  = covenantToken;
     StartTime      = startTime;
     CustomInit();
 }
Exemple #9
0
        protected virtual void RaiseStatusChanged(ListenerStatus status)
        {
            if (this.natManager != null)
            {
                if (status == ListenerStatus.Listening)
                {
                    this.natManager.Open(this.Protocol, this.Endpoint.Port);
                }
                else
                {
                    this.natManager.Close();
                }
            }

            this.status = status;
            if (StatusChanged != null)
            {
                Toolbox.RaiseAsyncEvent <EventArgs>(StatusChanged, this, EventArgs.Empty);
            }
        }
 public void Start()
 {
     _tcpListener = new TcpListener(IPAddress.Parse(_tcpEndpointDetails.IpAddress), _tcpEndpointDetails.Port);
     _tcpListener.Start();
     try
     {
         TcpClient tcpClient = null;
         while ((tcpClient = _tcpListener.AcceptTcpClient()) != null)
         {
             ITwitterMessageService twitterClient = new TcpMessageService(tcpClient, _logger);
             _twitterHandler.Add(twitterClient);
             twitterClient.Start();
             _logger.LogMessage("Listener added new Tcp Client : " + twitterClient.SessionId);
         }
         _listenerStatus = ListenerStatus.Started;
     }
     catch (SocketException ex)
     {
         _logger.LogException("Start - Listener: ", ex);
     }
 }
Exemple #11
0
 protected ListenerBase(int port)
 {
     _port = port;
         EndPoint = new IPEndPoint(IPAddress.Any, port);
         _status = ListenerStatus.Stopped;
 }
Exemple #12
0
 public void Stop()
 {
     _status = ListenerStatus.Stopped;
         if (Listener != null)
         {
             Listener.Close();
             Listener = null;
         }
 }
        public async Task<string> OpenAsync(CancellationToken cancellationToken)
        {
            if (m_ListenerStatus != ListenerStatus.Stopped)
                throw new InvalidOperationException("listener is not in stopped state");



            m_ListenerStatus = ListenerStatus.Starting;
            try
            {
                List<Task> startTasks = new List<Task>(m_listeningDefinitions.Count());

                foreach (var def in m_listeningDefinitions)
                    startTasks.Add(Task.Run(() => AddStartHost(def), cancellationToken));


                await Task.WhenAll(startTasks);

            }
            catch (TaskCanceledException tce)
            {
                Trace.WriteLine(string.Format("Multipoint listener cancled while trying to start, trying to abort (error:{0})", tce.Message));
                Abort();
            }
            catch (AggregateException ae)
            {
                Abort();
                // something is wrong
                Trace.WriteLine(string.Format("Multi point listener failed to start with error {0} stack:{1}", ae.Message, ae.StackTrace));
                throw new AggregateException(ae);
            }

            catch (Exception E)
            {
                Abort();
                // something is wrong
                Trace.WriteLine(string.Format("Multi point listener failed to start with error {0} stack:{1}", E.Message, E.StackTrace));
                throw new AggregateException(E);
            }
            m_ListenerStatus = ListenerStatus.Started;
            return m_publishingAddress;
        }
        public async Task CloseAsync(CancellationToken cancellationToken)
        {
            try
            {
                List<Task> stopTasks = new List<Task>(m_listeningDefinitions.Count());

                foreach (var def in m_listeningDefinitions)
                    stopTasks.Add(Task.Run(() => StopHost(def), cancellationToken));


                await Task.WhenAll(stopTasks);

                m_ListenerStatus = ListenerStatus.Stopped;

            }
            catch (TaskCanceledException tce)
            {
                // start canceled 
                Trace.WriteLine(string.Format("Multipoint listener cancled while trying to stop, trying to abort(error:{0})", tce.Message));
                Abort();
            }
            catch (AggregateException ae)
            {
                Abort();
                // something is wrong
                Trace.WriteLine(string.Format("Multi point listener failed to start with error {0} stack:{1}", ae.Message, ae.StackTrace));
                throw new AggregateException(ae);
            }

            catch (Exception E)
            {
                Abort();
                // something is wrong
                Trace.WriteLine(string.Format("Multi point listener failed to start with error {0} stack:{1}", E.Message, E.StackTrace));
                throw new AggregateException(E);
            }

            m_ListenerStatus = ListenerStatus.Stopped;
        }
        public void Abort()
        {
            // force stop
            foreach (var def in m_listeningDefinitions)
            {
                StopHost(def);
                Trace.WriteLine(string.Format("Host {0} has been aborted", def.HostTitle));
            }

            m_ListenerStatus = ListenerStatus.Stopped;

        }
Exemple #16
0
 protected virtual void RaiseStatusChanged(ListenerStatus status)
 {
     this.status = status;
     if (StatusChanged != null)
         Toolbox.RaiseAsyncEvent(StatusChanged, this, EventArgs.Empty);
 }
Exemple #17
0
 protected Listener(IPEndPoint endpoint)
 {
     status = ListenerStatus.NotListening;
     this.endpoint = endpoint;
 }