you should know how many bytes you received every loop iteration, just keep a local count.

Code:
var %x = $sock($sockname).rcvd
while ($true) {
  sockread &bvar
  inc %x $sockbr
  if ($sockbr == 0 || %x >= %THEFILESIZE) break
}


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"