From 15e6a2318c35adb7b8b0abe1b5827398068b2c52 Mon Sep 17 00:00:00 2001 From: bptato Date: Thu, 15 Dec 2022 10:28:15 +0100 Subject: 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. --- src/io/loader.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/io') 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) -- cgit 1.4.1-2-gfad0