From: knobo
Subject: Server-client model
Date: 
Message-ID: <1144967231.333221.234020@j33g2000cwa.googlegroups.com>
Hi,

I'm writing an application that works with a server over a unix socket.
I need a event loop  (thread/process) to continuously poll the socket
to check if there is any messages for me . Then occasional I have to
write a message to the server.  I used the cp-port package in debian
with the open-unix-socet to connect.

Question:
How can I poll for messages? If I do a read-line, would not I then
block for writing? Is there some nice way to do a select() system call.
I need to be able to write and listen for feedback at the same time
(well, as much same time as possible).

From: Alan Manuel K. Gloria
Subject: Re: Server-client model
Date: 
Message-ID: <1145002243.990179.239590@z34g2000cwc.googlegroups.com>
I think CL has a function 'listen that may work:
http://www.lisp.org/HyperSpec/Body/fun_listen.html

I don't have proof if this will work though (me noob!)
From: knobo
Subject: Re: Server-client model
Date: 
Message-ID: <1145024070.181608.112520@t31g2000cwb.googlegroups.com>
well, it would work if it would Waite until input is ready, then
continue. If not I would need a tight loop, which would take to much
resources.
From: Alan Manuel K. Gloria
Subject: Re: Server-client model
Date: 
Message-ID: <1145074071.455180.27240@u72g2000cwu.googlegroups.com>
Huh?  I thought you didn't want to wait for input, that you wanted to
poll if input is available?  All polling systems use a loop - I have
yet to see a polling system that doesn't have a loop.  I think CL has
nice enough loops (and modern computing systems are fast enough
anyway).

Unfortunately, the CL standard doesn't have threads, and whatever
threads exist are implementation-dependent.  But AFAIK the overhead of
switching threads would be similar to the loop overhead in a polling
system - the threads simply allow you to abstract away the polling
(which would be better IMO).  If CL had continuations, in fact you
could write "thread-like" code that is equivalent to a polling loop
(without an explicit polling loop) and without requiring real threads.

How is your program structured, anyway?  If your CL implementation has
a good threads implementation, and you're using threads, I would expect
that if a thread does a blocking operation (e.g. 'read-line) the CL
implementation would not waste time on it.  Is it really wasting that
much resources?

(all of the above, of course, coming from a complete noob!)
From: knobo
Subject: Re: Server-client model
Date: 
Message-ID: <1145083575.459929.179760@j33g2000cwa.googlegroups.com>
system:wait-until-fd-usable fixed my problem.
From: Alan Manuel K. Gloria
Subject: Re: Server-client model
Date: 
Message-ID: <1145096062.499096.66780@t31g2000cwb.googlegroups.com>
Which Lisp are you using?
From: knobo
Subject: Re: Server-client model
Date: 
Message-ID: <1145097144.069843.51490@i39g2000cwa.googlegroups.com>
cmucl