why error: "accept: Invalid argument"

Discussion in 'C Programming' started by Yarco, Nov 16, 2005.

  1. Yarco

    Yarco Guest

    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.
    Yarco, Nov 16, 2005
    #1
    1. Advertising

  2. Yarco

    Michael Mair Guest

    Yarco wrote:
    > 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
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Nov 16, 2005
    #2
    1. Advertising

  3. Yarco

    Yarco Guest

    Thanks
    Yarco, Nov 16, 2005
    #3
  4. Yarco

    Gary Baydo Guest

    On Wed, 16 Nov 2005 06:02:15 +0100, Michael Mair wrote:

    > Yarco wrote:
    >> 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
    Gary Baydo, Nov 16, 2005
    #4
  5. Yarco

    pete Guest

    Gary Baydo wrote:

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


    perror() is in the standard library.

    --
    pete
    pete, Nov 16, 2005
    #5
  6. Yarco

    Michael Mair Guest

    Gary Baydo wrote:
    > On Wed, 16 Nov 2005 06:02:15 +0100, Michael Mair wrote:
    >
    >
    >>Yarco wrote:
    >>
    >>>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
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Nov 16, 2005
    #6
  7. Yarco

    A.A Guest

    >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, Nov 16, 2005
    #7
  8. Yarco

    A.A Guest

    >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, Nov 16, 2005
    #8
  9. Yarco

    A.A Guest

    >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, Nov 16, 2005
    #9
  10. Yarco

    A.A Guest

    >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, Nov 16, 2005
    #10
  11. "Yarco" <> writes:
    > 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.

    --
    Keith Thompson (The_Other_Keith) <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.
    Keith Thompson, Nov 16, 2005
    #11
  12. Yarco

    Yarco Guest

    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.
    Yarco, Nov 16, 2005
    #12
  13. "Yarco" <> 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) <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.
    Keith Thompson, Nov 16, 2005
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Why, why, why???

    =?Utf-8?B?VGltOjouLg==?=, Jan 27, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    551
    Juan T. Llibre
    Jan 27, 2005
  2. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    450
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  3. Mr. SweatyFinger

    VWD why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    371
    =?Utf-8?B?Q2lhcmFuIE8nJycnRG9ubmVsbA==?=
    Dec 21, 2006
  4. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    862
    Mark Rae
    Dec 21, 2006
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,762
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page