1fblocked(n)                  Tcl Built-In Commands                 fblocked(n)
2
3
4

NAME

6       fblocked  -  Test whether the last input operation exhausted all avail‐
7       able input
8

SYNOPSIS

10       fblocked channelId
11
12

DESCRIPTION

14       The fblocked command returns 1 if the most recent  input  operation  on
15       channelId  returned  less information than requested because all avail‐
16       able input was exhausted.  For example, if gets is invoked  when  there
17       are  only  three  characters  available  for  input  and no end-of-line
18       sequence, gets returns  an  empty  string  and  a  subsequent  call  to
19       fblocked will return 1.
20
21       ChannelId must be an identifier for an open channel such as a Tcl stan‐
22       dard channel (stdin, stdout, or stderr), the return value from an invo‐
23       cation  of  open or socket, or the result of a channel creation command
24       provided by a Tcl extension.
25

EXAMPLE

27       The fblocked  command  is  particularly  useful  when  writing  network
28       servers,  as  it  allows you to write your code in a line-by-line style
29       without preventing the servicing of other  connections.   This  can  be
30       seen in this simple echo-service:
31
32       # This is called whenever a new client connects to the server proc con‐
33       nect {chan host port} {
34           set clientName [format <%s:%d> $host $port]
35           puts "connection from $clientName"
36           fconfigure $chan -blocking 0 -buffering line
37           fileevent $chan readable [list echoLine $chan $clientName] }
38
39       # This is called whenever either at least one byte of input #  data  is
40       available,  or  the  channel  was  closed by the client.  proc echoLine
41       {chan clientName} {
42           gets $chan line
43           if {[eof $chan]} {
44               puts "finishing connection from $clientName"
45               close $chan
46           } elseif {![fblocked $chan]} {
47               # Didn't block waiting for end-of-line
48               puts "$clientName - $line"
49               puts $chan $line
50           } }
51
52       # Create the server socket and enter  the  event-loop  to  wait  #  for
53       incoming connections...  socket -server connect 12345 vwait forever
54

SEE ALSO

56       gets(n), open(n), read(n), socket(n), Tcl_StandardChannels(3)
57

KEYWORDS

59       blocking, nonblocking
60
61
62
63Tcl                                   7.5                          fblocked(n)
Impressum