main->PostmasterMain->ServerLoop: for(;;){ ... //会阻塞在这,监视文件描述符的变化 selres = select(nSockets, &rmask, NULL, NULL, &timeout); if (selres > 0){ for (i = 0; i < MAXLISTEN; i++){ //找一个有效的fd if (ListenSocket[i] == PGINVALID_SOCKET) break; if (FD_ISSET(ListenSocket[i], &rmask)){ port = ConnCreate(ListenSocket[i]);->StreamConnection->accept BackendStartup(port);//fork进程 |-- pid = fork_process(); | if (pid == 0){//child | InitPostmasterChild(); | ClosePostmasterPorts(false); | BackendInitialize(port); | //该函数不会返回 | BackendRun(port);->PostgresMain: | |-- for (;;){ | | if (send_ready_for_query){ | | ... | | ReadyForQuery(whereToSendOutput);->pq_flush();->internal_flush->secure_write->secure_raw_write->send | | send_ready_for_query = false; | | } | | firstchar = ReadCommand(&input_message); | | switch(firstchar):{ | | case 'Q':exec_simple_query(query_string); | | ... | | } | |-- } | } | ...father |-- return STATUS_OK //关闭father socket StreamClose(port->sock); ConnFree(port); } } } }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。