PostmasterMain函数中与 ListenSocket 相关代码摘要

PostgreSQL的postmaster.c 中,PostmasterMain函数中,和ListenSocket数组相关的代码大致如下

/*                                            
 * Postmaster main entry point                                            
 */                                            
int                                            
PostmasterMain(int argc, char *argv[])                                            
{                                            
    ……                                                                      
    /*                                        
     * Establish input sockets.                                        
     */                                        
    for (i = 0; i < MAXLISTEN; i++)                                        
        ListenSocket[i] = PGINVALID_SOCKET;
    if (ListenAddresses)                                        
    {                                        
        ……                                    
        foreach(l, elemlist)                                    
        {                                    
            char       *curhost = (char *) lfirst(l);
            if (strcmp(curhost, "*") == 0)                                
                status = StreamServerPort(AF_UNSPEC, NULL, 
                              (unsigned short) PostPortNumber,                
                              UnixSocketDir,                
                              ListenSocket, MAXLISTEN);                
            else                                
                status = StreamServerPort(AF_UNSPEC, curhost,  
                              (unsigned short) PostPortNumber,                
                              UnixSocketDir,                
                              ListenSocket, MAXLISTEN);                
                                            
            if (status == STATUS_OK)                                
                success++;                            
            else                                
                ereport(WARNING,                            
                        (errmsg("could not create listen socket for \"%s\"",       
                                curhost)));            
        }                                    
                                            
        if (!success && list_length(elemlist))                                    
            ereport(FATAL,                                
                    (errmsg("could not create any TCP/IP sockets")));              
                                            
        list_free(elemlist);                                    
        pfree(rawstring);                                    
    }                                        
    ……                                                                  
    /*                                        
     * check that we have some socket to listen on 
     */                                        
    if (ListenSocket[0] == PGINVALID_SOCKET) 
        ereport(FATAL,                                    
                (errmsg("no socket created for listening"))); 
                                            
    ……                                        
                                            
    status = ServerLoop();                 
    /*                                        
     * ServerLoop probably shouldn't ever return, but if it does, close down. 
     */                                        
    ExitPostmaster(status != STATUS_OK);   
    return 0;                    /* not reached */                    
}                                            

 

posted @ 2012-07-20 09:11  健哥的数据花园  阅读(514)  评论(0编辑  收藏  举报