By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,468 Members | 1,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,468 IT Pros & Developers. It's quick & easy.

why error: "accept: Invalid argument"

P: n/a
when doing fork in a loop:
Expand|Select|Wrap|Line Numbers
  1. while(1) {
  2. tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
  3. if (tmp_sd == -1) {
  4. perror("accept");
  5. exit(0);
  6. }
  7.  
  8. //check client ip
  9.  
  10. //fork
  11. pid = fork();
  12. switch(pid) {
  13. case -1:
  14. perror("fork");
  15. break;
  16. case 0:
  17. _exit(0);
  18. }
  19.  
  20. close(tmp_sd);
  21. }
  22.  
If there's no fork, the code done well.
But if fork, when telnet, it has error: accept: Invalid argument
Thanks a lot.

Nov 16 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Yarco wrote:
when doing fork in a loop:
Expand|Select|Wrap|Line Numbers
  1.          while(1) {
  2.                  tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
  3.                  if (tmp_sd == -1) {
  4.                          perror("accept");
  5.                          exit(0);
  6.                  }
  7.                  //check client ip
  8.                  //fork
  9.                  pid = fork();
  10.                  switch(pid) {
  11.                          case -1:
  12.                                  perror("fork");
  13.                                  break;
  14.                          case 0:
  15.                                  _exit(0);
  16.                  }
  17.                  close(tmp_sd);
  18.          }
  19.  
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
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 16 '05 #2

P: n/a
Thanks

Nov 16 '05 #3

P: n/a
On Wed, 16 Nov 2005 06:02:15 +0100, Michael Mair wrote:
Yarco wrote:
when doing fork in a loop:
Expand|Select|Wrap|Line Numbers
  1.          while(1) {
  2.                  tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
  3.                  if (tmp_sd == -1) {
  4.                          perror("accept");
  5.                          exit(0);
  6.                  }
  7.                  //check client ip
  8.                  //fork
  9.                  pid = fork();
  10.                  switch(pid) {
  11.                          case -1:
  12.                                  perror("fork");
  13.                                  break;
  14.                          case 0:
  15.                                  _exit(0);
  16.                  }
  17.                  close(tmp_sd);
  18.          }
  19.  
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

Nov 16 '05 #4

P: n/a
Gary Baydo wrote:
Isn't perror() part of the standard? It's declared in stdio.h.


perror() is in the standard library.

--
pete
Nov 16 '05 #5

P: n/a
Gary Baydo wrote:
On Wed, 16 Nov 2005 06:02:15 +0100, Michael Mair wrote:

Yarco wrote:
when doing fork in a loop:
Expand|Select|Wrap|Line Numbers
  1.         while(1) {
  2.                 tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
  3.                 if (tmp_sd == -1) {
  4.                         perror("accept");
  5.                         exit(0);
  6.                 }
  7.                 //check client ip
  8.                 //fork
  9.                 pid = fork();
  10.                 switch(pid) {
  11.                         case -1:
  12.                                 perror("fork");
  13.                                 break;
  14.                         case 0:
  15.                                 _exit(0);
  16.                 }
  17.                 close(tmp_sd);
  18.         }
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
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 16 '05 #6

P: n/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);
}

Nov 16 '05 #7

P: n/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);
}

Nov 16 '05 #8

P: n/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);
}

Nov 16 '05 #9

P: n/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);
}

Nov 16 '05 #10

P: n/a
"Yarco" <ya*****@gmail.com> writes:
when doing fork in a loop:
Expand|Select|Wrap|Line Numbers
  1.          while(1) {
  2.                  tmp_sd = accept(sd, (struct sockaddr*)&tmp_sin, &len);
  3.                  if (tmp_sd == -1) {
  4.                          perror("accept");
  5.                          exit(0);
  6.                  }
  7.                  //check client ip
  8.                  //fork
  9.                  pid = fork();
  10.                  switch(pid) {
  11.                          case -1:
  12.                                  perror("fork");
  13.                                  break;
  14.                          case 0:
  15.                                  _exit(0);
  16.                  }
  17.                  close(tmp_sd);
  18.          }
  19.  
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 16 '05 #11

P: n/a
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.

Nov 16 '05 #12

P: n/a
"Yarco" <ya*****@gmail.com> writes:
I've posted it in comp.unix.programmer. But nobody answer it.


You posted less than 4 hours ago. Be patient. It's still off-topic here.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 16 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.