CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2009
    Posts
    10

    [RESOLVED] Accept errors

    I am trying to write a Linux Daemon that will accept TCP/IP connections on a specific port. During development I did not have the code in that creates a child process and then exits the parent and everything worked fine. I was able to run a test for 24 hours without a problem.

    However, after putting the code at the beginning that initiates a child process, then exits the Parent the Accept function started to fail. Below is my accept function.

    if((new_sock = accept(sock, (struct sockaddr*) &client_name, &size)) < 0){
    syslog(LOG_MAKEPRI(LOG_LOCAL1, LOG_ERR), "Error accepting connection");
    }

    When I run it and the connecting device attempts to connect, the Syslog starts to fill up with the above message if it is running as a child process.

    If this is not the proper forum for this question, please forgive me and point me to the correct forum.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Accept errors

    Quote Originally Posted by Bear35805 View Post
    When I run it and the connecting device attempts to connect, the Syslog starts to fill up with the above message if it is running as a child process.
    OK, so what's your question?

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Oct 2009
    Posts
    10

    Re: Accept errors

    The question is why does the accept return a value less than zero when it is running as a Daemon? In other words this code is in the child process that continues running when the main process has exited. If I remove the code that starts the Child Process and exits the parent, the accept works just fine. How can I make it work properly under the Child Process?

    I have attached the CPP file that contains the code.
    Attached Files Attached Files

  4. #4
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: Accept errors

    You should read the documentation of accept()
    It it fails, it will set the errno variable to show why it failed.
    http://www.linuxhowtos.org/manpages/2/accept.htm

  5. #5
    Join Date
    Oct 2009
    Posts
    10

    Re: [RESOLVED] Accept errors

    Thanks JnMacd that got me going in the right direction to fix the problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured