4.3.3.2 master_notify函数:子进程写status_fd管道

来源:互联网 发布:python3网络编程 pdf 编辑:程序博客网 时间:2024/05/29 11:43

对status_fd管道的读在master_status_event回调函数中执行。对它的写被放在一个专门的c文件中:master_proto.c

/master/ master_proto.c/* DESCRIPTION/*     Themaster process provides a standard environment for its/*     childprocesses. Part of this environment is a pair of file/*     descriptorsthat the master process shares with all child/*     processesthat provide the same service./* .IP MASTER_LISTEN_FD/*     Theshared file descriptor for accepting client connection/*     requests.The master process listens on this socket or FIFO/*     whenall child processes are busy./* .IP MASTER_STATUS_FD/*     Theshared file descriptor for sending child status updates to/*     themaster process./* .PP/*     Achild process uses master_notify() to send a status notification/*     messageto the master process./* .IP MASTER_STAT_AVAIL/*     Thechild process is ready to accept client connections./* .IP MASTER_STAT_TAKEN/*     Untilfurther notice, the child process is unavailable for/*     acceptingclient connections./* .PP/*     Whena child process terminates without sending a status update,/*     themaster process will figure out that the child is no longer/*     available.65 int    master_notify(int pid, unsigned generation, int status) 66 { 67    const char *myname = "master_notify"; 68    MASTER_STATUS stat; 69 70    /* 71     * We use a simple binary protocol to minimize security risks. Since this 72     * is local IPC, there are no byte order or word length issues. The 73      * server treats this information as gossip, sosending a bad PID or a 74     * bad status code will only have amusement value. 75     */ 76    stat.pid = pid; 77    stat.gen = generation; 78    stat.avail = status; 79 80    if (write(MASTER_STATUS_FD, (void *) &stat, sizeof(stat)) !=sizeof(stat)) { 81        if (msg_verbose) 82            msg_info("%s: status %d: %m", myname, status); 83        return (-1); 84     }else { 85        if (msg_verbose) 86             msg_info("%s: status %d",myname, status); 87        return (0); 88     } 89 }

 

master_notify在single_server.c,multi_server.c,trigger_server.c,event_server.c中被调用,一旦运行模板准备为业务模块提供服务了,就通知父进程该子进程将进入工作状态,让父进程将相关MASTER_PROC结构体的avail字段设为MASTER_STAT_TAKEN。
0 0
原创粉丝点击