Tcl 预期:匹配\u最大设置缓冲区大小不正确

Tcl 预期:匹配\u最大设置缓冲区大小不正确,tcl,expect,Tcl,Expect,根据expect手册页面 match_max defines the size of the buffer (in bytes) used internally by expect. 但是,当我使用值1调用match_max时,expect内部一次使用四个字符。(这可以在exp_internal 1生成的输出中看到)将match_max设置为2,使用7个字节的缓冲区,3定义10个字符的缓冲区,4个引线指向13,5到16 为什么会这样 编辑-回答评论中的问题: 手动启动telnet会

根据expect手册页面

match_max
      defines the size of the buffer (in bytes) used internally by expect.
但是,当我使用值1调用
match_max
时,expect内部一次使用四个字符。(这可以在
exp_internal 1
生成的输出中看到)将
match_max
设置为2,使用7个字节的缓冲区,3定义10个字符的缓冲区,4个引线指向13,5到16

为什么会这样

编辑-回答评论中的问题:

手动启动telnet会话将提供以下输出:

Trying 192.168.xxx.yyy...
Connected to 192.168.xxx.yyy.
Escape character is '^]'.
运行telnet时,expect、
match_max
设置为1:

expect: does "Tryi" (spawn_id exp11) match glob pattern "Login: $"? no
"Password: $"? no
...
expect: does "ryin" (spawn_id exp11) match glob pattern "Login: $"? no
"Password: $"? no
一次考虑四个字符

匹配_max 2执行相同操作:

expect: does "Trying " (spawn_id exp11) match glob pattern "Login: $"? no
"Password: $"? no 
...
expect: does "ying 19" (spawn_id exp11) match glob pattern "Login: $"? no
"Password: $"? no

缓冲区实际上设置为七个字符。

我刚刚做了一个测试。对于较小的数字(大约小于
170
match_max N
实际上意味着
3N+1
。对于大数字,
N
意味着比
2N
多一点。似乎
expect
正在使用一个非常有趣的算法。:)


您能否发布指示实际
匹配\u max
值的输出?使用如此小的缓冲区有什么意义?使用如此小的缓冲区的意义在于测试我的
full\u buffer
处理程序是否工作正常。不知道为什么。但是如果
match\u max 1
真的有效,那么它就永远不会匹配像
Login:$
这样的长模式。
$ cat foo.exp
log_user 0
spawn yes hello world
match_max [lindex $argv 0]
set n 0
expect {
    full_buffer {
        send_user "forgotten: [string length $expect_out(buffer)]\n"
        if { [incr n] < 5 } {
            exp_continue
        }
    }
}
$ expect foo.exp 1
forgotten: 4
forgotten: 4
forgotten: 4
forgotten: 4
forgotten: 4
$ expect foo.exp 10
forgotten: 31
forgotten: 31
forgotten: 31
forgotten: 31
forgotten: 31
$ expect foo.exp 100
forgotten: 206
forgotten: 301
forgotten: 301
forgotten: 301
forgotten: 301
$ expect foo.exp 1000
forgotten: 2085
forgotten: 2075
forgotten: 2085
forgotten: 2106
forgotten: 2099
$ expect foo.exp 10000
forgotten: 20220
forgotten: 20169
forgotten: 20436
forgotten: 20566
forgotten: 20326
$ expect foo.exp 100000
forgotten: 200133
forgotten: 200161
forgotten: 200408
forgotten: 200090
forgotten: 200440
$
/* get the latest buffer size.  Double the user input for two */
/* reasons.  1) Need twice the space in case the match */
/* straddles two bufferfuls, 2) easier to hack the division by */
/* two when shifting the buffers later on */

bufsiz = 2*exp_match_max;