Re: Select?
Björn Lundin <[email protected]> Sun, 30 Mar 2003 17:47:37 +0200
| Newsgroups | gmane.comp.lang.ada.sockets |
|---|---|
| Message-ID | <[email protected]> |
<posted & mailed> Samuel Tardieu wrote: >>>>>> "Björn" == Björn Lundin <[email protected]> writes: > > Björn> Are there any thoughts of implementing 'select' an Ada > Björn> sockets? It would be a nice feature. > > It may be, but I don't want to implement everything that would be nice > if there is no real need. What problem would it solve? > > Sam Let's say we have a server process, performing some action on a text-based protocol from a client. It could be implemented like this: loop declare Reply : string (1..10); Do_Exit : Boolean := False; Answer : string := Get_Line(A_Socket); begin Handle_Answer_And_Do_Some_Action(Answer,Do_Exit,Reply); Send_Back_Reply(A_Socket,Reply); end; exit when Do_Exit; end loop; Assume further that this is part of a fairly big system, and for some reason, the system needs to be taken down. How will I wake up from Get_Line? In this case, no data has arrived on the socket. If the server accepted connections all the time, I could connect and send in a STOP message, but once connected, always connected, ie only ONE client on this server. With select, i could periodically check if a STOP has arrived by some other means, (presence of a file, shared memory... ) every 3 seconds or so. I have not tried yet, but another possible ways could be closing the socket from another task, so get_line gets a 'Connection_closed' exception, and stop from there? A third way would be non-blocking sockets, but I don't like the idea of it. It either loops and consumes CPU or it needs a delay, and sinks response time The key is how to wake up from Get_Line (when nothing has arrived), without consuming to much CPU, and still have OK answering time. I'm thankful for pointers solving this, with or without 'select' /Björn _______________________________________________ AdaSockets mailing list [email protected] http://www.rfc1149.net/mailman/listinfo/adasockets