diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-15 10:28:15 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-15 10:28:15 +0100 |
commit | 15e6a2318c35adb7b8b0abe1b5827398068b2c52 (patch) | |
tree | 7b41aec0edbf9a144180bee78977673a229d3238 /src/io | |
parent | 811484c125162fa30aec11288e1ef3101382de88 (diff) | |
download | chawan-15e6a2318c35adb7b8b0abe1b5827398068b2c52.tar.gz |
Make load() slightly less dumb
This gets rid of the inefficient timeout thing. Still, the ideal solution would be to move the timeout into the container; TODO.
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/loader.nim | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/io/loader.nim b/src/io/loader.nim index a1d449c7..775cb78f 100644 --- a/src/io/loader.nim +++ b/src/io/loader.nim @@ -11,6 +11,7 @@ # # The body is passed to the stream as-is, so effectively nothing can follow it. +import nativesockets import options import streams import tables @@ -137,9 +138,10 @@ proc runFileLoader*(fd: cint, config: LoaderConfig) = ssock.close() quit(0) -proc doRequest*(loader: FileLoader, request: Request): Response = +#TODO async requests... +proc doRequest*(loader: FileLoader, request: Request, blocking = true): Response = new(result) - let stream = connectSocketStream(loader.process, false, false) + let stream = connectSocketStream(loader.process, false, blocking = true) stream.swrite(LOAD) stream.swrite(request) stream.flush() @@ -156,6 +158,8 @@ proc doRequest*(loader: FileLoader, request: Request): Response = result.redirect = parseUrl(location, some(request.url)) # Only a stream of the response body may arrive after this point. result.body = stream + if not blocking: + stream.source.getFd().setBlocking(blocking) proc quit*(loader: FileLoader) = let stream = connectSocketStream(loader.process) |