scm@datlog.co.uk ( Steve Mawer ) (07/18/89)
I have a problem with BSD sockets, which I hope someone on the net can give me assistance with. I have an application which listens on a well-known port, accepts a connection and execs a child process, then awaits further connects. When a predetermined number of connections has been made, my program has to stop listening until one or more of its children terminates, freeing connection capacity for more connections. This is to allow potential connectees to try other machines for a connection when capacity on one machine is reached. With the listen pending, the connection happens even when I'm not doing an accept, hanging up the connecting process (although other connects will fail due to the listen queue being full). The program has to run in a number of environments, including Ultrix and AIX. The Excelan implementation is no problem, due to the way in which they've done the socket interface (which is a pain in other ways). My problem is - how can I stop the outstanding listen? I've RTFMd but can find no relevant information. My documentation describes fully how make sockets and get connections, but not how to suspend them in a temporary manner. I've tried closing the listening socket, but I then can't re-open it due to EADDRINUSE errors. I've tried to setsockopt to SO_ACCEPTCONN 'off', but that seems to have no effect (on AIX, BTW). Shutdown seems interesting, but there doesn't seem to be a corresponding openup call to restart the shutdown part, it also seems to me that it only stops 'sends' and/or 'receives', not 'reads' and/or 'writes'(?). Is what I'm attempting impossible, or am I just missing the obvious? Please e-mail, and I'll summarise to the net. - Steve C. Mawer <scm@datlog.co.uk> or < {backbone}!ukc!datlog!scm > Voice: +44 1 863 0383 (x2153) -- Steve C. Mawer <scm@datlog.co.uk> or < {backbone}!ukc!datlog!scm > Voice: +44 1 863 0383 (x2153)
SANDEEP@S63.Prime.COM (07/24/89)
scm@datlog.UUCP writes : >I have an application which listens on a well-known port, accepts a >connection and execs a child process, then awaits further connects. I haven't tried this, but seems like it should work: #define MAXBACK 1 int numconn; server() { int oldmask; numconn = 0; /*create and bind socket */ signal(SIGCHLD,decnumconn); for(;;) { if (numconn < MAXCONN) { err = listen(s,MAXBACK); oldmask = signal(SIGCHLD); sigblock(SIGCHLD); numconn++; sigsetmask(oldmask); /* accept,fork, etc. */ } } } decnumconn() { numconn--; } client() { /*create and bind socket */ while ((connect(..,..,..) < 0) { if (errno != ECONNREFUSED) return(-1); /* or whatever */ } /* transfer data */ } -------------------------------------- In_Real_Life: Sandeep Srivastava Prime Computer, Natick, MA 01701. Internet : sandeep@s63.prime.com 508-879-2960x3711
SANDEEP@S63.Prime.COM (07/24/89)
scm@datlog.UUCP writes : >I have an application which listens on a well-known port, accepts a >connection and execs a child process, then awaits further connects. Please read my previous response as: #define MAXBACK 1 int numconn; server() { int oldmask,mask; numconn = 0; /*create and bind socket */ signal(SIGCHLD,decnumconn); for(;;) { if (numconn < MAXCONN) { err = listen(s,MAXBACK); mask = signal(SIGCHLD); oldmask = sigblock(mask); numconn++; sigsetmask(oldmask); /* accept,fork, etc. */ } } } decnumconn() { numconn--; } client() { /*create and bind socket */ while ((connect(..,..,..) < 0) { if (errno != ECONNREFUSED) return(-1); /* or whatever */ } /* transfer data */ } -------------------------------------- In_Real_Life: Sandeep Srivastava Prime Computer, Natick, MA 01701. Internet : sandeep@s63.prime.com 508-879-2960x3711 /* End of text from S63:comp.unix.questions */