Emysql icon indicating copy to clipboard operation
Emysql copied to clipboard

Rewrite TCP Receive Loop

Open hdiedrich opened this issue 13 years ago • 2 comments

jlouis: "I'd do a simple

 gen_tcp:recv(Socket, PacketLength, ?TIMEOUT)

on the socket and then just wait for all data to arrive directly like this, or time out after a while. Then go again and wait if {error, timeout} occurs. It is simpler, pushes work to the C layer, and is probably going to run a faster route than this."

hdiedrich avatar Apr 28 '13 23:04 hdiedrich

Why would it have been implemented like this in the first place? Where there maybe in the past size limits in gen_tcp:recv, or any such?

hdiedrich avatar Apr 28 '13 23:04 hdiedrich

I don't really know, but I can only think of lack of knowledge. If we know that we need N bytes, we can decide for how long we are willing to wait on that to arrive and then get them all in one go. If we then get a timeout on the receive, we can choose to pick a smaller receive size to see if there is any progress on the socket at all and loop it a bit at a time, but I would rather just calculate a maximum receive timeout and then handle it that way.

jlouis avatar Apr 29 '13 08:04 jlouis