We're trying to read as much as possible from tcp buffer up to 2*max_msg_size. When read ptr is over half a buffer (i.e. 1*max_msg_size), buffer is shifted left for a half. So I think remaining is always less than maxremaining.