Esempio n. 1
0
        internal void BeginAcceptCallback(IAsyncResult ar)
        {
            if (!this.IsDisposed)
            {
                RtmpSocketListener listener = ar.AsyncState as RtmpSocketListener;
                try
                {
                    //Get accepted socket
                    Socket acceptedSocket = listener.Socket.EndAccept(ar);
                    if (acceptedSocket.Connected == false)
                    {
                        return;
                    }

#if !(NET_1_1)
                    acceptedSocket.NoDelay = FluorineConfiguration.Instance.FluorineSettings.RtmpServer.RtmpTransportSettings.TcpNoDelay;//true;
#endif
                    //Adjust buffer size
#if NET_1_1
                    try
                    {
                        acceptedSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, FluorineConfiguration.Instance.FluorineSettings.RtmpServer.RtmpTransportSettings.ReceiveBufferSize);
                    }
                    catch (SocketException ex)
                    {
                        log.Warn(__Res.GetString(__Res.SocketServer_SocketOptionFail, "ReceiveBuffer"), ex);
                    }
                    try
                    {
                        acceptedSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, FluorineConfiguration.Instance.FluorineSettings.RtmpServer.RtmpTransportSettings.SendBufferSize);
                    }
                    catch (SocketException ex)
                    {
                        log.Warn(__Res.GetString(__Res.SocketServer_SocketOptionFail, "SendBuffer"), ex);
                    }
#else
                    acceptedSocket.ReceiveBufferSize = FluorineConfiguration.Instance.FluorineSettings.RtmpServer.RtmpTransportSettings.ReceiveBufferSize;
                    acceptedSocket.SendBufferSize    = FluorineConfiguration.Instance.FluorineSettings.RtmpServer.RtmpTransportSettings.SendBufferSize;
#endif

                    listener.RtmpServer.InitializeConnection(acceptedSocket);
                }
                catch (Exception ex)
                {
                    //log.Error(__Res.GetString(__Res.SocketServer_ListenerFail), ex);
                    if (HandleError(ex))
                    {
                        listener.RtmpServer.RaiseOnError(ex);
                    }
                }
                finally
                {
                    //Continue to accept
                    listener.Socket.BeginAccept(new AsyncCallback(BeginAcceptCallback), listener);
                }
            }
        }
Esempio n. 2
0
 public void RemoveListener(RtmpSocketListener socketListener)
 {
     if (!this.IsDisposed)
     {
         lock (_socketListeners)
         {
             _socketListeners.Remove(socketListener);
         }
     }
 }
Esempio n. 3
0
 public void AddListener(IPEndPoint localEndPoint, int acceptCount)
 {
     if (!this.IsDisposed)
     {
         lock (_socketListeners)
         {
             RtmpSocketListener socketListener = new RtmpSocketListener(this, localEndPoint, acceptCount);
             _socketListeners.Add(socketListener);
         }
     }
 }
Esempio n. 4
0
        /*
         * private void IdleCheck(object state)
         *      {
         *  if (!IsDisposed)
         *  {
         *      //Disable timer event
         *      _idleTimer.Change(Timeout.Infinite, Timeout.Infinite);
         *      try
         *      {
         *          int loopSleep = 0;
         *          RtmpServerConnection[] connections = GetConnections();
         *          if (connections != null)
         *          {
         *              foreach (RtmpServerConnection connection in connections)
         *              {
         *                  if (IsDisposed)
         *                      break;
         *                  try
         *                  {
         *                      if (connection != null && connection.IsActive)
         *                      {
         *                          //Check the idle timeout
         *                          if (DateTime.Now > (connection.LastAction.AddMilliseconds(_idleTimeOutValue)))
         *                          {
         *                              //connection.Close();
         *                          }
         *                      }
         *                  }
         *                  finally
         *                  {
         *                      ThreadPoolEx.LoopSleep(ref loopSleep);
         *                  }
         *              }
         *          }
         *      }
         *      finally
         *      {
         *          //Restart the timer event
         *          if (!IsDisposed)
         *              _idleTimer.Change(_idleCheckInterval, _idleCheckInterval);
         *      }
         *  }
         *      }
         */

        internal RtmpSocketListener[] GetSocketListeners()
        {
            RtmpSocketListener[] socketListeners = null;
            if (!this.IsDisposed)
            {
                lock (_socketListeners)
                {
                    socketListeners = new RtmpSocketListener[_socketListeners.Count];
                    _socketListeners.CopyTo(socketListeners, 0);
                }
            }
            return(socketListeners);
        }
Esempio n. 5
0
        public void RemoveListener(RtmpSocketListener socketListener)
		{
			if(!this.IsDisposed)
			{
				lock(_socketListeners)
				{
					_socketListeners.Remove(socketListener);
				}
			}
        }
Esempio n. 6
0
		public void AddListener(IPEndPoint localEndPoint, int acceptCount)
		{
			if(!this.IsDisposed)
			{
				lock(_socketListeners)
				{
                    RtmpSocketListener socketListener = new RtmpSocketListener(this, localEndPoint, acceptCount);
					_socketListeners.Add(socketListener);
				}
			}
		}
Esempio n. 7
0
        /*
        private void IdleCheck(object state)
		{
            if (!IsDisposed)
            {
                //Disable timer event
                _idleTimer.Change(Timeout.Infinite, Timeout.Infinite);
                try
                {
                    int loopSleep = 0;
                    RtmpServerConnection[] connections = GetConnections();
                    if (connections != null)
                    {
                        foreach (RtmpServerConnection connection in connections)
                        {
                            if (IsDisposed)
                                break;
                            try
                            {
                                if (connection != null && connection.IsActive)
                                {
                                    //Check the idle timeout
                                    if (DateTime.Now > (connection.LastAction.AddMilliseconds(_idleTimeOutValue)))
                                    {
                                        //connection.Close();
                                    }
                                }
                            }
                            finally
                            {
                                ThreadPoolEx.LoopSleep(ref loopSleep);
                            }
                        }
                    }
                }
                finally
                {
                    //Restart the timer event
                    if (!IsDisposed)
                        _idleTimer.Change(_idleCheckInterval, _idleCheckInterval);
                }
            }
		}
        */

		internal RtmpSocketListener[] GetSocketListeners()
		{
            RtmpSocketListener[] socketListeners = null;
			if(!this.IsDisposed)
			{
				lock(_socketListeners)
				{
                    socketListeners = new RtmpSocketListener[_socketListeners.Count];
					_socketListeners.CopyTo(socketListeners, 0);
				}

			}
			return socketListeners;
		}