Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!bloom-beacon!primerd!ENI!S63!SANDEEP From: SANDEEP@S63.Prime.COM Newsgroups: comp.unix.questions Subject: Re: Socket help wanted Message-ID: <100300001@S63.Prime.COM> Date: 24 Jul 89 16:15:00 GMT References: <2145@dlvax2.datlog.co.uk> Lines: 60 Nf-ID: #R:dlvax2.datlog.co.uk:-214500:S63:100300001:000:1028 Nf-From: S63.Prime.COM!SANDEEP Jul 24 16:15:00 1989 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