diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-10 20:20:34 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-10 20:25:29 +0100 |
commit | d8c4b0979c6d1ff9f6edea650e3aeb1ca1e4a104 (patch) | |
tree | e585452d7e855f7e66d69dd37ffe1f7758fe9e7f /src/io | |
parent | 7cb7ea1db2b4566fde492c1e0cc4c42f245dea63 (diff) | |
download | chawan-d8c4b0979c6d1ff9f6edea650e3aeb1ca1e4a104.tar.gz |
loader: fixes & cleanup
* LoaderHandle.fd is no more, we now check ostream's fd * setBlocking converted to a PosixStream method * SocketStream now sets fd variable * handle sostream/fd redirection properly * fix suspend/resume This fixes non-HTML resource loading, mostly. However, tee is still broken :/
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/posixstream.nim | 9 | ||||
-rw-r--r-- | src/io/socketstream.nim | 6 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/io/posixstream.nim b/src/io/posixstream.nim index 66b2d0d9..0cc6ff73 100644 --- a/src/io/posixstream.nim +++ b/src/io/posixstream.nim @@ -4,7 +4,7 @@ import std/streams type PosixStream* = ref object of Stream - fd*: FileHandle + fd*: cint isend*: bool ErrorAgain* = object of IOError @@ -79,6 +79,13 @@ method sendData*(s: PosixStream, buffer: pointer, len: int): int {.base.} = raisePosixIOError() return n +method setBlocking*(s: PosixStream, blocking: bool) {.base.} = + let ofl = fcntl(s.fd, F_GETFL, 0) + if blocking: + discard fcntl(s.fd, F_SETFL, ofl and not O_NONBLOCK) + else: + discard fcntl(s.fd, F_SETFL, ofl or O_NONBLOCK) + proc psWriteData(s: Stream, buffer: pointer, len: int) = #TODO use sendData instead let s = cast[PosixStream](s) diff --git a/src/io/socketstream.nim b/src/io/socketstream.nim index 38c43a84..dd391f21 100644 --- a/src/io/socketstream.nim +++ b/src/io/socketstream.nim @@ -105,8 +105,8 @@ func newSocketStream*(): SocketStream = closeImpl: sockClose ) -proc setBlocking*(ss: SocketStream, blocking: bool) = - ss.source.getFd().setBlocking(blocking) +method setBlocking*(s: SocketStream, blocking: bool) = + s.source.getFd().setBlocking(blocking) # see serversocket.nim for an explanation {.compile: "connect_unix.c".} @@ -125,6 +125,7 @@ proc connectSocketStream*(path: string, buffered = true, blocking = true): cint(path.len)) != 0: raiseOSError(osLastError()) result.source = sock + result.fd = cint(sock.getFd()) proc connectSocketStream*(pid: Pid, buffered = true, blocking = true): SocketStream = @@ -141,3 +142,4 @@ proc acceptSocketStream*(ssock: ServerSocket, blocking = true): SocketStream = result.source = sock if not blocking: sock.getFd().setBlocking(false) + result.fd = cint(sock.getFd()) |