I have an old Classic Open Transport program that I'm trying to modernize
with sockets. This program runs a server that accepts an undetermined
number of connections from clients and then uses those clients as a
distributed computing platform. The way the program handled an unknown
number of clients was by using threads. In addition to the main
application thread, there was a single "server connection" thread that
waited for OT connection attempts. Each time one occurred, a new thread
would be created to handle that individual client's communications. This
is all modeled on Apple's SimpleServer demo, which I'm not sure is even on
the website anymore. I guess the OT calls were nonblocking, or at least
some of the calls were nonblocking. In particular, I think OTListen was
might have been nonblocking (I can't tell now because the program is too
old to debug, CW won't run it in a debugger, only standalone).
Anyway, I'm rewriting the program to use sockets with Mach-O. Everything
compiles and builds and runs fine. The equivalent of OTListen is accept.
The problem is, once the main connection server threads calls accept, the
program locks up waiting for a connection. It doesn't matter if I call
YieldToAnyThread right before calling accept, because eventually the
thread manager comes back and resumes this thread (which of course is
necessary to catch the next connection attempt), and then immediately
locks up in the accept call, and no other threads can execute either.
I kind of thought one good point of threads was to allow blocking calls to
go off by themselves and block all they want, but leave other threads
nonblocked and otherwise executing. Otherwise, what was the point of
using individual threads to handle the individual clients in the first
place? (or was there never a point and I shouldn't have done that
anyway?)
Am I missing something here, or is this going to be much much hard with
sockets than with OT? Basically, I need preemtive multitasking or
something like that. Can I tell accept to give up and return after some
set period of time, say 1/100th of a second or so?
________________________________________________________________________
Keith Wiley kwiley DeleteThis @cs.unm.edu
http://www.unm.edu/~keithw
"Yet mark his perfect self-contentment, and hence learn his lesson,
that to be self-contented is to be vile and ignorant, and that to
aspire is better than to be blindly and impotently happy."
-- Edwin A. Abbott, Flatland
________________________________________________________________________