dp_filehandler - to handle file descriptor conditions
dp_isready - Check if a socket has data pending
dp_update - Process pending events and/or when-idle handlers
dp_after - Execute a command after a certain amount of time has elapsed
dp_whenidle - Execute a command when the system is idle
dp_waitvariable - Wait for a variable to be modified
dp_filehandler sockId ?mode command?
dp_isready sockId
dp_update ?idletasks?
dp_after ms ?arg1 arg2 arg3 ...?
dp_whenidle command ?arg1 arg2 arg3 ...?
dp_waitvariable variable
L'|0u-1v'
L'0u+1v-0u'
The dp_isready command checks whether sockId is readable or
writeable using a select(2) system call. It returns a list of up two
boolean values (i.e., 1 or 0). The first value specifies whether
sockId is readable, and the second value specifies whether
sockId is writeable. For example, the tcl expression
if [lindex [dp_isready file3] 1] {MyOutput file3}
calls MyOutput if file3 is writeable.
The dp_update command is equivalent to the Tk "update" command,
except that it operates even if a connection to the X server is not
present. See the Tk documentation on "update" for an explanation of
it's usage.
The dp_after command is equivalent to the Tk "after" command,
except that it operates even if a connection to the X server is not
present. See the Tk documentation on "after" for an explanation of
it's usage.
The dp_whenidle command arranges for the specified Tcl/Tk command
to be evaluated whenever the system is about to go to sleep waiting for
an event to occur.
The dp_waitvariable command is equivalent to the Tk "tkwait variable"
command, except that it operates even if a connection to the X server
is not present. See the Tk documentation on "tkwait" for an explanation of
it's usage.
The dp_filehander command allows one to specify a Tcl/Tk
command which will be evaluated whenever the file descriptor
represented by sockId is readable, writable, and/or has an
exceptional condition pending. Command will be invoked with two
arguments appended: a single character indicating the mode
('r', 'w', or 'e'), and the sockId.
A sockId is an identifier which represents a file descriptor. It
is identical to the identifier manipulated by the Tcl-DP (Tcl
Distributed Programming) network connection management commands
(dp_connect, dp_shutdown, etc.). SockId's are also
manipulated by the read, eof, gets, puts, and close file management
commands of Tcl.
The mode argument indicates the situations when the command
will be evaluated. It may be any combination of the following values:
r
Eval command whenever there is data to be read from the
sockId. The command is evaluated with two arguments
appended: r to indicate that data is readable on the file
descriptor, and the sockId, which represents the file descriptor
that is readable. The command should read at least some data
from the sockId, or otherwise command will be called
continuously.
w
Eval command whenever data can be written to the sockId
without blocking. The command is evaluated with two arguments
appended: w to indicate that the file descriptor is writable, and
the sockId, which represents the writable file descriptor.
e
Eval command whenever there is an exceptional condition pending
on the sockId. The command is evaluated with two arguments
appended: e to indicate exception, and the sockId, which
represents the file descriptor with the exceptional condition.
If the mode and command arguments are not specified, then
any previously specified command for the given sockId is
deleted. Specifying a new command using the dp_filehandler
command will also delete any previously specified command for a
sockId.
The following file handlers create a telnet like interface to the
sendmail process (the smtp port) running on the local host. The command
"say" sends the string passed to it to sendmail. The reply is
automatically printed on stdout by the get_remote procedure.
proc get_remote {mode fid} {
# Exit if remote connection closed on us.
if {[gets $fid input] == -1} {
puts stdout "Connection closed by foreign host."
exit
}
puts stdout $input
}
proc say {args} {
global remote
puts $remote $args;
}
set remote [lindex [dp_connect localhost smtp] 0]
dp_filehandler $remote r get_remote
Tcl-DP, select(2)
Pekka Nikander, Telecom Finland (Pekka.Nikander@ajk.tele.fi)
Extended by Tim MacKenzie (tym@dibbler.cs.monash.edu.au)
Further enhancements by Brian Smith (bsmith@cs.berkeley.edu)
and Steve Yen (syen@cs.berkeley.edu)