Posted to tcl by aspect at Sun Mar 08 03:09:30 GMT 2015view raw

  1. Sketch of implementation for async resolver using threads:
  2.  
  3. * program communicates with a resolver thread via a socketpair
  4. * resolver thread created with first request
  5. * resolver thread manages a pool of worker threads
  6. * communicates with workers over socketpairs
  7. * basically a select() loop
  8. * if all workers are busy, resolver thread queues the request
  9. * workers use getnameinfo()/getaddrinfo() to resolve a hostname to IP address string
  10. * comms are line-oriented
  11. * program sends a request "ID HOSTNAME\n"
  12. * resolver dispatches the request to a worker and sends back the result through master sock
  13. * result comes in the form "ID IPADDRSTRING\n"
  14.  
  15. Details of thread pool management are in progress. Startup costs shouldn't be important for resolution, so a clean implementation triumphs.
  16.  
  17. Currently working on pthread implementation, which ought to be easy to switch to Tcl_Thread
  18. and wrap in a convenient TclObjCommand.
  19.  
  20. Getting it into the notifier should also be easy (?)
  21.  
  22. No promises this will be done in a reasonable timeframe; it's mostly a learning exercise for now.
  23.  
  24. Not thinking hard about the Tcl command interface yet, but expect something like:
  25.  
  26. resolver init
  27. resolver resolve $hostname -command [info coroutine]
  28. resolver configure -workers
  29.  
  30. Hopefully won't need deep re-engineering to attach to Notifier (single socket).
  31.  
  32. How Tcl_SocketObjCommand will make use of this, I don't know.
  33.  
  34. Requirements:
  35.  
  36. * POSIX threads or Tcl_Thread
  37. * POSIX socketpair
  38. * getnameinfo/getaddrinfo
  39.  
  40. Not currently considering:
  41.  
  42. * control over getnameinfo params: fixed at AF_UNSPEC + IPPROTO_TCP
  43. * I18n Domain Names support
  44.  
  45.