From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,e6293bc5c0d52b2b X-Google-Attributes: gid103376,public From: gisle@apal.ii.uib.no (Gisle S�lensminde) Subject: Re: Unix SELECT Ada binding Date: 1999/07/22 Message-ID: #1/1 X-Deja-AN: 503948426 Content-Transfer-Encoding: 8bit References: <379638B1.101427E5@res.raytheon.com> Organization: University of Bergen, Norway Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-07-22T00:00:00+00:00 List-Id: In article <379638B1.101427E5@res.raytheon.com>, Andy Askey wrote: >Has anyone created an Ada package with binding into the SELECT C library >function that does I/O multiplexing? The binding is straight forward >but there are several macros (FD_SET, FD_CLR, ...) that have to be >translated into Ada. > The unix/C portability seems to be based on the existance of these macros, and they will be expanded to different things on different platforms. Interfacing to them can be difficult. On solaris (cc -E) FD_SET(a,b) becomes: ( ( b ) -> fds_bits [ ( a ) / ( sizeof ( fds_mask ) * 8 ) ] |= ( ( unsigned ) 1 << ( ( a ) % ( sizeof ( fds_mask ) * 8 ) ) ) ); On Linux (gcc -E) FD_SET(a,b) becomes: __asm__ __volatile__ ("btsl %1,%0" : "=m" (( ( b ) )-> fds_bits[(( ( a ) ) / (8 * sizeof (__fd_mask)) ) ]) : "r" (((int) ( ( a ) )) % (8 * sizeof (__fd_mask)) ) : "cc","memory") ; And you even got yet another expansion. I just wrote a tiny server, and for that one, I used one task for each file descriptor I wanted to listen to. This may use more CPU and memory, but it is more portable. (It works on both Linux, Solaris and windows NT in my case) >For example, the select.h file has the following macro for FD_SET: > >#define FD_SET(__n, __p) ((__p)->fds_bits[(__n)/FD_NFDBITS] |= \ > ((unsigned)1 << ((__n) % >FD_NFDBITS))) > > >If anyone has an example of this they care to share, we will greatly >appreciated it. > >Thanx. >Andy >-- >--------------------------------------------------- >| Andy Askey | >| Software Engineer | >| Raytheon Systems Company | >| 670 Discovery Drive, Huntsville, AL 35806 | >| Phone: (256) 971-2367 Fax: (256) 971-2306 | >| andrew_j_askey@res.raytheon.com | >--------------------------------------------------- -- -- Gisle S�lensminde ( gisle@ii.uib.no )