The help file (mIRC v6.16) for /sockread says:
If you specify the -f switch with a %var variable, this forces mIRC to fill the %var variable with whatever text is in the receive buffer, even if it doesn't end in a $crlf.
The -n switch allows you to read a $crlf terminated line into a &binvar. If the incoming line does not contain a $crlf, no bytes will be read into &binvar, unless you specify the -f switch, which forces the read (same as when reading into %vars).
The -n switch allows reading in a &binvar like you'd read in a regular %var. This "line per line" reading works as expected.
So I'd expect -nf (with &binvar) to behave analogously to -f (with regular %var), which the help file also states explicitly.
But "sockread -nf &binvar" and "sockread -f %var" have a different behaviour. The former just reads everything in the buffer, including $crlf's, ignoring the -n switch, while the latter still reads "line per line" and in addition it reads any leftover data that doesn't end in $crlf.
So:
1. "sockread -f %var" doesn't work as described in the help file. It doesn't "fill the %var with whatever is in the buffer", because it still reads up to the next $crlf, unless there is data without any $crlf's left.
This behaviour makes more sense to me than reading everything out of the buffer, so I'd say it's a documentation bug.
2. "sockread -nf &binvar" does "fill the &var with whatever is in the buffer", but this is clearly not "the same as when reading into %vars".
Here's some code to illustrate things. It just writes "line1<CRLF>li<pause>ne2<CRLF>line3" and reads it with sockread into %vars and &binvars with different switches:
alias socktest {
set %socktest-num 1
set %socktest-socks binvar var binvar-n var-f binvar-nf binvar-f
set %socktest-switches - - -n -f -nf -f
socklisten socktest-listen 4567
var %s = socktest- $+ $gettok(%socktest-socks, %socktest-num, 32)
set %socktest-switch $gettok(%socktest-switches, %socktest-num, 32)
inc %socktest-num
sockopen %s localhost 4567
}
on *:SOCKLISTEN:socktest-listen: {
sockaccept socktest-server
bset -t &data1 1 line1 $+ $crlf $+ li
bset -t &data2 1 ne2 $+ $crlf $+ line3
sockwrite socktest-server &data1
.timer 1 1 sockwrite socktest-server $bvar(&data2,1,20).text
.timer 1 2 sockclose socktest-server
}
on *:SOCKWRITE:socktest-server: {
if ($sockerr) {
echo -ag Write failed
}
}
on *:SOCKOPEN:socktest-*: {
if (%socktest-switch == -) unset %socktest-switch
echo -ag Connected: $sockname
}
on *:SOCKCLOSE:socktest-*var*: {
echo -ag Left in buffer: $sock($sockname).rq
echo -ag ---
var %s = socktest- $+ $gettok(%socktest-socks, %socktest-num, 32)
set %socktest-switch $gettok(%socktest-switches, %socktest-num, 32)
if (%s != socktest-) {
inc %socktest-num
sockopen %s localhost 4567
}
else {
unset %socktest-*
sockclose socktest-listen
}
}
on *:SOCKREAD:socktest-binvar*: {
echo -ag Sockread
sockread %socktest-switch &binvar
while ($sockbr != 0) {
echo -ag read $sockbr bytes: $bvar(&binvar,1,100).text
sockread %socktest-switch &binvar
}
}
on *:SOCKREAD:socktest-var*: {
echo -ag Sockread
sockread %socktest-switch %var
while ($sockbr != 0) {
echo -ag read $sockbr bytes: %var
sockread %socktest-switch %var
}
}