Posted to tcl by aspect at Sun Mar 08 03:09:30 GMT 2015view pretty
Sketch of implementation for async resolver using threads: * program communicates with a resolver thread via a socketpair * resolver thread created with first request * resolver thread manages a pool of worker threads * communicates with workers over socketpairs * basically a select() loop * if all workers are busy, resolver thread queues the request * workers use getnameinfo()/getaddrinfo() to resolve a hostname to IP address string * comms are line-oriented * program sends a request "ID HOSTNAME\n" * resolver dispatches the request to a worker and sends back the result through master sock * result comes in the form "ID IPADDRSTRING\n" Details of thread pool management are in progress. Startup costs shouldn't be important for resolution, so a clean implementation triumphs. Currently working on pthread implementation, which ought to be easy to switch to Tcl_Thread and wrap in a convenient TclObjCommand. Getting it into the notifier should also be easy (?) No promises this will be done in a reasonable timeframe; it's mostly a learning exercise for now. Not thinking hard about the Tcl command interface yet, but expect something like: resolver init resolver resolve $hostname -command [info coroutine] resolver configure -workers Hopefully won't need deep re-engineering to attach to Notifier (single socket). How Tcl_SocketObjCommand will make use of this, I don't know. Requirements: * POSIX threads or Tcl_Thread * POSIX socketpair * getnameinfo/getaddrinfo Not currently considering: * control over getnameinfo params: fixed at AF_UNSPEC + IPPROTO_TCP * I18n Domain Names support