Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/fblocked.n @ 52

Last change on this file since 52 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 2.4 KB
Line 
1'\"
2'\" Copyright (c) 1996 Sun Microsystems, Inc.
3'\"
4'\" See the file "license.terms" for information on usage and redistribution
5'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6'\"
7'\" RCS: @(#) $Id: fblocked.n,v 1.8 2005/05/10 18:33:59 kennykb Exp $
8.so man.macros
9.TH fblocked n 7.5 Tcl "Tcl Built-In Commands"
10.BS
11'\" Note:  do not modify the .SH NAME line immediately below!
12.SH NAME
13fblocked \- Test whether the last input operation exhausted all available input
14.SH SYNOPSIS
15\fBfblocked \fIchannelId\fR
16.BE
17
18.SH DESCRIPTION
19.PP
20The \fBfblocked\fR command returns 1 if the most recent input operation
21on \fIchannelId\fR returned less information than requested because all
22available input was exhausted.
23For example, if \fBgets\fR is invoked when there are only three
24characters available for input and no end-of-line sequence, \fBgets\fR
25returns an empty string and a subsequent call to \fBfblocked\fR will
26return 1.
27.PP
28\fIChannelId\fR must be an identifier for an open channel such as a
29Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR),
30the return value from an invocation of \fBopen\fR or \fBsocket\fR, or
31the result of a channel creation command provided by a Tcl extension.
32.SH EXAMPLE
33The \fBfblocked\fR command is particularly useful when writing network
34servers, as it allows you to write your code in a line-by-line style
35without preventing the servicing of other connections.  This can be
36seen in this simple echo-service:
37.PP
38.CS
39# This is called whenever a new client connects to the server
40proc connect {chan host port} {
41    set clientName [format <%s:%d> $host $port]
42    puts "connection from $clientName"
43    fconfigure $chan -blocking 0 -buffering line
44    fileevent $chan readable [list echoLine $chan $clientName]
45}
46
47# This is called whenever either at least one byte of input
48# data is available, or the channel was closed by the client.
49proc echoLine {chan clientName} {
50    gets $chan line
51    if {[eof $chan]} {
52        puts "finishing connection from $clientName"
53        close $chan
54    } elseif {![\fBfblocked\fR $chan]} {
55        # Didn't block waiting for end-of-line
56        puts "$clientName - $line"
57        puts $chan $line
58    }
59}
60
61# Create the server socket and enter the event-loop to wait
62# for incoming connections...
63socket -server connect 12345
64vwait forever
65.CE
66
67.SH "SEE ALSO"
68gets(n), open(n), read(n), socket(n), Tcl_StandardChannels(3)
69
70.SH KEYWORDS
71blocking, nonblocking
Note: See TracBrowser for help on using the repository browser.