doumindang2416 2019-02-10 03:27
浏览 266
已采纳

进入crypto / ssh包,stdoutpipe()io.Reader的缓冲区限制是多少

I'm writing a utility to execute commands on remote servers with the crypto/ssh package. I'm currently reading from the session.stdoutpipe() io.Reader in to a bytes.Buffer which I can format and print out after the session is complete.

The documentation states:

StdoutPipe func() (io.Reader, error) StdoutPipe returns a pipe that will be connected to the remote command's standard output when the command starts. There is a fixed amount of buffering that is shared between stdout and stderr streams. If the StdoutPipe reader is not serviced fast enough it may eventually cause the remote command to block.

I haven't had any issues so far with my testing, but it got me curious to know what is the fixed amount. I've successfully streamed text up to 6.5mb without reading the pipe Reader until the command has finished.

Does anyone know what the fixed amount is, or when the command will start to block? I can't find it in the source.

  • 写回答

1条回答 默认 最新

  • douliexu5623 2019-02-10 12:34
    关注

    It is not in the Go source because it's OS dependent.

    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.

    For example, on 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.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?