Thread: fd_set iteration

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    8

    fd_set iteration

    Hi -- got a quickie (I hope) for you guys:

    I saw an example of doing this (on Unix, select.h) but I dont remember much except the result..

    Basically, this is what I'm interested in doing (pseudo-code wise):

    fd_set myset
    FD_ZERO(&myset)
    for (i=0; i<32; i++)
    printf myset[i]\n , or myset.fds_bits[i].. or whatever


    FD_ISSET() checks the status of each bit, but I want to actually access/print their values. The desired output:

    0
    0
    0
    0
    0
    .... (32 times)

    So, who knows how I can gut the internal organs of an fd_set?

    Thanks

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    you could loop, using the FD_ISSET macro.

    I believe the descriptor set is defined as an array of unsigned ints, however I don't believe you should make that assumption and use it that way. the loop with FD_ISSET is much safer.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    8
    Hmm.. FD_ISSET would return 1 if set, 0 if not set.. I'm not sure that's what I was thinking of. I believe I saw the output of some bits expressed in base2->base10 -- but 1 set bit (00000001) in an fd_set is still "1" in decimal right, sooo.. maybe I'm not remembering accurately. Thanks anyway.. I'll have to stew on this a bit longer.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'm not sure why you need to stew about anything.
    Code:
    for( x = 0; x < highestdescriptor; x++ )
    {
        printf( "%d", FD_ISSET( descriptors, x ) );
    }
    printf( "\n" );
    So what exactly are you having problems with?


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Iteration?
    By Aliaks in forum C++ Programming
    Replies: 2
    Last Post: 06-06-2009, 11:17 PM
  2. MPI - linear pipeline solution for jacobi iteration
    By eclipt in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2006, 05:25 AM
  3. recursivity & iteration
    By Marlon in forum C++ Programming
    Replies: 2
    Last Post: 06-14-2005, 01:58 PM
  4. The "continue" statement in JAVA
    By Hexxx in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-26-2004, 06:19 PM
  5. Iteration help please
    By incognito in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2001, 07:37 AM