comp.lang.ada
 help / color / mirror / Atom feed
* Re: Unix SELECT Ada binding
  1999-07-21  0:00 Unix SELECT Ada binding Andy Askey
@ 1999-07-21  0:00 ` David C. Hoos, Sr.
  1999-07-22  0:00 ` Gisle S�lensminde
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David C. Hoos, Sr. @ 1999-07-21  0:00 UTC (permalink / raw)



Andy Askey <askeya@res.raytheon.com> wrote in message
news:379638B1.101427E5@res.raytheon.com...
> 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.
>
> 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.

Walk over to the EADTB side of your building.  I did it for VADS in
the EADTB networking code, some five years ago.






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Unix SELECT Ada binding
@ 1999-07-21  0:00 Andy Askey
  1999-07-21  0:00 ` David C. Hoos, Sr.
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Andy Askey @ 1999-07-21  0:00 UTC (permalink / raw)


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.

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          |
---------------------------------------------------




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Unix SELECT Ada binding
  1999-07-21  0:00 Unix SELECT Ada binding Andy Askey
  1999-07-21  0:00 ` David C. Hoos, Sr.
@ 1999-07-22  0:00 ` Gisle S�lensminde
  1999-07-22  0:00 ` Andi Kleen
  1999-07-22  0:00 ` Samuel T. Harris
  3 siblings, 0 replies; 5+ messages in thread
From: Gisle S�lensminde @ 1999-07-22  0:00 UTC (permalink / raw)


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 )   





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Unix SELECT Ada binding
  1999-07-21  0:00 Unix SELECT Ada binding Andy Askey
                   ` (2 preceding siblings ...)
  1999-07-22  0:00 ` Andi Kleen
@ 1999-07-22  0:00 ` Samuel T. Harris
  3 siblings, 0 replies; 5+ messages in thread
From: Samuel T. Harris @ 1999-07-22  0:00 UTC (permalink / raw)


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.
> 
> 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
> --

Doing this ages ago in another life, I found the easiest
thing to do was write a C helper routine which used the
macro instead of trying to duplicate the macro in Ada.
Interface to the C helpers and viola. Takes about 5 mins work.

While Ada purists may cringe at this, I find that one
of my favorite features of Ada are the interface capabilities
which allows me to glue stuff together when that is
appropriate. I don't like C, but I recognize the need
to use it when it gets the job done.

-- 
Samuel T. Harris, Principal Engineer
Raytheon, Scientific and Technical Systems
"If you can make it, We can fake it!"




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Unix SELECT Ada binding
  1999-07-21  0:00 Unix SELECT Ada binding Andy Askey
  1999-07-21  0:00 ` David C. Hoos, Sr.
  1999-07-22  0:00 ` Gisle S�lensminde
@ 1999-07-22  0:00 ` Andi Kleen
  1999-07-22  0:00 ` Samuel T. Harris
  3 siblings, 0 replies; 5+ messages in thread
From: Andi Kleen @ 1999-07-22  0:00 UTC (permalink / raw)


Andy Askey <askeya@res.raytheon.com> writes:

> 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.

[...]

Near all modern Unixes have poll(2), which is probably much easier to
bind to than select [and if you have to handle older OS versions you
can always link in one of the poll-on-select C wrappers). poll does also
scale bigger for huge number of file descriptors and doesn't add arbitary
fd limits to your program.
If you really want to use select I would recommend using a small C interface
layer which uses the FD_* macros. 

-Andi

-- 
This is like TV. I don't like TV.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1999-07-22  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-21  0:00 Unix SELECT Ada binding Andy Askey
1999-07-21  0:00 ` David C. Hoos, Sr.
1999-07-22  0:00 ` Gisle S�lensminde
1999-07-22  0:00 ` Andi Kleen
1999-07-22  0:00 ` Samuel T. Harris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox