home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / tcl / 1917 < prev    next >
Encoding:
Text File  |  1992-11-21  |  2.0 KB  |  55 lines

  1. Newsgroups: comp.lang.tcl
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!henry!mathew
  3. From: mathew@elroy.Jpl.Nasa.Gov (Mathew Yeates)
  4. Subject: polling, nonblocking reads in tcl
  5. Message-ID: <mathew.722381246@henry>
  6. Sender: news@elroy.jpl.nasa.gov (Usenet)
  7. Nntp-Posting-Host: henry.jpl.nasa.gov
  8. Organization: Image Analysis Systems Group, JPL
  9. Date: Sat, 21 Nov 1992 21:27:26 GMT
  10. Lines: 43
  11.  
  12. Im having trouble with the following. I set a up telnet connection
  13. and want to read by polling the pipe and responding to input. Here
  14. is a code fragment (I'm using extended tcl)
  15. -----------------------------------------------------------------------
  16. set valkcon [open "|/usr/ucb/telnet valkyries.andrew.cmu.edu 5000" w+]
  17. fcntl $valkcon NDELAY 1
  18.  
  19. set motd ""
  20. while {1} {
  21. set ready [lindex [select $valkcon {} {} 0] 0]
  22.     if {[llength $ready] != 0} {
  23.                 set onechar [read $ready 1]
  24.                 append motd  $onechar
  25.                 .t insert end $onechar
  26.                 update
  27.  
  28.                 if {[string match {*Enter Login :*} $motd] != 0} {
  29.                 set motd ""
  30.                 break
  31.                 } else {}
  32.         }
  33. }
  34. ---------------------------------------------------------------------
  35.  
  36. Problems:
  37. 1) If I try and read much more than 1 byte, the program bombs with an
  38. "Operation would block". Ive tried catching this by replacing the
  39. read line with catch {set onechar [read $ready 100]} but in this case
  40. when an exception occurs, onechar is not set so the next line gives an
  41. error. Ive also tried not setting fcntl but, in this case, the program
  42. seems to hang for long periods of time. This may be related to problem 2.
  43.  
  44. 2) It seems that the input is being buffered. Is this a consequence of
  45. the Tcl command "read" being built on top of fread instead of read?
  46. Often times, the program will hang at the select call as if there is
  47. no impending input (even though I know it is there). If I force some
  48. characters through the telnet connection, then the missing characters
  49. show but the ones I just sent do not. In other words, there is a delay.
  50.  
  51. Any clues?
  52.  
  53. Thanks in advance,
  54. Mathew 
  55.