Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / share / tcl / help / tcl / files / fblocked
1 NAME
2 fblocked - Test whether the last input operation exhausted all avail-
3 able input
4
5 SYNOPSIS
6 fblocked channelId
7
8
9 DESCRIPTION
10 The fblocked command returns 1 if the most recent input operation on
11 channelId returned less information than requested because all avail-
12 able input was exhausted. For example, if gets is invoked when there
13 are only three characters available for input and no end-of-line
14 sequence, gets returns an empty string and a subsequent call to
15 fblocked will return 1.
16
17 ChannelId must be an identifier for an open channel such as a Tcl stan-
18 dard channel (stdin, stdout, or stderr), the return value from an invo-
19 cation of open or socket, or the result of a channel creation command
20 provided by a Tcl extension.
21
22 EXAMPLE
23 The fblocked command is particularly useful when writing network
24 servers, as it allows you to write your code in a line-by-line style
25 without preventing the servicing of other connections. This can be
26 seen in this simple echo-service:
27
28 # This is called whenever a new client connects to the server
29 proc connect {chan host port} {
30 set clientName [format <%s:%d> $host $port]
31 puts "connection from $clientName"
32 fconfigure $chan -blocking 0 -buffering line
33 fileevent $chan readable [list echoLine $chan $clientName]
34 }
35
36 # This is called whenever either at least one byte of input
37 # data is available, or the channel was closed by the client.
38 proc echoLine {chan clientName} {
39 gets $chan line
40 if {[eof $chan]} {
41 puts "finishing connection from $clientName"
42 close $chan
43 } elseif {![fblocked $chan]} {
44 # Didn't block waiting for end-of-line
45 puts "$clientName - $line"
46 puts $chan $line
47 }
48 }
49
50 # Create the server socket and enter the event-loop to wait
51 # for incoming connections...
52 socket -server connect 12345
53 vwait forever
54
55
56 SEE ALSO
57 gets(n), open(n), read(n), socket(n), Tcl_StandardChannels(3)
58
59
60 KEYWORDS