Provided by:
manpages-zh_1.5.1-1_all 
NAME
fcopy - 從一茬q道向另一蚑s數據
` SYNOPSIS
fcopy inchan outchan ?-size size? ?-command callback?
_________________________________________________________________
yz DESCRIPTION
fcopy 命令從一 I/O 通道 inchan 向另一 I/O 通道 outchan
複製數據。fcopy 命令在 Tcl I/O
系統中起到緩沖的槓桿作用(leverage),它避免額外的複製,並且在向慢速目標如網路套接口複製大檔案的時-
埡蚹K在主存中緩沖過多的數據。
fcopy 命令從 inchan 傳輸數據直到檔案結束或傳輸完
size字節。如果沒有給出 -size 參數,則複製持續到檔案結束。從
inchan讀的所有數據都複製到 outchan。如果沒有
-command選項,在複製完成並返回寫到 outchan 的字節數之前 fcopy 將阻塞。
-command 參數使 fcopy在-
I景工作。在這種情況下它立即返回,並在複製完成時調用 callback。調用
callback 加上一茤峔瑧額外的參數來指示有多少字節被寫到了 outchan。在-
I景複製期間如果發生了一蚇欞~,第二-
荌捊O與錯誤相關聯的錯誤字符串。使用I景複製不需n把 inchan 或 outchan
轉換成非阻塞模式;fcopy 命令將自動關照這些。但是,需n使用 vwait
命令或使用 Tk 進入事件循環。
在I景複製期間不允章 inchan 或 outchan 做其他 I/O
操作。如果在複製進行期間 inchan 或 outchan
中被關閉,停止當前的複製並且不做命令回調。如果 inchan被關閉,則寫出為
outchan 而排隊(queue)的所有數據。
注意在一茤R令複製期間 inchan 可以變成可讀的。在一-
I景複製期間你應該關閉任何
fileevent句柄,這樣這些句柄不與複製相觸及(interfere)。通過一
fileevent句柄的任何 I/O 嘗試將得到一 "channel busy" 錯誤。
Fcopy 依據 inchan 和 outchan 的 -translation選項來轉換它-
怳云瑰仵蛈瘚異籈C。參見fconfigure的手冊條目來得到 -translation
選項的詳情。轉換意味著從 inchan 讀到的字節數與寫到
outchan.的字節數可能不同。只報告寫到 outchan中的字節數。n麼作為同步的
fcopy 的返回An麼作為給異步的 fcopy 的回調的參數。
d EXAMPLE
第一茖狺l展示了回調如何得到傳遞給它的傳輸了的字節數。它還使用 vwait
來使應用進入事件循環。當然,不使用回調也能做出這蚋略F的例子。
proc Cleanup {in out bytes {error {}}} {
global total
set total $bytes
close $in
close $out
if {[string length $error] != 0} {
# error occurred during the copy
}
}
set in [open $file1]
set out [socket $server $port]
fcopy $in $out -command [list Cleanup $in $out]
vwait total
第二茖狺l按塊(chunk)複製並在命令回調中測試檔案結束。
proc CopyMore {in out chunk bytes {error {}}} {
global total done
incr total $bytes
if {([string length $error] != 0) || [eof $in] {
set done $total
close $in
close $out
} else {
fcopy $in $out -command [list CopyMore $in $out $chunk] \
-size $chunk
}
}
set in [open $file1]
set out [socket $server $port]
set chunk 1024
set total 0
fcopy $in $out -command [list CopyMore $in $out $chunk] -size $chunk
vwait done
SEE ALSO
eof(n), fblocked(n), fconfigure(n)
r KEYWORDS
blocking, channel, end of line, end of file, nonblocking, read,
translation
[]
Hhh
[]
2001/08/02
m Linux manUpn:
http://cmpp.linuxforum.net