why error: "accept: Invalid argument"

Y

Yarco

when doing fork in a loop:
Code:
        while(1) {
                tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
                if (tmp_sd == -1) {
                        perror("accept");
                        exit(0);
                }

                //check client ip

                //fork
                pid = fork();
                switch(pid) {
                        case -1:
                                perror("fork");
                                break;
                        case 0:
                                _exit(0);
                }

                close(tmp_sd);
        }
If there's no fork, the code done well.
But if fork, when telnet, it has error: accept: Invalid argument
Thanks a lot.
 
M

Michael Mair

Yarco said:
when doing fork in a loop:
Code:
while(1) {
tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
if (tmp_sd == -1) {
perror("accept");
exit(0);
}

//check client ip

//fork
pid = fork();
switch(pid) {
case -1:
perror("fork");
break;
case 0:
_exit(0);
}

close(tmp_sd);
}
If there's no fork, the code done well.
But if fork, when telnet, it has error: accept: Invalid argument

Platform or compiler specific questions are best asked in a
newsgroup where they are topical.
There are no functions accept(), perror(), fork(), close(), and
_exit() in standard C, so I won't say anything about their use.
comp.unix.programmer might be a good place to ask.

Your switch definitely lacks a default, though, to ward against
unexpected pid values. printf() debug from there...


Cheers
Michael
 
G

Gary Baydo

Yarco said:
when doing fork in a loop:
Code:
while(1) {
tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
if (tmp_sd == -1) {
perror("accept");
exit(0);
}

//check client ip

//fork
pid = fork();
switch(pid) {
case -1:
perror("fork");
break;
case 0:
_exit(0);
}

close(tmp_sd);
}
If there's no fork, the code done well.
But if fork, when telnet, it has error: accept: Invalid argument

Platform or compiler specific questions are best asked in a
newsgroup where they are topical.
There are no functions accept(), perror(), fork(), close(), and
_exit() in standard C, so I won't say anything about their use.
[snip]

Isn't perror() part of the standard? It's declared in stdio.h.

Regards,
Gary
 
M

Michael Mair

Gary said:
Yarco said:
when doing fork in a loop:
Code:
while(1) {
tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
if (tmp_sd == -1) {
perror("accept");
exit(0);
}

//check client ip

//fork
pid = fork();
switch(pid) {
case -1:
perror("fork");
break;
case 0:
_exit(0);
}

close(tmp_sd);
}
If there's no fork, the code done well.
But if fork, when telnet, it has error: accept: Invalid argument

Platform or compiler specific questions are best asked in a
newsgroup where they are topical.
There are no functions accept(), perror(), fork(), close(), and
_exit() in standard C, so I won't say anything about their use.

[snip]

Isn't perror() part of the standard? It's declared in stdio.h.

You are right, thanks for the correction. I got carried away
before breakfast... I really should enforce my "no newsgroups
before caffeine" policy.

Cheers
Michael
 
A

A.A

tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
int
accept(int s,
struct sockaddr * restrict addr,
socklen_t * restrict addrlen);
///////////////////////////////////////
case 0: {
(void)printf("test........?");
_exit(0);
}
 
A

A.A

tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
int
accept(int s,
struct sockaddr * restrict addr,
socklen_t * restrict addrlen);
///////////////////////////////////////
case 0: {
(void)printf("test........?");
_exit(0);
}
 
A

A.A

tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
int
accept(int s,
struct sockaddr * restrict addr,
socklen_t * restrict addrlen);
///////////////////////////////////////
case 0: {
(void)printf("test........?");
_exit(0);
}
 
A

A.A

tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
int
accept(int s,
struct sockaddr * restrict addr,
socklen_t * restrict addrlen);
///////////////////////////////////////
case 0: {
(void)printf("test........?");
_exit(0);
}
 
K

Keith Thompson

Yarco said:
when doing fork in a loop:
Code:
while(1) {
tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
if (tmp_sd == -1) {
perror("accept");
exit(0);
}

//check client ip

//fork
pid = fork();
switch(pid) {
case -1:
perror("fork");
break;
case 0:
_exit(0);
}

close(tmp_sd);
}
If there's no fork, the code done well.
But if fork, when telnet, it has error: accept: Invalid argument

accept() and for() are not standard C functions. (Neither are _exit()
and close().)

Try comp.unix.programmer.
 
Y

Yarco

I've posted it in comp.unix.programmer. But nobody answer it.

my code is Ok when compiling.
But when i "telnet" the server, it gets error:
accept: Invalid argument.
Then quit.
But without "fork" process, i "telnet" the server, and the server is
still running.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top