diff options
author | bptato <nincsnevem662@gmail.com> | 2024-09-23 18:07:23 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-09-23 18:08:14 +0200 |
commit | 8e8c7f0911f4a20446a83090d722fecaf203f6f3 (patch) | |
tree | 334a897643051bc6e16d564591ddecba22af565d /src/loader | |
parent | 3b3d517130bb42ec69e6f684510e3b3a3668947c (diff) | |
download | chawan-8e8c7f0911f4a20446a83090d722fecaf203f6f3.tar.gz |
client, forkserver, dynstream: misc refactorings, fixes
* fix broken int conversion in dynstream * fix EPIPE handling in forkserver * merge fdmap and connectingContainers into loader map
Diffstat (limited to 'src/loader')
-rw-r--r-- | src/loader/loader.nim | 2 | ||||
-rw-r--r-- | src/loader/loaderhandle.nim | 3 | ||||
-rw-r--r-- | src/loader/loaderiface.nim | 27 |
3 files changed, 19 insertions, 13 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim index b5a6b3ba..85490b84 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -694,6 +694,8 @@ proc loadCGI(ctx: LoaderContext; client: ClientData; handle: InputHandle; # expects SIGCHLD to be untouched. (e.g. git dies a horrible death with # SIGCHLD as SIG_IGN) signal(SIGCHLD, SIG_DFL) + # let's also reset SIGPIPE, which we ignored in forkserver + signal(SIGPIPE, SIG_DFL) # close the parent handles for i in 0 ..< ctx.handleMap.len: if ctx.handleMap[i] != nil: diff --git a/src/loader/loaderhandle.nim b/src/loader/loaderhandle.nim index 23ddff30..b43149fb 100644 --- a/src/loader/loaderhandle.nim +++ b/src/loader/loaderhandle.nim @@ -42,9 +42,6 @@ type suspended*: bool dead*: bool - SigchldHandle* = ref object of LoaderHandle - notifyMap*: seq[tuple[pid: int; input: InputHandle]] - HandleParserState* = enum hpsBeforeLines, hpsAfterFirstLine, hpsControlDone diff --git a/src/loader/loaderiface.nim b/src/loader/loaderiface.nim index 8cc5ff42..51f02480 100644 --- a/src/loader/loaderiface.nim +++ b/src/loader/loaderiface.nim @@ -25,7 +25,7 @@ type key*: ClientKey process*: int clientPid*: int - map: seq[LoaderData] + map: seq[MapData] mapFds*: int # number of fds in map unregistered*: seq[int] registerFun*: proc(fd: int) @@ -38,9 +38,11 @@ type ConnectDataState = enum cdsBeforeResult, cdsBeforeStatus, cdsBeforeHeaders - LoaderData = ref object of RootObj + MapData* = ref object of RootObj stream*: SocketStream + LoaderData = ref object of MapData + ConnectData* = ref object of LoaderData state: ConnectDataState status: uint16 @@ -123,7 +125,7 @@ proc startRequest*(loader: FileLoader; request: Request; w.swrite(config) return stream -iterator data*(loader: FileLoader): LoaderData {.inline.} = +iterator data*(loader: FileLoader): MapData {.inline.} = for it in loader.map: if it != nil: yield it @@ -133,27 +135,32 @@ iterator ongoing*(loader: FileLoader): OngoingData {.inline.} = if it of OngoingData: yield OngoingData(it) -func fd*(data: LoaderData): int = +func fd*(data: MapData): int = return int(data.stream.fd) -proc put*(loader: FileLoader; data: LoaderData) = +proc put*(loader: FileLoader; data: MapData) = let fd = int(data.stream.fd) if loader.map.len <= fd: loader.map.setLen(fd + 1) assert loader.map[fd] == nil loader.map[fd] = data - inc loader.mapFds + if data of LoaderData: + inc loader.mapFds -proc get*(loader: FileLoader; fd: int): LoaderData = +proc get*(loader: FileLoader; fd: int): MapData = if fd < loader.map.len: return loader.map[fd] return nil -proc unset*(loader: FileLoader; data: LoaderData) = +proc unset*(loader: FileLoader; fd: int) = + if loader.map[fd] != nil and loader.map[fd] of LoaderData: + dec loader.mapFds + loader.map[fd] = nil + +proc unset*(loader: FileLoader; data: MapData) = let fd = int(data.stream.fd) if loader.get(fd) != nil: - dec loader.mapFds - loader.map[fd] = nil + loader.unset(fd) proc fetch0(loader: FileLoader; input: Request; promise: FetchPromise; redirectNum: int) = |