Can I change the Demiliter that async uses? It's defaulted to \r\L I believe. I need it to detect the end of a recv by using \0. I'm talking about code like this "await user.socket.recvLine()"
I really hope I don't have to do something like
while line.contains(char(0)) == false:
var chunk = await user.socket.recv(1)
if chunk != "":
line.add(chunk)
else:
break
ThanksYou will need to do something similar I'm afraid. I would suggest checking chunk instead of using contains on the line, it will be more efficient.
The implementation of recvLineInto (what recvLine calls) might also be helpful https://github.com/nim-lang/Nim/blob/devel/lib/pure/asyncnet.nim#L319
dom96: Does this result in any loss of speed? And do you mean:
while chunk != char(0):
var chunk = await user.socket.recv(1)
if chunk != "":
line.add(chunk)
else:
break
Yes, I mean that.
It potentially will result in a loss of speed, yes. The sockets are buffered by default so you will be reading each character from the buffer, one by one, through a Future[char] which will be the biggest bottleneck. The recvLineInto procedure accesses the buffer directly, unfortunately the buffer is not exported so you can't do that. But we can export it in the stdlib easily to make such optimisations possible, it's just a matter of a simple PR :)
It would be cool if you benchmarked this though, I would love to see some timings.