Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Server-client model

0 views
Skip to first unread message

knobo

unread,
Apr 13, 2006, 6:27:11 PM4/13/06
to
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).

Alan Manuel K. Gloria

unread,
Apr 14, 2006, 4:10:44 AM4/14/06
to
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!)

knobo

unread,
Apr 14, 2006, 10:14:30 AM4/14/06
to
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.

Alan Manuel K. Gloria

unread,
Apr 15, 2006, 12:07:51 AM4/15/06
to
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!)

knobo

unread,
Apr 15, 2006, 2:46:15 AM4/15/06
to

system:wait-until-fd-usable fixed my problem.

Alan Manuel K. Gloria

unread,
Apr 15, 2006, 6:14:22 AM4/15/06
to
Which Lisp are you using?

knobo

unread,
Apr 15, 2006, 6:32:24 AM4/15/06
to
cmucl

Alan Manuel K. Gloria

unread,
Apr 15, 2006, 10:18:20 PM4/15/06
to
I see. system:wait-until-fd-usable does not seem to be part of the CL
standard, so it's probably a cmucl extension I know nothing about,
since I'm using clisp. If portability isn't an issue, your process
will probably be the best for your system.

0 new messages