UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2006-02-10 02:33 PM

peco
Member
Registered: 2006-02-10
Posts: 2

Re: AIX 5.3 and select()

I have the following code that works under AIX 4.3 but fails in 5.3. It simply is looking at an established socket and a message queue for readding...

SELLIST(1,1) select_list;                  /* list of ids to watch in */
                                           /* select                  */

/*
 * Macros to handle bit manipulation of the socket descriptor mask
 */
#define NUMSMBIT        (sizeof(int) * 8)
#define SDSET(n, p)    ((p)->fdsmask[(n)/NUMSMBIT] |= (1 << ((n) % NUMSMBIT)))
#define SDCLR(n, p)    ((p)->fdsmask[(n)/NUMSMBIT] &= ~(1 << ((n) % NUMSMBIT)))
#define SDISSET(n, p)  ((p)->fdsmask[(n)/NUMSMBIT] & (1 << ((n) % NUMSMBIT)))
#define SDZERO(p)      bzero((char *)(p), sizeof(*(p)))
#define BITQUEUEMASK(n) ((n) << 16 )

  int    max_num_queues = 1;


   /*
    * Set the max descriptor size to check for.
    */
    max_descriptor = ( BITQUEUEMASK(max_num_queues) + ( SocketDesc + 1));

   /*
    * Set the Socket Descriptor in the select list.
    */
    SDZERO( &select_list );
    SDSET( SocketDesc, &select_list );

   /*
    * Set the Socket Queue in the select list.
    */
    select_list.msgids[ 0 ] = BackendQueue;

   /*
    * Wait for a message on the socket or the socket queue.
    */
    select_id = select( max_descriptor, (fd_set*)&select_list, NULL, NULL, (struct timeval *)&timeout );

    if( select_id > 0 )
    {

     /*
      * Socket received a message.
      */
      if( SDISSET( SocketDesc, &select_list ) )
      {
        ProcessSocketMsg();
      }

     /*
      * Message Queue received a message.
      */
      else
      {
        ProcessQueueMsg();
      }
    }

All the code is not shown like setting up the socket and the timeout structure but all that works and has worked under AIX 4.3.  Running under AIX 5.3 the select returns EBADF. I know the FD_SETSIZE has changed in this version of AIX but don't see how that effects the code. 
Thanks for any suggestions...

Offline

#2 2006-02-10 08:24 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,760
Website

Re: AIX 5.3 and select()

Wow, that's really weird code...  I've never seen this SELLIST() stuff before, but
doing a little searching, it appears to be a legit AIX thing...  Wild...

But, it looks to me like the value you want for the first arg to SELLIST() might need
to be larger than the "1" you use...  It needs to be large enough to contain the FD
you are setting in there, and if that FD# happens to exceed 7, there won't be room
in a single int to hold it...  So, could that maybe be the case?  Is your "SocketDesc"
larger than 7?

Other than that, I don't know what it might be...  I've never dealt with that weirdo
manner of select() before; only with plain old fd_sets...

Offline

#3 2006-02-10 08:36 PM

peco
Member
Registered: 2006-02-10
Posts: 2

Re: AIX 5.3 and select()

Rob, thanks for the reply. I have tried increasing the SELLIST sizes but that didn't work.  Do you have any sample code of a select() waiting on a socket and message queue without using the SELLIST?

Offline

#4 2006-02-10 11:01 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,760
Website

Re: AIX 5.3 and select()

No, not a message queue...  I never knew such an incarnation of select() existed...
(But, then, I don't think I've ever used AIX, either...)  Most select()'s tend to only
work on file descriptors of some sort (whether they be sockets, real files, pipes, or
whatever) via plain old fd_sets...  (Though, I know that the QNX4 select() is capable
of working with QNX SRR messages via some klugery...)

Offline

Board footer

Powered by FluxBB