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); } } }
public void RemoveListener(RtmpSocketListener socketListener) { if (!this.IsDisposed) { lock (_socketListeners) { _socketListeners.Remove(socketListener); } } }
public void AddListener(IPEndPoint localEndPoint, int acceptCount) { if (!this.IsDisposed) { lock (_socketListeners) { RtmpSocketListener socketListener = new RtmpSocketListener(this, localEndPoint, acceptCount); _socketListeners.Add(socketListener); } } }
/* * 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); }
public void RemoveListener(RtmpSocketListener socketListener) { if(!this.IsDisposed) { lock(_socketListeners) { _socketListeners.Remove(socketListener); } } }
public void AddListener(IPEndPoint localEndPoint, int acceptCount) { if(!this.IsDisposed) { lock(_socketListeners) { RtmpSocketListener socketListener = new RtmpSocketListener(this, localEndPoint, acceptCount); _socketListeners.Add(socketListener); } } }
/* 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; }