* [9fans] Help!
@ 2001-04-02 8:50 bawei
2001-04-02 13:12 ` [9fans] Help! Boyd Roberts
0 siblings, 1 reply; 2+ messages in thread
From: bawei @ 2001-04-02 8:50 UTC (permalink / raw)
To: 9fans
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [9fans] Re: Help!
2001-04-02 8:50 [9fans] Help! bawei
@ 2001-04-02 13:12 ` Boyd Roberts
0 siblings, 0 replies; 2+ messages in thread
From: Boyd Roberts @ 2001-04-02 13:12 UTC (permalink / raw)
To: 9fans
<bawei@yahoo.com> a crit dans le message news:
9a828r$981$1@news.netple.com...
> This is a program for testing.
> 8.out 1497: warning: process exceeds 100 file descriptors
dead giveaway.
now, this is just off the top of my head, but how about calling
close(dfd[num]);
debugging trivial user mode stuff shouldn't be the purpose of the group.
but hell, i don't work for bell.
--
Boyd Roberts http://www.insultant.net boyd@insultant.net
What do you know about surfing, Major? You're from goddamn New Jersey.
-- Lt. Colonel Kilgore
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-04-02 13:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-02 8:50 [9fans] Help! bawei
2001-04-02 13:12 ` [9fans] Help! Boyd Roberts
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).