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

NAME

8       fblocked  -  Test whether the last input operation exhausted all avail‐
9       able input
10

SYNOPSIS

12       fblocked channelId
13_________________________________________________________________
14
15

DESCRIPTION

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

EXAMPLE

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

SEE ALSO

64       gets(n), open(n), read(n), socket(n), Tcl_StandardChannels(3)
65
66

KEYWORDS

68       blocking, nonblocking
69
70
71
72Tcl                                   7.5                          fblocked(n)
Impressum