Renamed `client` access variable to `transport`
This commit is contained in:
parent
d5f397104e
commit
1feca64ca8
|
@ -112,7 +112,7 @@ proc genErrorSending(name, writeCode: NimNode): NimNode =
|
||||||
let error = %{"code": %(code), "id": id, "message": %msg, "data": data}
|
let error = %{"code": %(code), "id": id, "message": %msg, "data": data}
|
||||||
debug "Error generated", error = error, id = id
|
debug "Error generated", error = error, id = id
|
||||||
|
|
||||||
template client: untyped = clientTrans
|
template transport: untyped = clientTrans
|
||||||
var value {.inject.} = wrapReply(id, newJNull(), error)
|
var value {.inject.} = wrapReply(id, newJNull(), error)
|
||||||
`res` = `writeCode`
|
`res` = `writeCode`
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ proc genProcessMessages(name, sendErrorName, writeCode: NimNode): NimNode =
|
||||||
%(methodName & " is not a registered method."))
|
%(methodName & " is not a registered method."))
|
||||||
else:
|
else:
|
||||||
let callRes = await server.procs[methodName](node["params"])
|
let callRes = await server.procs[methodName](node["params"])
|
||||||
template client: untyped = clientTrans
|
template transport: untyped = clientTrans
|
||||||
var value {.inject.} = wrapReply(id, callRes, newJNull())
|
var value {.inject.} = wrapReply(id, callRes, newJNull())
|
||||||
asyncCheck `writeCode`
|
asyncCheck `writeCode`
|
||||||
|
|
||||||
|
@ -166,9 +166,9 @@ proc genProcessClient(nameIdent, procMessagesIdent, sendErrIdent, readCode, afte
|
||||||
var rpc = getUserData[RpcServer[S]](server)
|
var rpc = getUserData[RpcServer[S]](server)
|
||||||
while true:
|
while true:
|
||||||
var maxRequestLength {.inject.} = defaultMaxRequestLength
|
var maxRequestLength {.inject.} = defaultMaxRequestLength
|
||||||
template client: untyped = clientTrans
|
template transport: untyped = clientTrans
|
||||||
|
|
||||||
let value {.inject.} = await `readCode`
|
var value {.inject.} = await `readCode`
|
||||||
`afterReadCode`
|
`afterReadCode`
|
||||||
if value == "":
|
if value == "":
|
||||||
`closeCode`
|
`closeCode`
|
||||||
|
@ -209,11 +209,11 @@ macro defineRpcServerTransport*(procClientName: untyped, body: untyped = nil): u
|
||||||
procClientName.expectKind nnkIdent
|
procClientName.expectKind nnkIdent
|
||||||
var
|
var
|
||||||
writeCode = quote do:
|
writeCode = quote do:
|
||||||
client.write(value)
|
transport.write(value)
|
||||||
readCode = quote do:
|
readCode = quote do:
|
||||||
client.readLine(defaultMaxRequestLength)
|
transport.readLine(defaultMaxRequestLength)
|
||||||
closeCode = quote do:
|
closeCode = quote do:
|
||||||
client.close
|
transport.close
|
||||||
afterReadCode = newStmtList()
|
afterReadCode = newStmtList()
|
||||||
|
|
||||||
if body != nil:
|
if body != nil:
|
||||||
|
@ -228,21 +228,22 @@ macro defineRpcServerTransport*(procClientName: untyped, body: untyped = nil): u
|
||||||
|
|
||||||
case verb.toLowerAscii
|
case verb.toLowerAscii
|
||||||
of "write":
|
of "write":
|
||||||
# `client`, the RpcClient
|
# `transport`, the client transport
|
||||||
# `value`, the data returned from the invoked RPC
|
# `value`, the data returned from the invoked RPC
|
||||||
|
# Note: Update `value` so it's length can be sent afterwards
|
||||||
writeCode = code
|
writeCode = code
|
||||||
of "read":
|
of "read":
|
||||||
# `client`, the RpcClient
|
# `transport`, the client transport
|
||||||
# `maxRequestLength`, set to defaultMaxRequestLength
|
# `maxRequestLength`, set to defaultMaxRequestLength
|
||||||
# Result of expression is awaited
|
# Note: Result of expression is awaited
|
||||||
readCode = code
|
readCode = code
|
||||||
of "close":
|
of "close":
|
||||||
# `client`, the RpcClient
|
# `transport`, the client transport
|
||||||
# Access to `value`, which contains the data read by `readCode`
|
# `value`, which contains the data read by `readCode`
|
||||||
closeCode = code
|
closeCode = code
|
||||||
of "afterread":
|
of "afterread":
|
||||||
# `client`, the RpcClient
|
# `transport`, the client transport
|
||||||
# Access to `value`, which contains the data read by `readCode`
|
# `value`, which contains the data read by `readCode`
|
||||||
afterReadCode = code
|
afterReadCode = code
|
||||||
else: error("Unknown RPC verb \"" & verb & "\"")
|
else: error("Unknown RPC verb \"" & verb & "\"")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue