亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

轉到 crypto/ssh 包,stdoutpipe() io.Reader 的緩沖區限制是多少

轉到 crypto/ssh 包,stdoutpipe() io.Reader 的緩沖區限制是多少

Go
當年話下 2023-06-05 18:16:40
我正在編寫一個實用程序來使用 crypto/ssh 包在遠程服務器上執行命令。我目前正在從 session.stdoutpipe() io.Reader 讀取到一個 bytes.Buffer,我可以在會話完成后格式化并打印出來。文件指出:StdoutPipe func() (io.Reader, error) StdoutPipe 返回一個管道,該管道將在命令啟動時連接到遠程命令的標準輸出。stdout 和 stderr 流之間共享固定數量的緩沖。如果 StdoutPipe 讀取器的服務速度不夠快,最終可能會導致遠程命令阻塞。到目前為止,我的測試沒有遇到任何問題,但我很想知道固定金額是多少。在命令完成之前,我沒有讀取管道閱讀器就成功地流式傳輸了高達 6.5mb 的文本。有誰知道固定金額是多少,或者命令何時開始阻塞?我在源代碼中找不到它。
查看完整描述

1 回答

?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

它不在 Go 源代碼中,因為它依賴于操作系統。


應用程序不應依賴于特定的容量:應用程序應設計為讀取進程在數據可用時立即使用數據,這樣寫入進程就不會一直處于阻塞狀態。


例如,在 Linux 上:


$ man pipe


PIPE(2)                    Linux Programmer's Manual                   PIPE(2)


NAME

       pipe, pipe2 - create pipe


Pipe capacity


       A pipe has a limited capacity.  If the pipe is full, then a write(2)

       will block or fail, depending on whether the O_NONBLOCK flag is set

       (see below).  Different implementations have different limits for the

       pipe capacity.  Applications should not rely on a particular

       capacity: an application should be designed so that a reading process

       consumes data as soon as it is available, so that a writing process

       does not remain blocked.


       In Linux versions before 2.6.11, the capacity of a pipe was the same

       as the system page size (e.g., 4096 bytes on i386).  Since Linux

       2.6.11, the pipe capacity is 16 pages (i.e., 65,536 bytes in a system

       with a page size of 4096 bytes).  Since Linux 2.6.35, the default

       pipe capacity is 16 pages, but the capacity can be queried and set

       using the fcntl(2) F_GETPIPE_SZ and F_SETPIPE_SZ operations.  See

       fcntl(2) for more information.


查看完整回答
反對 回復 2023-06-05
  • 1 回答
  • 0 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號