EAGAIN undeclared...

This is a discussion on EAGAIN undeclared... within the C Programming forums, part of the General Programming Boards category; Hi there, I guessing that I probably dont have some library so gcc gives this error: erro: 'EAGAIN' undeclared (first ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    17

    EAGAIN undeclared...

    Hi there, I guessing that I probably dont have some library so gcc gives this error:
    erro: 'EAGAIN' undeclared (first use in this function)

    Can you tell what am I doing wrong?

    Thanks in advance

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Code:
    #include <errno.h>

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    17
    hi again, i am doing a non-blocking server...So I put the
    Code:
    accept
    inside a
    Code:
    for
    and each time
    Code:
    accept>0
    it creates a new thread, passing in it the socket descriptor of accepted client.

    I set
    Code:
    socket(PF_INET, SOCK_STREAM || SOCK_NONBLOCK, IPPROTO_TCP)
    .

    Can you give me some hints to put the accept in a non-bloking mode? Probably I have to test the accept with the flag EWOULDBLOCK., but I am having some dificulties on setting this up.

    Thanks in advance

    PS: this is because I want to do more things inside that for...

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Well is the first problem solved or not?

    I would read this link (especially the bottom), and relevant man pages:
    - Blocking vs. non-blocking sockets
    - socket(7): socket interface - Linux man page
    - fcntl(2): change file descriptor - Linux man page

    One thing in particular is that all of these links mention "O_NONBLOCK", and never "SOCK_NONBLOCK".

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    17
    Quote Originally Posted by nadroj View Post
    Well is the first problem solved or not?

    I would read this link (especially the bottom), and relevant man pages:
    - Blocking vs. non-blocking sockets
    - socket(7): socket interface - Linux man page
    - fcntl(2): change file descriptor - Linux man page

    One thing in particular is that all of these links mention "O_NONBLOCK", and never "SOCK_NONBLOCK".
    Thank you. I will read it carefully. SOCK_NONSOCK is a flag mentioned in socket(2) man page

  6. #6
    Registered User
    Join Date
    Oct 2009
    Posts
    17
    I guess i am having some troubles with error messages. In accept(2) man pages it says that SOCK_NONBLOCK flag will save extra calls to fcntl. So far so good... I set that up and now I simple dont know how to test if accept will block or not.

    Any hints??

  7. #7
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Cant you just do an "accept" and do a printf statement to see if it continues immediately after the "accept" statement and prints the message, before a client connects? Make sure to print to "stderr", so use "fprintf" to do so (because stderr is unbuffered, so all messages get printed immediately).

    I havent done anything with sockets in a while now, so maybe Im just not understanding what the problem is.

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by tmcp View Post
    I guess i am having some troubles with error messages. In accept(2) man pages it says that SOCK_NONBLOCK flag will save extra calls to fcntl.
    Not in mine it doesn't! Please quote this. Also, there is no flags parameter to accept().

    Anyway, if the socket is set NON_BLOCK, accept() will not block -- you do not have to test that.

    If you want to test if the socket was successfully set non-block, just do this:
    Code:
    accept(....); 
    puts("HEY");
    Now run the program, but don't try to connect to it. If HEY appears right away, you are in non-blocking mode. Otherwise, execution will wait for accept to accept something.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User
    Join Date
    Oct 2009
    Posts
    17
    Thanks, I will probably have to use O_NONBLOCK and set it with fcntl....

    Quote Originally Posted by MK27 View Post
    Not in mine it doesn't! Please quote this. Also, there is no flags parameter to accept().
    Flags are for
    Code:
    accept4()
    . A non.standard Linux system call. Linux 2.6.28. Glibc 2.10
    Last edited by tmcp; 11-23-2009 at 11:06 PM.

  10. #10
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by tmcp View Post
    Thanks, I will probably have to use O_NONBLOCK and set it with fcntl....Flags are for
    Code:
    accept4()
    . A non.standard Linux system call. Linux 2.6.28. Glibc 2.10
    Okay. This is very very non-standard tho, since I am running glibc 2.9 (fedora 10-64) and accept4 does not exist here, so it probably will not be available on 95%+ of linux systems. Whereas accept() and fcntl() are available anywhere you have C.

    Use of fcntl() for this is pretty straightforward:

    Code:
    fcntl(sock,F_SETFL,O_NONBLOCK);
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  11. #11
    Registered User
    Join Date
    Oct 2009
    Posts
    17
    Quote Originally Posted by nadroj View Post
    Cant you just do an "accept" and do a printf statement to see if it continues immediately after the "accept" statement and prints the message, before a client connects? Make sure to print to "stderr", so use "fprintf" to do so (because stderr is unbuffered, so all messages get printed immediately).

    I havent done anything with sockets in a while now, so maybe Im just not understanding what the problem is.
    Thanks for the answer. Dont know that about fprintf ! Yep, its that I am trying to do. So I guess I am doing it wrong because accept will block my other threads that are running simultaneous. As I say I maybe have to use fcntl...

    Thank you again.

  12. #12
    Registered User
    Join Date
    Oct 2009
    Posts
    17
    Quote Originally Posted by MK27 View Post
    Okay. This is very very non-standard tho, since I am running glibc 2.9 (fedora 10-64) and accept4 does not exist here, so it probably will not be available on 95%+ of linux systems.[/code]
    Thanks you for the hints. Thats what I am going to do...I will post my results later

  13. #13
    Registered User
    Join Date
    Oct 2009
    Posts
    17
    Problem solved...Its runnig all ok. Thanks for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 10:15 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 10:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21