vwait.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:2k
- '"
- '" Copyright (c) 1995-1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: vwait.n,v 1.4.18.1 2004/10/27 14:43:15 dkf Exp $
- '"
- .so man.macros
- .TH vwait n 8.0 Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- vwait - Process events until a variable is written
- .SH SYNOPSIS
- fBvwaitfR fIvarNamefR
- .BE
- .SH DESCRIPTION
- .PP
- This command enters the Tcl event loop to process events, blocking
- the application if no events are ready. It continues processing
- events until some event handler sets the value of variable
- fIvarNamefR. Once fIvarNamefR has been set, the fBvwaitfR
- command will return as soon as the event handler that modified
- fIvarNamefR completes. fIvarNamefR must globally scoped
- (either with a call to fBglobalfR for the fIvarNamefR, or with
- the full namespace path specification).
- .PP
- In some cases the fBvwaitfR command may not return immediately
- after fIvarNamefR is set. This can happen if the event handler
- that sets fIvarNamefR does not complete immediately. For example,
- if an event handler sets fIvarNamefR and then itself calls
- fBvwaitfR to wait for a different variable, then it may not return
- for a long time. During this time the top-level fBvwaitfR is
- blocked waiting for the event handler to complete, so it cannot
- return either.
- .SH EXAMPLES
- Run the event-loop continually until some event calls fBexitfR.
- (You can use any variable not mentioned elsewhere, but the name
- fIforeverfR reminds you at a glance of the intent.)
- .CS
- fBvwaitfR forever
- .CE
- .PP
- Wait five seconds for a connection to a server socket, otherwise
- close the socket and continue running the script:
- .CS
- # Initialise the state
- after 5000 set state timeout
- set server [socket -server accept 12345]
- proc accept {args} {
- global state connectionInfo
- set state accepted
- set connectionInfo $args
- }
- # Wait for something to happen
- fBvwaitfR state
- # Clean up events that could have happened
- close $server
- after cancel set state timeout
- # Do something based on how the vwait finished...
- switch $state {
- timeout {
- puts "no connection on port 12345"
- }
- accepted {
- puts "connection: $connectionInfo"
- puts [lindex $connectionInfo 0] "Hello there!"
- }
- }
- .CE
- .SH "SEE ALSO"
- global(n), update(n)
- .SH KEYWORDS
- event, variable, wait