File
doc/fcopy.n
— part of check-in
[63410153ac]
at
2016-07-24 13:09:40
on branch core-8-6-branch
— [6a19dedc2e] "Clarified" what the units are that [chan copy] uses for -size and that synchronous copying returns.
(user:
dkf
size: 6620)
[more...]
0000: 27 5c 22 0a 27 5c 22 20 43 6f 70 79 72 69 67 68 '\".'\" Copyrigh
0010: 74 20 28 63 29 20 31 39 39 33 20 54 68 65 20 52 t (c) 1993 The R
0020: 65 67 65 6e 74 73 20 6f 66 20 74 68 65 20 55 6e egents of the Un
0030: 69 76 65 72 73 69 74 79 20 6f 66 20 43 61 6c 69 iversity of Cali
0040: 66 6f 72 6e 69 61 2e 0a 27 5c 22 20 43 6f 70 79 fornia..'\" Copy
0050: 72 69 67 68 74 20 28 63 29 20 31 39 39 34 2d 31 right (c) 1994-1
0060: 39 39 37 20 53 75 6e 20 4d 69 63 72 6f 73 79 73 997 Sun Microsys
0070: 74 65 6d 73 2c 20 49 6e 63 2e 0a 27 5c 22 0a 27 tems, Inc..'\".'
0080: 5c 22 20 53 65 65 20 74 68 65 20 66 69 6c 65 20 \" See the file
0090: 22 6c 69 63 65 6e 73 65 2e 74 65 72 6d 73 22 20 "license.terms"
00a0: 66 6f 72 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 for information
00b0: 6f 6e 20 75 73 61 67 65 20 61 6e 64 20 72 65 64 on usage and red
00c0: 69 73 74 72 69 62 75 74 69 6f 6e 0a 27 5c 22 20 istribution.'\"
00d0: 6f 66 20 74 68 69 73 20 66 69 6c 65 2c 20 61 6e of this file, an
00e0: 64 20 66 6f 72 20 61 20 44 49 53 43 4c 41 49 4d d for a DISCLAIM
00f0: 45 52 20 4f 46 20 41 4c 4c 20 57 41 52 52 41 4e ER OF ALL WARRAN
0100: 54 49 45 53 2e 0a 27 5c 22 0a 2e 54 48 20 66 63 TIES..'\"..TH fc
0110: 6f 70 79 20 6e 20 38 2e 30 20 54 63 6c 20 22 54 opy n 8.0 Tcl "T
0120: 63 6c 20 42 75 69 6c 74 2d 49 6e 20 43 6f 6d 6d cl Built-In Comm
0130: 61 6e 64 73 22 0a 2e 73 6f 20 6d 61 6e 2e 6d 61 ands"..so man.ma
0140: 63 72 6f 73 0a 2e 42 53 0a 27 5c 22 20 4e 6f 74 cros..BS.'\" Not
0150: 65 3a 20 20 64 6f 20 6e 6f 74 20 6d 6f 64 69 66 e: do not modif
0160: 79 20 74 68 65 20 2e 53 48 20 4e 41 4d 45 20 6c y the .SH NAME l
0170: 69 6e 65 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 ine immediately
0180: 62 65 6c 6f 77 21 0a 2e 53 48 20 4e 41 4d 45 0a below!..SH NAME.
0190: 66 63 6f 70 79 20 5c 2d 20 43 6f 70 79 20 64 61 fcopy \- Copy da
01a0: 74 61 20 66 72 6f 6d 20 6f 6e 65 20 63 68 61 6e ta from one chan
01b0: 6e 65 6c 20 74 6f 20 61 6e 6f 74 68 65 72 0a 2e nel to another..
01c0: 53 48 20 53 59 4e 4f 50 53 49 53 0a 5c 66 42 66 SH SYNOPSIS.\fBf
01d0: 63 6f 70 79 20 5c 66 49 69 6e 63 68 61 6e 5c 66 copy \fIinchan\f
01e0: 52 20 5c 66 49 6f 75 74 63 68 61 6e 5c 66 52 20 R \fIoutchan\fR
01f0: 3f 5c 66 42 5c 2d 73 69 7a 65 20 5c 66 49 73 69 ?\fB\-size \fIsi
0200: 7a 65 5c 66 52 3f 20 3f 5c 66 42 5c 2d 63 6f 6d ze\fR? ?\fB\-com
0210: 6d 61 6e 64 20 5c 66 49 63 61 6c 6c 62 61 63 6b mand \fIcallback
0220: 5c 66 52 3f 0a 2e 42 45 0a 0a 2e 53 48 20 44 45 \fR?..BE...SH DE
0230: 53 43 52 49 50 54 49 4f 4e 0a 2e 50 50 0a 54 68 SCRIPTION..PP.Th
0240: 65 20 5c 66 42 66 63 6f 70 79 5c 66 52 20 63 6f e \fBfcopy\fR co
0250: 6d 6d 61 6e 64 20 63 6f 70 69 65 73 20 64 61 74 mmand copies dat
0260: 61 20 66 72 6f 6d 20 6f 6e 65 20 49 2f 4f 20 63 a from one I/O c
0270: 68 61 6e 6e 65 6c 2c 20 5c 66 49 69 6e 63 68 61 hannel, \fIincha
0280: 6e 5c 66 52 20 74 6f 20 61 6e 6f 74 68 65 72 20 n\fR to another
0290: 49 2f 4f 20 63 68 61 6e 6e 65 6c 2c 20 5c 66 49 I/O channel, \fI
02a0: 6f 75 74 63 68 61 6e 5c 66 52 2e 0a 54 68 65 20 outchan\fR..The
02b0: 5c 66 42 66 63 6f 70 79 5c 66 52 20 63 6f 6d 6d \fBfcopy\fR comm
02c0: 61 6e 64 20 6c 65 76 65 72 61 67 65 73 20 74 68 and leverages th
02d0: 65 20 62 75 66 66 65 72 69 6e 67 20 69 6e 20 74 e buffering in t
02e0: 68 65 20 54 63 6c 20 49 2f 4f 20 73 79 73 74 65 he Tcl I/O syste
02f0: 6d 20 74 6f 0a 61 76 6f 69 64 20 65 78 74 72 61 m to.avoid extra
0300: 20 63 6f 70 69 65 73 20 61 6e 64 20 74 6f 20 61 copies and to a
0310: 76 6f 69 64 20 62 75 66 66 65 72 69 6e 67 20 74 void buffering t
0320: 6f 6f 20 6d 75 63 68 20 64 61 74 61 20 69 6e 0a oo much data in.
0330: 6d 61 69 6e 20 6d 65 6d 6f 72 79 20 77 68 65 6e main memory when
0340: 20 63 6f 70 79 69 6e 67 20 6c 61 72 67 65 20 66 copying large f
0350: 69 6c 65 73 20 74 6f 20 73 6c 6f 77 20 64 65 73 iles to slow des
0360: 74 69 6e 61 74 69 6f 6e 73 20 6c 69 6b 65 0a 6e tinations like.n
0370: 65 74 77 6f 72 6b 20 73 6f 63 6b 65 74 73 2e 0a etwork sockets..
0380: 2e 50 50 0a 54 68 65 20 5c 66 42 66 63 6f 70 79 .PP.The \fBfcopy
0390: 5c 66 52 0a 63 6f 6d 6d 61 6e 64 20 74 72 61 6e \fR.command tran
03a0: 73 66 65 72 73 20 64 61 74 61 20 66 72 6f 6d 20 sfers data from
03b0: 5c 66 49 69 6e 63 68 61 6e 5c 66 52 20 75 6e 74 \fIinchan\fR unt
03c0: 69 6c 20 65 6e 64 20 6f 66 20 66 69 6c 65 0a 6f il end of file.o
03d0: 72 20 5c 66 49 73 69 7a 65 5c 66 52 20 62 79 74 r \fIsize\fR byt
03e0: 65 73 20 6f 72 20 63 68 61 72 61 63 74 65 72 73 es or characters
03f0: 20 68 61 76 65 20 62 65 65 6e 0a 74 72 61 6e 73 have been.trans
0400: 66 65 72 72 65 64 3b 20 5c 66 49 73 69 7a 65 5c ferred; \fIsize\
0410: 66 52 20 69 73 20 69 6e 20 62 79 74 65 73 20 69 fR is in bytes i
0420: 66 20 74 68 65 20 74 77 6f 20 63 68 61 6e 6e 65 f the two channe
0430: 6c 73 20 61 72 65 20 75 73 69 6e 67 20 74 68 65 ls are using the
0440: 0a 73 61 6d 65 20 65 6e 63 6f 64 69 6e 67 2c 20 .same encoding,
0450: 61 6e 64 20 69 73 20 69 6e 20 63 68 61 72 61 63 and is in charac
0460: 74 65 72 73 20 6f 74 68 65 72 77 69 73 65 2e 0a ters otherwise..
0470: 49 66 20 6e 6f 20 5c 66 42 5c 2d 73 69 7a 65 5c If no \fB\-size\
0480: 66 52 20 61 72 67 75 6d 65 6e 74 20 69 73 20 67 fR argument is g
0490: 69 76 65 6e 2c 0a 74 68 65 6e 20 74 68 65 20 63 iven,.then the c
04a0: 6f 70 79 20 67 6f 65 73 20 75 6e 74 69 6c 20 65 opy goes until e
04b0: 6e 64 20 6f 66 20 66 69 6c 65 2e 0a 41 6c 6c 20 nd of file..All
04c0: 74 68 65 20 64 61 74 61 20 72 65 61 64 20 66 72 the data read fr
04d0: 6f 6d 20 5c 66 49 69 6e 63 68 61 6e 5c 66 52 20 om \fIinchan\fR
04e0: 69 73 20 63 6f 70 69 65 64 20 74 6f 20 5c 66 49 is copied to \fI
04f0: 6f 75 74 63 68 61 6e 5c 66 52 2e 0a 57 69 74 68 outchan\fR..With
0500: 6f 75 74 20 74 68 65 20 5c 66 42 5c 2d 63 6f 6d out the \fB\-com
0510: 6d 61 6e 64 5c 66 52 20 6f 70 74 69 6f 6e 2c 20 mand\fR option,
0520: 5c 66 42 66 63 6f 70 79 5c 66 52 20 62 6c 6f 63 \fBfcopy\fR bloc
0530: 6b 73 20 75 6e 74 69 6c 20 74 68 65 20 63 6f 70 ks until the cop
0540: 79 20 69 73 20 63 6f 6d 70 6c 65 74 65 0a 61 6e y is complete.an
0550: 64 20 72 65 74 75 72 6e 73 20 74 68 65 20 6e 75 d returns the nu
0560: 6d 62 65 72 20 6f 66 20 62 79 74 65 73 20 6f 72 mber of bytes or
0570: 20 63 68 61 72 61 63 74 65 72 73 20 28 75 73 69 characters (usi
0580: 6e 67 20 74 68 65 20 73 61 6d 65 20 72 75 6c 65 ng the same rule
0590: 73 20 61 73 0a 66 6f 72 20 74 68 65 20 5c 66 42 s as.for the \fB
05a0: 5c 2d 73 69 7a 65 5c 66 52 20 6f 70 74 69 6f 6e \-size\fR option
05b0: 29 20 77 72 69 74 74 65 6e 20 74 6f 20 5c 66 49 ) written to \fI
05c0: 6f 75 74 63 68 61 6e 5c 66 52 2e 0a 2e 50 50 0a outchan\fR...PP.
05d0: 54 68 65 20 5c 66 42 5c 2d 63 6f 6d 6d 61 6e 64 The \fB\-command
05e0: 5c 66 52 20 61 72 67 75 6d 65 6e 74 20 6d 61 6b \fR argument mak
05f0: 65 73 20 5c 66 42 66 63 6f 70 79 5c 66 52 20 77 es \fBfcopy\fR w
0600: 6f 72 6b 20 69 6e 20 74 68 65 20 62 61 63 6b 67 ork in the backg
0610: 72 6f 75 6e 64 2e 0a 49 6e 20 74 68 69 73 20 63 round..In this c
0620: 61 73 65 20 69 74 20 72 65 74 75 72 6e 73 20 69 ase it returns i
0630: 6d 6d 65 64 69 61 74 65 6c 79 20 61 6e 64 20 74 mmediately and t
0640: 68 65 20 5c 66 49 63 61 6c 6c 62 61 63 6b 5c 66 he \fIcallback\f
0650: 52 20 69 73 20 69 6e 76 6f 6b 65 64 0a 6c 61 74 R is invoked.lat
0660: 65 72 20 77 68 65 6e 20 74 68 65 20 63 6f 70 79 er when the copy
0670: 20 63 6f 6d 70 6c 65 74 65 73 2e 0a 54 68 65 20 completes..The
0680: 5c 66 49 63 61 6c 6c 62 61 63 6b 5c 66 52 20 69 \fIcallback\fR i
0690: 73 20 63 61 6c 6c 65 64 20 77 69 74 68 0a 6f 6e s called with.on
06a0: 65 20 6f 72 20 74 77 6f 20 61 64 64 69 74 69 6f e or two additio
06b0: 6e 61 6c 0a 61 72 67 75 6d 65 6e 74 73 20 74 68 nal.arguments th
06c0: 61 74 20 69 6e 64 69 63 61 74 65 73 20 68 6f 77 at indicates how
06d0: 20 6d 61 6e 79 20 62 79 74 65 73 20 77 65 72 65 many bytes were
06e0: 20 77 72 69 74 74 65 6e 20 74 6f 20 5c 66 49 6f written to \fIo
06f0: 75 74 63 68 61 6e 5c 66 52 2e 0a 49 66 20 61 6e utchan\fR..If an
0700: 20 65 72 72 6f 72 20 6f 63 63 75 72 72 65 64 20 error occurred
0710: 64 75 72 69 6e 67 20 74 68 65 20 62 61 63 6b 67 during the backg
0720: 72 6f 75 6e 64 20 63 6f 70 79 2c 20 74 68 65 20 round copy, the
0730: 73 65 63 6f 6e 64 20 61 72 67 75 6d 65 6e 74 20 second argument
0740: 69 73 20 74 68 65 0a 65 72 72 6f 72 20 73 74 72 is the.error str
0750: 69 6e 67 20 61 73 73 6f 63 69 61 74 65 64 20 77 ing associated w
0760: 69 74 68 20 74 68 65 20 65 72 72 6f 72 2e 0a 57 ith the error..W
0770: 69 74 68 20 61 20 62 61 63 6b 67 72 6f 75 6e 64 ith a background
0780: 20 63 6f 70 79 2c 0a 69 74 20 69 73 20 6e 6f 74 copy,.it is not
0790: 20 6e 65 63 65 73 73 61 72 79 20 74 6f 20 70 75 necessary to pu
07a0: 74 20 5c 66 49 69 6e 63 68 61 6e 5c 66 52 20 6f t \fIinchan\fR o
07b0: 72 20 5c 66 49 6f 75 74 63 68 61 6e 5c 66 52 20 r \fIoutchan\fR
07c0: 69 6e 74 6f 0a 6e 6f 6e 2d 62 6c 6f 63 6b 69 6e into.non-blockin
07d0: 67 20 6d 6f 64 65 3b 20 74 68 65 20 5c 66 42 66 g mode; the \fBf
07e0: 63 6f 70 79 5c 66 52 20 63 6f 6d 6d 61 6e 64 20 copy\fR command
07f0: 74 61 6b 65 73 20 63 61 72 65 20 6f 66 20 74 68 takes care of th
0800: 61 74 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 at automatically
0810: 2e 0a 48 6f 77 65 76 65 72 2c 20 69 74 20 69 73 ..However, it is
0820: 20 6e 65 63 65 73 73 61 72 79 20 74 6f 20 65 6e necessary to en
0830: 74 65 72 20 74 68 65 20 65 76 65 6e 74 20 6c 6f ter the event lo
0840: 6f 70 20 62 79 20 75 73 69 6e 67 0a 74 68 65 20 op by using.the
0850: 5c 66 42 76 77 61 69 74 5c 66 52 20 63 6f 6d 6d \fBvwait\fR comm
0860: 61 6e 64 20 6f 72 20 62 79 20 75 73 69 6e 67 20 and or by using
0870: 54 6b 2e 0a 2e 50 50 0a 59 6f 75 20 61 72 65 20 Tk...PP.You are
0880: 6e 6f 74 20 61 6c 6c 6f 77 65 64 20 74 6f 20 64 not allowed to d
0890: 6f 20 6f 74 68 65 72 20 69 6e 70 75 74 20 6f 70 o other input op
08a0: 65 72 61 74 69 6f 6e 73 20 77 69 74 68 20 5c 66 erations with \f
08b0: 49 69 6e 63 68 61 6e 5c 66 52 2c 20 6f 72 0a 6f Iinchan\fR, or.o
08c0: 75 74 70 75 74 20 6f 70 65 72 61 74 69 6f 6e 73 utput operations
08d0: 20 77 69 74 68 20 5c 66 49 6f 75 74 63 68 61 6e with \fIoutchan
08e0: 5c 66 52 2c 20 64 75 72 69 6e 67 20 61 20 62 61 \fR, during a ba
08f0: 63 6b 67 72 6f 75 6e 64 0a 5c 66 42 66 63 6f 70 ckground.\fBfcop
0900: 79 5c 66 52 2e 20 54 68 65 20 63 6f 6e 76 65 72 y\fR. The conver
0910: 73 65 20 69 73 20 65 6e 74 69 72 65 6c 79 20 6c se is entirely l
0920: 65 67 69 74 69 6d 61 74 65 2c 20 61 73 20 65 78 egitimate, as ex
0930: 68 69 62 69 74 65 64 20 62 79 20 74 68 65 0a 62 hibited by the.b
0940: 69 64 69 72 65 63 74 69 6f 6e 61 6c 20 66 63 6f idirectional fco
0950: 70 79 20 65 78 61 6d 70 6c 65 20 62 65 6c 6f 77 py example below
0960: 2e 0a 2e 50 50 0a 49 66 20 65 69 74 68 65 72 20 ...PP.If either
0970: 5c 66 49 69 6e 63 68 61 6e 5c 66 52 20 6f 72 20 \fIinchan\fR or
0980: 5c 66 49 6f 75 74 63 68 61 6e 5c 66 52 20 67 65 \fIoutchan\fR ge
0990: 74 20 63 6c 6f 73 65 64 0a 77 68 69 6c 65 20 74 t closed.while t
09a0: 68 65 20 63 6f 70 79 20 69 73 20 69 6e 20 70 72 he copy is in pr
09b0: 6f 67 72 65 73 73 2c 20 74 68 65 20 63 75 72 72 ogress, the curr
09c0: 65 6e 74 20 63 6f 70 79 20 69 73 20 73 74 6f 70 ent copy is stop
09d0: 70 65 64 0a 61 6e 64 20 74 68 65 20 63 6f 6d 6d ped.and the comm
09e0: 61 6e 64 20 63 61 6c 6c 62 61 63 6b 20 69 73 20 and callback is
09f0: 5c 66 49 6e 6f 74 5c 66 52 20 6d 61 64 65 2e 0a \fInot\fR made..
0a00: 49 66 20 5c 66 49 69 6e 63 68 61 6e 5c 66 52 20 If \fIinchan\fR
0a10: 69 73 20 63 6c 6f 73 65 64 2c 0a 74 68 65 6e 20 is closed,.then
0a20: 61 6c 6c 20 64 61 74 61 20 61 6c 72 65 61 64 79 all data already
0a30: 20 71 75 65 75 65 64 20 66 6f 72 20 5c 66 49 6f queued for \fIo
0a40: 75 74 63 68 61 6e 5c 66 52 20 69 73 20 77 72 69 utchan\fR is wri
0a50: 74 74 65 6e 20 6f 75 74 2e 0a 2e 50 50 0a 4e 6f tten out...PP.No
0a60: 74 65 20 74 68 61 74 20 5c 66 49 69 6e 63 68 61 te that \fIincha
0a70: 6e 5c 66 52 20 63 61 6e 20 62 65 63 6f 6d 65 20 n\fR can become
0a80: 72 65 61 64 61 62 6c 65 20 64 75 72 69 6e 67 20 readable during
0a90: 61 20 62 61 63 6b 67 72 6f 75 6e 64 20 63 6f 70 a background cop
0aa0: 79 2e 0a 59 6f 75 20 73 68 6f 75 6c 64 20 74 75 y..You should tu
0ab0: 72 6e 20 6f 66 66 20 61 6e 79 20 5c 66 42 66 69 rn off any \fBfi
0ac0: 6c 65 65 76 65 6e 74 5c 66 52 20 68 61 6e 64 6c leevent\fR handl
0ad0: 65 72 73 20 64 75 72 69 6e 67 20 61 20 62 61 63 ers during a bac
0ae0: 6b 67 72 6f 75 6e 64 0a 63 6f 70 79 20 73 6f 20 kground.copy so
0af0: 74 68 6f 73 65 20 68 61 6e 64 6c 65 72 73 20 64 those handlers d
0b00: 6f 20 6e 6f 74 20 69 6e 74 65 72 66 65 72 65 20 o not interfere
0b10: 77 69 74 68 20 74 68 65 20 63 6f 70 79 2e 0a 41 with the copy..A
0b20: 6e 79 20 77 72 6f 6e 67 2d 73 69 64 65 64 20 49 ny wrong-sided I
0b30: 2f 4f 20 61 74 74 65 6d 70 74 65 64 20 28 62 79 /O attempted (by
0b40: 20 61 20 5c 66 42 66 69 6c 65 65 76 65 6e 74 5c a \fBfileevent\
0b50: 66 52 20 68 61 6e 64 6c 65 72 20 6f 72 20 6f 74 fR handler or ot
0b60: 68 65 72 77 69 73 65 29 20 77 69 6c 6c 20 67 65 herwise) will ge
0b70: 74 20 61 0a 2e 51 57 20 22 63 68 61 6e 6e 65 6c t a..QW "channel
0b80: 20 62 75 73 79 22 0a 65 72 72 6f 72 2e 0a 2e 50 busy".error...P
0b90: 50 0a 5c 66 42 46 63 6f 70 79 5c 66 52 20 74 72 P.\fBFcopy\fR tr
0ba0: 61 6e 73 6c 61 74 65 73 20 65 6e 64 2d 6f 66 2d anslates end-of-
0bb0: 6c 69 6e 65 20 73 65 71 75 65 6e 63 65 73 20 69 line sequences i
0bc0: 6e 20 5c 66 49 69 6e 63 68 61 6e 5c 66 52 20 61 n \fIinchan\fR a
0bd0: 6e 64 20 5c 66 49 6f 75 74 63 68 61 6e 5c 66 52 nd \fIoutchan\fR
0be0: 0a 61 63 63 6f 72 64 69 6e 67 20 74 6f 20 74 68 .according to th
0bf0: 65 20 5c 66 42 5c 2d 74 72 61 6e 73 6c 61 74 69 e \fB\-translati
0c00: 6f 6e 5c 66 52 20 6f 70 74 69 6f 6e 0a 66 6f 72 on\fR option.for
0c10: 20 74 68 65 73 65 20 63 68 61 6e 6e 65 6c 73 2e these channels.
0c20: 0a 53 65 65 20 74 68 65 20 6d 61 6e 75 61 6c 20 .See the manual
0c30: 65 6e 74 72 79 20 66 6f 72 20 5c 66 42 66 63 6f entry for \fBfco
0c40: 6e 66 69 67 75 72 65 5c 66 52 20 66 6f 72 20 64 nfigure\fR for d
0c50: 65 74 61 69 6c 73 20 6f 6e 20 74 68 65 0a 5c 66 etails on the.\f
0c60: 42 5c 2d 74 72 61 6e 73 6c 61 74 69 6f 6e 5c 66 B\-translation\f
0c70: 52 20 6f 70 74 69 6f 6e 2e 0a 54 68 65 20 74 72 R option..The tr
0c80: 61 6e 73 6c 61 74 69 6f 6e 73 20 6d 65 61 6e 20 anslations mean
0c90: 74 68 61 74 20 74 68 65 20 6e 75 6d 62 65 72 20 that the number
0ca0: 6f 66 20 62 79 74 65 73 20 72 65 61 64 20 66 72 of bytes read fr
0cb0: 6f 6d 20 5c 66 49 69 6e 63 68 61 6e 5c 66 52 0a om \fIinchan\fR.
0cc0: 63 61 6e 20 62 65 20 64 69 66 66 65 72 65 6e 74 can be different
0cd0: 20 74 68 61 6e 20 74 68 65 20 6e 75 6d 62 65 72 than the number
0ce0: 20 6f 66 20 62 79 74 65 73 20 77 72 69 74 74 65 of bytes writte
0cf0: 6e 20 74 6f 20 5c 66 49 6f 75 74 63 68 61 6e 5c n to \fIoutchan\
0d00: 66 52 2e 0a 4f 6e 6c 79 20 74 68 65 20 6e 75 6d fR..Only the num
0d10: 62 65 72 20 6f 66 20 62 79 74 65 73 20 77 72 69 ber of bytes wri
0d20: 74 74 65 6e 20 74 6f 20 5c 66 49 6f 75 74 63 68 tten to \fIoutch
0d30: 61 6e 5c 66 52 20 69 73 20 72 65 70 6f 72 74 65 an\fR is reporte
0d40: 64 2c 0a 65 69 74 68 65 72 20 61 73 20 74 68 65 d,.either as the
0d50: 20 72 65 74 75 72 6e 20 76 61 6c 75 65 20 6f 66 return value of
0d60: 20 61 20 73 79 6e 63 68 72 6f 6e 6f 75 73 20 5c a synchronous \
0d70: 66 42 66 63 6f 70 79 5c 66 52 20 6f 72 0a 61 73 fBfcopy\fR or.as
0d80: 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20 74 6f the argument to
0d90: 20 74 68 65 20 63 61 6c 6c 62 61 63 6b 20 66 6f the callback fo
0da0: 72 20 61 6e 20 61 73 79 6e 63 68 72 6f 6e 6f 75 r an asynchronou
0db0: 73 20 5c 66 42 66 63 6f 70 79 5c 66 52 2e 0a 2e s \fBfcopy\fR...
0dc0: 50 50 0a 5c 66 42 46 63 6f 70 79 5c 66 52 20 6f PP.\fBFcopy\fR o
0dd0: 62 65 79 73 20 74 68 65 20 65 6e 63 6f 64 69 6e beys the encodin
0de0: 67 73 20 61 6e 64 20 63 68 61 72 61 63 74 65 72 gs and character
0df0: 20 74 72 61 6e 73 6c 61 74 69 6f 6e 73 20 63 6f translations co
0e00: 6e 66 69 67 75 72 65 64 0a 66 6f 72 20 74 68 65 nfigured.for the
0e10: 20 63 68 61 6e 6e 65 6c 73 2e 20 54 68 69 73 0a channels. This.
0e20: 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 20 69 means that the i
0e30: 6e 63 6f 6d 69 6e 67 20 63 68 61 72 61 63 74 65 ncoming characte
0e40: 72 73 20 61 72 65 20 63 6f 6e 76 65 72 74 65 64 rs are converted
0e50: 20 69 6e 74 65 72 6e 61 6c 6c 79 20 66 69 72 73 internally firs
0e60: 74 0a 55 54 46 2d 38 20 61 6e 64 20 74 68 65 6e t.UTF-8 and then
0e70: 20 69 6e 74 6f 20 74 68 65 20 65 6e 63 6f 64 69 into the encodi
0e80: 6e 67 20 6f 66 20 74 68 65 20 63 68 61 6e 6e 65 ng of the channe
0e90: 6c 20 5c 66 42 66 63 6f 70 79 5c 66 52 20 77 72 l \fBfcopy\fR wr
0ea0: 69 74 65 73 0a 74 6f 2e 20 53 65 65 20 74 68 65 ites.to. See the
0eb0: 20 6d 61 6e 75 61 6c 20 65 6e 74 72 79 20 66 6f manual entry fo
0ec0: 72 20 5c 66 42 66 63 6f 6e 66 69 67 75 72 65 5c r \fBfconfigure\
0ed0: 66 52 20 66 6f 72 20 64 65 74 61 69 6c 73 20 6f fR for details o
0ee0: 6e 20 74 68 65 0a 5c 66 42 5c 2d 65 6e 63 6f 64 n the.\fB\-encod
0ef0: 69 6e 67 5c 66 52 20 61 6e 64 20 5c 66 42 5c 2d ing\fR and \fB\-
0f00: 74 72 61 6e 73 6c 61 74 69 6f 6e 5c 66 52 20 6f translation\fR o
0f10: 70 74 69 6f 6e 73 2e 20 4e 6f 20 63 6f 6e 76 65 ptions. No conve
0f20: 72 73 69 6f 6e 20 69 73 0a 64 6f 6e 65 20 69 66 rsion is.done if
0f30: 20 62 6f 74 68 20 63 68 61 6e 6e 65 6c 73 20 61 both channels a
0f40: 72 65 0a 73 65 74 20 74 6f 20 65 6e 63 6f 64 69 re.set to encodi
0f50: 6e 67 0a 2e 51 57 20 62 69 6e 61 72 79 0a 61 6e ng..QW binary.an
0f60: 64 20 68 61 76 65 20 6d 61 74 63 68 69 6e 67 20 d have matching
0f70: 74 72 61 6e 73 6c 61 74 69 6f 6e 73 2e 20 49 66 translations. If
0f80: 20 6f 6e 6c 79 20 74 68 65 20 6f 75 74 70 75 74 only the output
0f90: 20 63 68 61 6e 6e 65 6c 20 69 73 20 73 65 74 20 channel is set
0fa0: 74 6f 20 65 6e 63 6f 64 69 6e 67 0a 2e 51 57 20 to encoding..QW
0fb0: 62 69 6e 61 72 79 0a 74 68 65 20 73 79 73 74 65 binary.the syste
0fc0: 6d 20 77 69 6c 6c 20 77 72 69 74 65 20 74 68 65 m will write the
0fd0: 20 69 6e 74 65 72 6e 61 6c 20 55 54 46 2d 38 20 internal UTF-8
0fe0: 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 6f representation o
0ff0: 66 20 74 68 65 20 69 6e 63 6f 6d 69 6e 67 0a 63 f the incoming.c
1000: 68 61 72 61 63 74 65 72 73 2e 20 49 66 20 6f 6e haracters. If on
1010: 6c 79 20 74 68 65 20 69 6e 70 75 74 20 63 68 61 ly the input cha
1020: 6e 6e 65 6c 20 69 73 20 73 65 74 20 74 6f 20 65 nnel is set to e
1030: 6e 63 6f 64 69 6e 67 0a 2e 51 57 20 62 69 6e 61 ncoding..QW bina
1040: 72 79 0a 74 68 65 20 73 79 73 74 65 6d 20 77 69 ry.the system wi
1050: 6c 6c 20 61 73 73 75 6d 65 20 74 68 61 74 20 74 ll assume that t
1060: 68 65 20 69 6e 63 6f 6d 69 6e 67 0a 62 79 74 65 he incoming.byte
1070: 73 20 61 72 65 20 76 61 6c 69 64 20 55 54 46 2d s are valid UTF-
1080: 38 20 63 68 61 72 61 63 74 65 72 73 20 61 6e 64 8 characters and
1090: 20 63 6f 6e 76 65 72 74 20 74 68 65 6d 20 61 63 convert them ac
10a0: 63 6f 72 64 69 6e 67 20 74 6f 20 74 68 65 0a 6f cording to the.o
10b0: 75 74 70 75 74 20 65 6e 63 6f 64 69 6e 67 2e 20 utput encoding.
10c0: 54 68 65 20 62 65 68 61 76 69 6f 75 72 20 6f 66 The behaviour of
10d0: 20 74 68 65 20 73 79 73 74 65 6d 20 66 6f 72 20 the system for
10e0: 62 79 74 65 73 20 77 68 69 63 68 20 61 72 65 20 bytes which are
10f0: 6e 6f 74 0a 76 61 6c 69 64 20 55 54 46 2d 38 20 not.valid UTF-8
1100: 63 68 61 72 61 63 74 65 72 73 20 69 73 20 75 6e characters is un
1110: 64 65 66 69 6e 65 64 20 69 6e 20 74 68 69 73 20 defined in this
1120: 63 61 73 65 2e 0a 2e 53 48 20 45 58 41 4d 50 4c case...SH EXAMPL
1130: 45 53 0a 2e 50 50 0a 54 68 65 20 66 69 72 73 74 ES..PP.The first
1140: 20 65 78 61 6d 70 6c 65 20 74 72 61 6e 73 66 65 example transfe
1150: 72 73 20 74 68 65 20 63 6f 6e 74 65 6e 74 73 20 rs the contents
1160: 6f 66 20 6f 6e 65 20 63 68 61 6e 6e 65 6c 20 65 of one channel e
1170: 78 61 63 74 6c 79 20 74 6f 0a 61 6e 6f 74 68 65 xactly to.anothe
1180: 72 2e 20 4e 6f 74 65 20 74 68 61 74 20 77 68 65 r. Note that whe
1190: 6e 20 63 6f 70 79 69 6e 67 20 6f 6e 65 20 66 69 n copying one fi
11a0: 6c 65 20 74 6f 20 61 6e 6f 74 68 65 72 2c 20 69 le to another, i
11b0: 74 20 69 73 20 62 65 74 74 65 72 20 74 6f 0a 75 t is better to.u
11c0: 73 65 20 5c 66 42 66 69 6c 65 20 63 6f 70 79 5c se \fBfile copy\
11d0: 66 52 20 77 68 69 63 68 20 61 6c 73 6f 20 63 6f fR which also co
11e0: 70 69 65 73 20 66 69 6c 65 20 6d 65 74 61 64 61 pies file metada
11f0: 74 61 20 28 65 2e 67 2e 20 74 68 65 20 66 69 6c ta (e.g. the fil
1200: 65 0a 61 63 63 65 73 73 20 70 65 72 6d 69 73 73 e.access permiss
1210: 69 6f 6e 73 29 20 77 68 65 72 65 20 70 6f 73 73 ions) where poss
1220: 69 62 6c 65 2e 0a 2e 50 50 0a 2e 43 53 0a 66 63 ible...PP..CS.fc
1230: 6f 6e 66 69 67 75 72 65 20 24 69 6e 20 2d 74 72 onfigure $in -tr
1240: 61 6e 73 6c 61 74 69 6f 6e 20 62 69 6e 61 72 79 anslation binary
1250: 0a 66 63 6f 6e 66 69 67 75 72 65 20 24 6f 75 74 .fconfigure $out
1260: 20 2d 74 72 61 6e 73 6c 61 74 69 6f 6e 20 62 69 -translation bi
1270: 6e 61 72 79 0a 5c 66 42 66 63 6f 70 79 5c 66 52 nary.\fBfcopy\fR
1280: 20 24 69 6e 20 24 6f 75 74 0a 2e 43 45 0a 2e 50 $in $out..CE..P
1290: 50 0a 54 68 69 73 20 73 65 63 6f 6e 64 20 65 78 P.This second ex
12a0: 61 6d 70 6c 65 20 73 68 6f 77 73 20 68 6f 77 20 ample shows how
12b0: 74 68 65 20 63 61 6c 6c 62 61 63 6b 20 67 65 74 the callback get
12c0: 73 0a 70 61 73 73 65 64 20 74 68 65 20 6e 75 6d s.passed the num
12d0: 62 65 72 20 6f 66 20 62 79 74 65 73 20 74 72 61 ber of bytes tra
12e0: 6e 73 66 65 72 72 65 64 2e 0a 49 74 20 61 6c 73 nsferred..It als
12f0: 6f 20 75 73 65 73 20 76 77 61 69 74 20 74 6f 20 o uses vwait to
1300: 70 75 74 20 74 68 65 20 61 70 70 6c 69 63 61 74 put the applicat
1310: 69 6f 6e 20 69 6e 74 6f 20 74 68 65 20 65 76 65 ion into the eve
1320: 6e 74 20 6c 6f 6f 70 2e 0a 4f 66 20 63 6f 75 72 nt loop..Of cour
1330: 73 65 2c 20 74 68 69 73 20 73 69 6d 70 6c 69 66 se, this simplif
1340: 69 65 64 20 65 78 61 6d 70 6c 65 20 63 6f 75 6c ied example coul
1350: 64 20 62 65 20 64 6f 6e 65 20 77 69 74 68 6f 75 d be done withou
1360: 74 20 74 68 65 20 63 6f 6d 6d 61 6e 64 0a 63 61 t the command.ca
1370: 6c 6c 62 61 63 6b 2e 0a 2e 50 50 0a 2e 43 53 0a llback...PP..CS.
1380: 70 72 6f 63 20 43 6c 65 61 6e 75 70 20 7b 69 6e proc Cleanup {in
1390: 20 6f 75 74 20 62 79 74 65 73 20 7b 65 72 72 6f out bytes {erro
13a0: 72 20 7b 7d 7d 7d 20 7b 0a 20 20 20 20 67 6c 6f r {}}} {. glo
13b0: 62 61 6c 20 74 6f 74 61 6c 0a 20 20 20 20 73 65 bal total. se
13c0: 74 20 74 6f 74 61 6c 20 24 62 79 74 65 73 0a 20 t total $bytes.
13d0: 20 20 20 63 6c 6f 73 65 20 24 69 6e 0a 20 20 20 close $in.
13e0: 20 63 6c 6f 73 65 20 24 6f 75 74 0a 20 20 20 20 close $out.
13f0: 69 66 20 7b 5b 73 74 72 69 6e 67 20 6c 65 6e 67 if {[string leng
1400: 74 68 20 24 65 72 72 6f 72 5d 20 21 3d 20 30 7d th $error] != 0}
1410: 20 7b 0a 20 20 20 20 20 20 20 20 23 20 65 72 72 {. # err
1420: 6f 72 20 6f 63 63 75 72 72 65 64 20 64 75 72 69 or occurred duri
1430: 6e 67 20 74 68 65 20 63 6f 70 79 0a 20 20 20 20 ng the copy.
1440: 7d 0a 7d 0a 73 65 74 20 69 6e 20 5b 6f 70 65 6e }.}.set in [open
1450: 20 24 66 69 6c 65 31 5d 0a 73 65 74 20 6f 75 74 $file1].set out
1460: 20 5b 73 6f 63 6b 65 74 20 24 73 65 72 76 65 72 [socket $server
1470: 20 24 70 6f 72 74 5d 0a 5c 66 42 66 63 6f 70 79 $port].\fBfcopy
1480: 5c 66 52 20 24 69 6e 20 24 6f 75 74 20 2d 63 6f \fR $in $out -co
1490: 6d 6d 61 6e 64 20 5b 6c 69 73 74 20 43 6c 65 61 mmand [list Clea
14a0: 6e 75 70 20 24 69 6e 20 24 6f 75 74 5d 0a 76 77 nup $in $out].vw
14b0: 61 69 74 20 74 6f 74 61 6c 0a 2e 43 45 0a 2e 50 ait total..CE..P
14c0: 50 0a 54 68 65 20 74 68 69 72 64 20 65 78 61 6d P.The third exam
14d0: 70 6c 65 20 63 6f 70 69 65 73 20 69 6e 20 63 68 ple copies in ch
14e0: 75 6e 6b 73 20 61 6e 64 20 74 65 73 74 73 20 66 unks and tests f
14f0: 6f 72 20 65 6e 64 20 6f 66 20 66 69 6c 65 0a 69 or end of file.i
1500: 6e 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20 63 61 n the command ca
1510: 6c 6c 62 61 63 6b 2e 0a 2e 50 50 0a 2e 43 53 0a llback...PP..CS.
1520: 70 72 6f 63 20 43 6f 70 79 4d 6f 72 65 20 7b 69 proc CopyMore {i
1530: 6e 20 6f 75 74 20 63 68 75 6e 6b 20 62 79 74 65 n out chunk byte
1540: 73 20 7b 65 72 72 6f 72 20 7b 7d 7d 7d 20 7b 0a s {error {}}} {.
1550: 20 20 20 20 67 6c 6f 62 61 6c 20 74 6f 74 61 6c global total
1560: 20 64 6f 6e 65 0a 20 20 20 20 69 6e 63 72 20 74 done. incr t
1570: 6f 74 61 6c 20 24 62 79 74 65 73 0a 20 20 20 20 otal $bytes.
1580: 69 66 20 7b 28 5b 73 74 72 69 6e 67 20 6c 65 6e if {([string len
1590: 67 74 68 20 24 65 72 72 6f 72 5d 20 21 3d 20 30 gth $error] != 0
15a0: 29 20 7c 7c 20 5b 65 6f 66 20 24 69 6e 5d 7d 20 ) || [eof $in]}
15b0: 7b 0a 20 20 20 20 20 20 20 20 73 65 74 20 64 6f {. set do
15c0: 6e 65 20 24 74 6f 74 61 6c 0a 20 20 20 20 20 20 ne $total.
15d0: 20 20 63 6c 6f 73 65 20 24 69 6e 0a 20 20 20 20 close $in.
15e0: 20 20 20 20 63 6c 6f 73 65 20 24 6f 75 74 0a 20 close $out.
15f0: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 20 } else {.
1600: 20 20 20 20 5c 66 42 66 63 6f 70 79 5c 66 52 20 \fBfcopy\fR
1610: 24 69 6e 20 24 6f 75 74 20 2d 73 69 7a 65 20 24 $in $out -size $
1620: 63 68 75 6e 6b 20 5c 65 0a 20 20 20 20 20 20 20 chunk \e.
1630: 20 20 20 20 20 20 20 20 20 2d 63 6f 6d 6d 61 6e -comman
1640: 64 20 5b 6c 69 73 74 20 43 6f 70 79 4d 6f 72 65 d [list CopyMore
1650: 20 24 69 6e 20 24 6f 75 74 20 24 63 68 75 6e 6b $in $out $chunk
1660: 5d 0a 20 20 20 20 7d 0a 7d 0a 73 65 74 20 69 6e ]. }.}.set in
1670: 20 5b 6f 70 65 6e 20 24 66 69 6c 65 31 5d 0a 73 [open $file1].s
1680: 65 74 20 6f 75 74 20 5b 73 6f 63 6b 65 74 20 24 et out [socket $
1690: 73 65 72 76 65 72 20 24 70 6f 72 74 5d 0a 73 65 server $port].se
16a0: 74 20 63 68 75 6e 6b 20 31 30 32 34 0a 73 65 74 t chunk 1024.set
16b0: 20 74 6f 74 61 6c 20 30 0a 5c 66 42 66 63 6f 70 total 0.\fBfcop
16c0: 79 5c 66 52 20 24 69 6e 20 24 6f 75 74 20 2d 73 y\fR $in $out -s
16d0: 69 7a 65 20 24 63 68 75 6e 6b 20 5c 65 0a 20 20 ize $chunk \e.
16e0: 20 20 20 20 20 20 2d 63 6f 6d 6d 61 6e 64 20 5b -command [
16f0: 6c 69 73 74 20 43 6f 70 79 4d 6f 72 65 20 24 69 list CopyMore $i
1700: 6e 20 24 6f 75 74 20 24 63 68 75 6e 6b 5d 0a 76 n $out $chunk].v
1710: 77 61 69 74 20 64 6f 6e 65 0a 2e 43 45 0a 2e 50 wait done..CE..P
1720: 50 0a 54 68 65 20 66 6f 75 72 74 68 20 65 78 61 P.The fourth exa
1730: 6d 70 6c 65 20 73 74 61 72 74 73 20 61 6e 20 61 mple starts an a
1740: 73 79 6e 63 68 72 6f 6e 6f 75 73 2c 20 62 69 64 synchronous, bid
1750: 69 72 65 63 74 69 6f 6e 61 6c 20 66 63 6f 70 79 irectional fcopy
1760: 20 62 65 74 77 65 65 6e 0a 74 77 6f 20 73 6f 63 between.two soc
1770: 6b 65 74 73 2e 20 54 68 6f 73 65 20 63 6f 75 6c kets. Those coul
1780: 64 20 61 6c 73 6f 20 62 65 20 70 69 70 65 73 20 d also be pipes
1790: 66 72 6f 6d 20 74 77 6f 20 5b 6f 70 65 6e 20 22 from two [open "
17a0: 7c 68 61 6c 20 39 30 30 30 22 20 72 2b 5d 0a 28 |hal 9000" r+].(
17b0: 74 68 6f 75 67 68 20 74 68 65 69 72 20 63 6f 6e though their con
17c0: 76 65 72 73 61 74 69 6f 6e 20 77 6f 75 6c 64 20 versation would
17d0: 72 65 6d 61 69 6e 20 73 65 63 72 65 74 20 74 6f remain secret to
17e0: 20 74 68 65 20 73 63 72 69 70 74 2c 20 73 69 6e the script, sin
17f0: 63 65 0a 61 6c 6c 20 66 6f 75 72 20 66 69 6c 65 ce.all four file
1800: 65 76 65 6e 74 20 73 6c 6f 74 73 20 61 72 65 20 event slots are
1810: 62 75 73 79 29 2e 0a 2e 50 50 0a 2e 43 53 0a 73 busy)...PP..CS.s
1820: 65 74 20 66 6c 6f 77 73 20 32 0a 70 72 6f 63 20 et flows 2.proc
1830: 44 6f 6e 65 20 7b 64 69 72 20 61 72 67 73 7d 20 Done {dir args}
1840: 7b 0a 20 20 20 20 20 67 6c 6f 62 61 6c 20 66 6c {. global fl
1850: 6f 77 73 20 64 6f 6e 65 0a 20 20 20 20 20 70 75 ows done. pu
1860: 74 73 20 22 24 64 69 72 20 69 73 20 6f 76 65 72 ts "$dir is over
1870: 2e 22 0a 20 20 20 20 20 69 6e 63 72 20 66 6c 6f .". incr flo
1880: 77 73 20 2d 31 0a 20 20 20 20 20 69 66 20 7b 24 ws -1. if {$
1890: 66 6c 6f 77 73 3c 3d 30 7d 20 7b 73 65 74 20 64 flows<=0} {set d
18a0: 6f 6e 65 20 31 7d 0a 7d 0a 5c 66 42 66 63 6f 70 one 1}.}.\fBfcop
18b0: 79 5c 66 52 20 24 73 6f 6b 31 20 24 73 6f 6b 32 y\fR $sok1 $sok2
18c0: 20 2d 63 6f 6d 6d 61 6e 64 20 5b 6c 69 73 74 20 -command [list
18d0: 44 6f 6e 65 20 55 50 5d 0a 5c 66 42 66 63 6f 70 Done UP].\fBfcop
18e0: 79 5c 66 52 20 24 73 6f 6b 32 20 24 73 6f 6b 31 y\fR $sok2 $sok1
18f0: 20 2d 63 6f 6d 6d 61 6e 64 20 5b 6c 69 73 74 20 -command [list
1900: 44 6f 6e 65 20 44 4f 57 4e 5d 0a 76 77 61 69 74 Done DOWN].vwait
1910: 20 64 6f 6e 65 0a 2e 43 45 0a 2e 53 48 20 22 53 done..CE..SH "S
1920: 45 45 20 41 4c 53 4f 22 0a 65 6f 66 28 6e 29 2c EE ALSO".eof(n),
1930: 20 66 62 6c 6f 63 6b 65 64 28 6e 29 2c 20 66 63 fblocked(n), fc
1940: 6f 6e 66 69 67 75 72 65 28 6e 29 2c 20 66 69 6c onfigure(n), fil
1950: 65 28 6e 29 0a 2e 53 48 20 4b 45 59 57 4f 52 44 e(n)..SH KEYWORD
1960: 53 0a 62 6c 6f 63 6b 69 6e 67 2c 20 63 68 61 6e S.blocking, chan
1970: 6e 65 6c 2c 20 65 6e 64 20 6f 66 20 6c 69 6e 65 nel, end of line
1980: 2c 20 65 6e 64 20 6f 66 20 66 69 6c 65 2c 20 6e , end of file, n
1990: 6f 6e 62 6c 6f 63 6b 69 6e 67 2c 20 72 65 61 64 onblocking, read
19a0: 2c 20 74 72 61 6e 73 6c 61 74 69 6f 6e 0a 27 5c , translation.'\
19b0: 22 20 4c 6f 63 61 6c 20 56 61 72 69 61 62 6c 65 " Local Variable
19c0: 73 3a 0a 27 5c 22 20 6d 6f 64 65 3a 20 6e 72 6f s:.'\" mode: nro
19d0: 66 66 0a 27 5c 22 20 45 6e 64 3a 0a ff.'\" End:.