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