Socket help wanted
SANDEEP at S63.Prime.COM
SANDEEP at S63.Prime.COM
Tue Jul 25 02:15:00 AEST 1989
scm at 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 at s63.prime.com 508-879-2960x3711
More information about the Comp.unix.questions
mailing list