为了对 postmaster.c 中的 ListenSocket 进行研究,先将其代码做一个概括(大部分代码省略):
复制代码
/*
* Postmaster main entry point
*/
int
PostmasterMain(int argc, char *argv[])
{
……
status = ServerLoop();
/*
* ServerLoop probably shouldn't ever return, but if it does, close down.
*/
ExitPostmaster(status != STATUS_OK);
return 0; /* not reached */
}
复制代码
然后添加我自己的代码后变成如下样子:
复制代码
/*
* Postmaster main entry point
*/
int
PostmasterMain(int argc, char *argv[])
{
……
/*added by gaojian begin*/
for (i = 0; i < MAXLISTEN; i++)
{
if (ListenSocket[i] != PGINVALID_SOCKET){
frpintf(stderr, "ListenSocket[%d] is: %d. \n", i,ListenSocket[i]);
}else{ break; }
}
/*added by gaojian end*/
status = ServerLoop();
/*
* ServerLoop probably shouldn't ever return, but if it does, close down.
*/
ExitPostmaster(status != STATUS_OK);
return 0; /* not reached */
}
复制代码
启动后运行的结果是显示两行信息:
ListenSocket[0] is 3.
ListenSocket[1] is 4.
至于为何是两行结果,这两行结果在 ServerLoop()中又如何起作用,还有待进一步研究。
本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/07/20/2600628.html,如需转载请自行联系原作者