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