Skip to content

Commit db3e179

Browse files
authored
Merge pull request #14 from fragcolor-xyz/master
Fix crash during handshake
2 parents 31946dd + d6d93b8 commit db3e179

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

private/utils.nim

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,32 @@ proc setOption*(r: RqlQuery, k: string, v: RqlQuery) {.noSideEffect, inline.} =
5454
proc setOption*[T](r: RqlQuery, k: string, v: T) {.noSideEffect, inline.} =
5555
r.optargs[k] = newDatum(v)
5656

57-
proc readUntil*(s: Socket, delim: char, bufferSize = 12): string =
58-
result = newString(bufferSize)
57+
proc readUntil*(s: Socket, delim: char): string =
58+
result = ""
59+
5960
var
6061
c: char
6162
byteRead = 0
63+
6264
while s.recv(addr c, 1) == 1:
6365
if c == delim:
6466
break
65-
if byteRead >= result.len:
66-
setLen(result, result.len + bufferSize)
67+
68+
result.add c
69+
inc byteRead
6770

68-
result[byteRead] = c
69-
inc(byteRead)
70-
71-
proc readUntil*(s: AsyncSocket, delim: char, bufferSize = 12): Future[string] {.async.} =
72-
result = newString(bufferSize)
71+
proc readUntil*(s: AsyncSocket, delim: char): Future[string] {.async.} =
72+
result = ""
73+
7374
var
7475
c: char
7576
byteRead = 0
7677
ret: int
78+
7779
while true:
7880
ret = await s.recvInto(addr c, 1)
7981
if ret != 1 or c == delim:
8082
break
81-
82-
if byteRead >= result.len:
83-
setLen(result, result.len + bufferSize)
84-
85-
result[byteRead] = c
86-
inc(byteRead)
83+
84+
result.add c
85+
inc byteRead

0 commit comments

Comments
 (0)