On 25 Oct 2001 at 17:08 (-0400), David Ford wrote: | I'm fresh in the code, but this has solved my issues with PQconnect* | failing when interrupted by signals. Some of it is sloppy and not to my | liking yet, but I'm still digging through to see if anything else needs | touched. Comments appreciated.
Disclaimer: I may be wrong as hell ;-), but... I'm not sure this is correct. I've tried to /make/ a SIGALRM cause connect to errno==EINTR, but I can't cause this condition. I suspect you have another signal being raised that is causing your symptom. FTR, the textbook definition[1] of EINTR error for connect is: The attempt to establish a connection was interrupted by delivery of a signal that was caught; the connection will be established asynchronously. Please check the attached prog to see if it is representative of your code relating to the connect error you're seeing. If it is, please run it and see if you can get it to cause the EINTR error from connect. If you can't I'm more certain that you have a problem elsewhere. cheers. brent 1. http://www.opengroup.org/onlinepubs/7908799/xns/connect.html -- "Develop your talent, man, and leave the world something. Records are really gifts from people. To think that an artist would love you enough to share his music with anyone is a beautiful thing." -- Duane Allman
#include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #include <signal.h> #include <netdb.h> #include <netinet/in.h> #include <sys/time.h> #include <errno.h> #include <fcntl.h> static int AT = 5; /* usecs for _ualarm to */ int nonblocking(int fd){ int fb = fcntl(fd, F_GETFL, 0); if (fb == -1) return -1; return fcntl(fd, F_SETFL, fb|O_NONBLOCK); } void sigalrm(int arg){ ualarm(AT,0); } int try_connect(){ int s,c; struct sockaddr_in serv; memset(&serv,0,sizeof(serv)); s = socket(PF_INET,SOCK_STREAM,6); nonblocking(s); serv.sin_family = AF_INET; serv.sin_port = htons(80); inet_aton("127.0.0.1",(struct in_addr*)&serv.sin_addr); c = connect(s,(struct sockaddr*)&serv,sizeof(serv)); if( c < 0 && errno == EINTR ) perror("connect (EINTR):"); // this is return c; } int main( int argc, char** argv ){ signal(SIGALRM,sigalrm); ualarm(AT,0); while(1){ try_connect(); if( errno == EBADF ){ break; } sleep(100); // this sleep never really sleeps 100 secs. } puts("ran out of file descriptors as expected."); return 0; }
---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])