1111 *
1212 *
1313 * IDENTIFICATION
14- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.174 2000/10/24 21:33:52 tgl Exp $
14+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.175 2000/10/25 22:27:25 tgl Exp $
1515 *
1616 * NOTES
1717 *
@@ -262,7 +262,7 @@ static void InitSSL(void);
262262#endif
263263
264264#ifdef CYR_RECODE
265- void GetCharSetByHost (char * ,int ,char * );
265+ extern void GetCharSetByHost (char * ,int ,char * );
266266
267267#endif
268268
@@ -803,34 +803,38 @@ ServerLoop(void)
803803Port * port ;
804804fd_set rmask ,
805805wmask ;
806+ struct timeval * timeout = (struct timeval * )NULL ;
806807#ifdef USE_SSL
807- bool no_select = false;
808- #endif
808+ struct timeval timeout_tv ;
809809
810810/*
811- * Wait for something to happen.
811+ * If we are using SSL, there may be input data already read and
812+ * pending in SSL's input buffers. If so, check for additional
813+ * input from other clients, but don't delay before processing.
812814 */
813- memcpy ((char * )& rmask , (char * )& readmask ,sizeof (fd_set ));
814- memcpy ((char * )& wmask , (char * )& writemask ,sizeof (fd_set ));
815-
816- #ifdef USE_SSL
817815for (curr = DLGetHead (PortList );curr ;curr = DLGetSucc (curr ))
818816{
819- if (((Port * )DLE_VAL (curr ))-> ssl &&
820- SSL_pending (((Port * )DLE_VAL (curr ))-> ssl )> 0 )
817+ Port * port = (Port * )DLE_VAL (curr );
818+
819+ if (port -> ssl && SSL_pending (port -> ssl ))
821820{
822- no_select = true;
821+ timeout_tv .tv_sec = 0 ;
822+ timeout_tv .tv_usec = 0 ;
823+ timeout = & timeout_tv ;
823824break ;
824825}
825826}
826- if (no_select )
827- FD_ZERO (& rmask );/* So we don't accept() anything below */
828827#endif
829828
829+ /*
830+ * Wait for something to happen.
831+ */
832+ memcpy ((char * )& rmask , (char * )& readmask ,sizeof (fd_set ));
833+ memcpy ((char * )& wmask , (char * )& writemask ,sizeof (fd_set ));
834+
830835PG_SETMASK (& UnBlockSig );
831836
832- if (select (nSockets ,& rmask ,& wmask , (fd_set * )NULL ,
833- (struct timeval * )NULL )< 0 )
837+ if (select (nSockets ,& rmask ,& wmask , (fd_set * )NULL ,timeout )< 0 )
834838{
835839if (errno == EINTR || errno == EWOULDBLOCK )
836840continue ;
@@ -894,8 +898,10 @@ ServerLoop(void)
894898 (void * )port );
895899}
896900
897- /* Build up new masks for select(). */
898-
901+ /*
902+ * Scan active ports, processing any available input. While we
903+ * are at it, build up new masks for next select().
904+ */
899905nSockets = initMasks (& readmask ,& writemask );
900906
901907curr = DLGetHead (PortList );
@@ -946,7 +952,7 @@ ServerLoop(void)
946952/*
947953 * Can't start backend if max backend count is exceeded.
948954 *
949- * The same whenshutdowning data base.
955+ * The same when data base is in startup/shutdown mode .
950956 */
951957if (Shutdown > NoShutdown )
952958PacketSendError (& port -> pktInfo ,
@@ -966,8 +972,8 @@ ServerLoop(void)
966972/*
967973 * If the backend start fails then keep the connection
968974 * open to report it. Otherwise, pretend there is an
969- * error to closethe connection which will now be
970- * managed by the backend.
975+ * error to closeour descriptor for the connection,
976+ *which will now be managed by the backend.
971977 */
972978if (BackendStartup (port )!= STATUS_OK )
973979PacketSendError (& port -> pktInfo ,
@@ -1067,22 +1073,23 @@ readStartupPacket(void *arg, PacketLen len, void *pkt)
10671073char SSLok ;
10681074
10691075#ifdef USE_SSL
1070- if (! EnableSSL || port -> laddr . sa . sa_family != AF_INET )
1071- /* No SSL when disabled or on Unix sockets */
1072- SSLok = 'N' ;
1076+ /* No SSL when disabled or on Unix sockets */
1077+ if (! EnableSSL || port -> laddr . sa . sa_family != AF_INET )
1078+ SSLok = 'N' ;
10731079else
1074- SSLok = 'S' ;/* Support for SSL */
1080+ SSLok = 'S' ;/* Support for SSL */
10751081#else
10761082SSLok = 'N' ;/* No support for SSL */
10771083#endif
10781084if (send (port -> sock ,& SSLok ,1 ,0 )!= 1 )
10791085{
10801086perror ("Failed to send SSL negotiation response" );
1081- return STATUS_ERROR ;/* Close connection */
1087+ return STATUS_ERROR ;/* Close connection */
10821088}
10831089
10841090#ifdef USE_SSL
1085- if (SSLok == 'S' ) {
1091+ if (SSLok == 'S' )
1092+ {
10861093if (!(port -> ssl = SSL_new (SSL_context ))||
10871094 !SSL_set_fd (port -> ssl ,port -> sock )||
10881095SSL_accept (port -> ssl ) <=0 )