Skip to content

Commit

Permalink
break socket send into chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
elcritch committed Oct 27, 2020
1 parent cc5f422 commit 057c56d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/nesper/servers/rpc/rpcsocket_queue_mpack.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ proc sendChunks*(sourceClient: Socket, rmsg: string) =
sourceClient.send(move sl)
i = j

proc sendLength*(sourceClient: Socket, rmsg: string) =
var rmsgN: int = rmsg.len()
var rmsgSz = newString(4)
for i in 0..3:
rmsgSz[i] = char(rmsgN and 0xFF)
rmsgN = rmsgN shr 8

sourceClient.send(move rmsgSz)

proc rpcMsgPackQueueWriteHandler*(srv: TcpServerInfo[RpcQueueHandle], result: ReadyKey, sourceClient: Socket, qh: RpcQueueHandle) =
raise newException(OSError, "the request to the OS failed")

Expand All @@ -56,12 +65,8 @@ proc rpcMsgPackQueueReadHandler*(srv: TcpServerInfo[RpcQueueHandle], result: Rea
continue

var rmsg: string = msgpack2json.fromJsonNode(res)
var rmsgN: int = rmsg.len()
var rmsgSz = newString(4)
for i in 0..3:
rmsgSz[i] = char(rmsgN and 0xFF)
rmsgN = rmsgN shr 8

sourceClient.sendLength(rmsg)
sourceClient.sendChunks(rmsg)

except TimeoutError:
Expand Down

0 comments on commit 057c56d

Please sign in to comment.