-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Hi,
I was experimenting with the performance of this library and I noticed that I can drop the response time from ~500msec to ~15msec by making a simple change (which however is probably buggy for special cases). It may be a hack but if someone wants to get more juice from this library it may point to the best point of the code to look at.
Specifically in function ReceiveString()
I changed Loop While Len(buffer) > 0
to Loop While Len(buffer) = 1024
More details
This is the code of the function (without the variable Dims)
Public Function ReceiveString() As String
message = ""
Do
buffer = Trim(ReceiveBytes(1024))
If Len(buffer) > 0 Then
message = message & buffer
End If
Loop While Len(buffer) > 0
As far as I can tell with Loop While Len(buffer) > 0
you always do an extra call to ReceiveBytes(1024)
which it seems always times out after ~500msec if there are no more bytes from the client. This call is 99.9% of the time unneeded and that is why my tweak has the effect it has. I guess that 0.1% of the time my tweak will result in missing a part of the client request (specifically if the client sends 1024 bytes or 2048 bytes in two parts etc).
Is there any way we can make ReceiveBytes(1024)
return fast if there are no bytes waiting?