Example #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);
                }
            }
        }
Example #2
0
 public void RemoveListener(RtmpSocketListener socketListener)
 {
     if (!base.IsDisposed)
     {
         lock (this._socketListeners)
         {
             this._socketListeners.Remove(socketListener);
         }
     }
 }
Example #3
0
        public void RemoveListener(RtmpSocketListener socketListener)
		{
			if(!this.IsDisposed)
			{
				lock(_socketListeners)
				{
					_socketListeners.Remove(socketListener);
				}
			}
        }
Example #4
0
		public void AddListener(IPEndPoint localEndPoint, int acceptCount)
		{
			if(!this.IsDisposed)
			{
				lock(_socketListeners)
				{
                    RtmpSocketListener socketListener = new RtmpSocketListener(this, localEndPoint, acceptCount);
					_socketListeners.Add(socketListener);
				}
			}
		}
Example #5
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);
        }
Example #6
0
 internal RtmpSocketListener[] GetSocketListeners()
 {
     RtmpSocketListener[] array = null;
     if (!base.IsDisposed)
     {
         lock (this._socketListeners)
         {
             array = new RtmpSocketListener[this._socketListeners.Count];
             this._socketListeners.CopyTo(array, 0);
         }
     }
     return(array);
 }
Example #7
0
 internal void BeginAcceptCallback(IAsyncResult ar)
 {
     if (!base.IsDisposed)
     {
         RtmpSocketListener asyncState = ar.AsyncState as RtmpSocketListener;
         try
         {
             System.Net.Sockets.Socket socket = asyncState.Socket.EndAccept(ar);
             socket.NoDelay           = FluorineConfiguration.Instance.FluorineSettings.RtmpServer.RtmpTransportSettings.TcpNoDelay;
             socket.ReceiveBufferSize = FluorineConfiguration.Instance.FluorineSettings.RtmpServer.RtmpTransportSettings.ReceiveBufferSize;
             socket.SendBufferSize    = FluorineConfiguration.Instance.FluorineSettings.RtmpServer.RtmpTransportSettings.SendBufferSize;
             asyncState.RtmpServer.InitializeConnection(socket);
             asyncState.Socket.BeginAccept(new AsyncCallback(this.BeginAcceptCallback), asyncState);
         }
         catch (Exception exception)
         {
             if (this.HandleError(exception))
             {
                 asyncState.RtmpServer.RaiseOnError(exception);
             }
         }
     }
 }
Example #8
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;
		}