9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: bawei@yahoo.com
To: 9fans@cse.psu.edu
Subject: [9fans] Help!
Date: Mon,  2 Apr 2001 08:50:38 +0000	[thread overview]
Message-ID: <9a828r$981$1@news.netple.com> (raw)

This is a program for testing.

#include <u.h>
#include <libc.h>
  int dfd[1000];
  int num;
int echo_server(void)
{
  int pid;
  int i;
  char buf[256];
  int lcfd;
  int clnum;
   char adir[40], ldir[40];
   int n;
  num=0;
  if(announce("tcp!*!8888", adir) < 0) return -1;
  for(;;){
    lcfd = listen(adir, ldir);//listen for a call
    if(lcfd < 0) return -1;
        dfd[num] = accept(lcfd, ldir);
       if(dfd[num] < 0) return -1;
        print("num : %d\n",dfd[num]);

      clnum=num;
      num++;
    pid = rfork(RFPROC|RFMEM);
    switch(pid){// fork a process to echo
      case 0:
      print("%s\n",ldir);
        while((n = read(dfd[clnum], buf, sizeof(buf))) > 0)      {for (i=0;i<num;i++)write(dfd[i], buf, n);   }
        exits(0);
      case -1:
        perror("forking");
      default:
        close(lcfd);
        break;
    }
  }
}
void main(){
  echo_server();
}

And I try to connect from my Windows.

term% 8.out
num : 5
/net/tcp/2
num : 6
/net/tcp/3
..
num : 99
8.out 1497: warning: process exceeds 100 file descriptors
..
num : 110
/net/tcp/106
8.out 1497: suicide: sys: trap: fault read addr=0x0 pc=0x00000000

Some other time I retry it.
term% 8.out
num : 5
/net/tcp/2
..
num : 515
/net/tcp/511

And cannot connect.
What's wrong?

Thanks.


             reply	other threads:[~2001-04-02  8:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-02  8:50 bawei [this message]
2001-04-02 13:12 ` [9fans] Help! Boyd Roberts
2001-04-02 13:16 [9fans] Help! presotto
2001-04-22 14:18 Re[2]: [9fans] X on Plan 9 David Lukes
2001-04-22 22:53 ` [9fans] HELP! Dave Iafrate - CSCI/F1997
2001-04-22 23:12 forsyth
2001-08-29  9:04 [9fans] help! Lei Ding
2001-08-29 13:12 ` Nicholas Waples
2001-08-30 18:59   ` geerten kuiper
2008-01-11 22:57 [9fans] Help! clinton
2008-01-11 23:02 ` john
2008-01-22 17:01   ` Glenn Becker
2008-01-11 23:06 ` john
2008-01-11 23:09 ` Pietro Gagliardi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='9a828r$981$1@news.netple.com' \
    --to=bawei@yahoo.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).