mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +00:00 
			
		
		
		
	refine the signal manager.
This commit is contained in:
		
							parent
							
								
									7996b3b789
								
							
						
					
					
						commit
						d317528af9
					
				
					 1 changed files with 21 additions and 19 deletions
				
			
		| 
						 | 
				
			
			@ -374,8 +374,6 @@ SrsSignalManager::SrsSignalManager(SrsServer* server)
 | 
			
		|||
 | 
			
		||||
SrsSignalManager::~SrsSignalManager()
 | 
			
		||||
{
 | 
			
		||||
    srs_freep(pthread);
 | 
			
		||||
    
 | 
			
		||||
    srs_close_stfd(signal_read_stfd);
 | 
			
		||||
    
 | 
			
		||||
    if (sig_pipe[0] > 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -384,24 +382,13 @@ SrsSignalManager::~SrsSignalManager()
 | 
			
		|||
    if (sig_pipe[1] > 0) {
 | 
			
		||||
        ::close(sig_pipe[1]);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    srs_freep(pthread);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int SrsSignalManager::initialize()
 | 
			
		||||
{
 | 
			
		||||
    int ret = ERROR_SUCCESS;
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int SrsSignalManager::start()
 | 
			
		||||
{
 | 
			
		||||
    int ret = ERROR_SUCCESS;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
    * Note that if multiple processes are used (see below), 
 | 
			
		||||
    * the signal pipe should be initialized after the fork(2) call 
 | 
			
		||||
    * so that each process has its own private pipe.
 | 
			
		||||
    */
 | 
			
		||||
    struct sigaction sa;
 | 
			
		||||
    
 | 
			
		||||
    /* Create signal pipe */
 | 
			
		||||
    if (pipe(sig_pipe) < 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -410,6 +397,24 @@ int SrsSignalManager::start()
 | 
			
		|||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    if ((signal_read_stfd = st_netfd_open(sig_pipe[0])) == NULL) {
 | 
			
		||||
        ret = ERROR_SYSTEM_CREATE_PIPE;
 | 
			
		||||
        srs_error("create signal manage st pipe failed. ret=%d", ret);
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int SrsSignalManager::start()
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
    * Note that if multiple processes are used (see below), 
 | 
			
		||||
    * the signal pipe should be initialized after the fork(2) call 
 | 
			
		||||
    * so that each process has its own private pipe.
 | 
			
		||||
    */
 | 
			
		||||
    struct sigaction sa;
 | 
			
		||||
    
 | 
			
		||||
    /* Install sig_catcher() as a signal handler */
 | 
			
		||||
    sa.sa_handler = SrsSignalManager::sig_catcher;
 | 
			
		||||
    sigemptyset(&sa.sa_mask);
 | 
			
		||||
| 
						 | 
				
			
			@ -440,10 +445,6 @@ int SrsSignalManager::cycle()
 | 
			
		|||
{
 | 
			
		||||
    int ret = ERROR_SUCCESS;
 | 
			
		||||
 | 
			
		||||
    if (signal_read_stfd == NULL) {
 | 
			
		||||
        signal_read_stfd = st_netfd_open(sig_pipe[0]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int signo;
 | 
			
		||||
    
 | 
			
		||||
    /* Read the next signal from the pipe */
 | 
			
		||||
| 
						 | 
				
			
			@ -852,6 +853,7 @@ int SrsServer::cycle()
 | 
			
		|||
#else
 | 
			
		||||
    srs_warn("main cycle terminated, system quit normally.");
 | 
			
		||||
    dispose();
 | 
			
		||||
    srs_trace("srs terminated");
 | 
			
		||||
    exit(0);
 | 
			
		||||
#endif
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue