diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-14 15:44:32 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-14 15:44:32 +0100 |
commit | 547a492611a8d6831d88b697e2785658a9c06177 (patch) | |
tree | c5fa38683acc29e4d70396d5f4d96346f453b469 /src/local/client.nim | |
parent | c2fbe0993228b2b62f8a916bae5271097254ce5c (diff) | |
download | chawan-547a492611a8d6831d88b697e2785658a9c06177.tar.gz |
Various refactorings & fixes
* disallow Stream interface usage on non-blocking PosixStreams * do not read estream of forkserver byte-by-byte (it's slow) * do not call writeData with a zero len in formdata * do not quote numbers in mailcap quoteFile * remove some unused stuff
Diffstat (limited to 'src/local/client.nim')
-rw-r--r-- | src/local/client.nim | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/local/client.nim b/src/local/client.nim index 20e1a6ef..2912b7ef 100644 --- a/src/local/client.nim +++ b/src/local/client.nim @@ -314,10 +314,10 @@ proc consoleBuffer(client: Client): Container {.jsfget.} = proc acceptBuffers(client: Client) = while client.pager.unreg.len > 0: let (pid, stream) = client.pager.unreg.pop() - let fd = stream.source.getFd() - if int(fd) in client.fdmap: + let fd = int(stream.fd) + if fd in client.fdmap: client.selector.unregister(fd) - client.fdmap.del(int(fd)) + client.fdmap.del(fd) else: client.pager.procmap.del(pid) stream.close() @@ -328,8 +328,8 @@ proc acceptBuffers(client: Client) = client.pager.alert("Error: failed to set up buffer") continue container.setStream(stream) - let fd = stream.source.getFd() - client.fdmap[int(fd)] = container + let fd = int(stream.fd) + client.fdmap[fd] = container client.selector.registerHandle(fd, {Read}, 0) client.pager.handleEvents(container) accepted.add(pid) @@ -344,22 +344,33 @@ proc handleRead(client: Client, fd: int) = client.handlePagerEvents() ) elif fd == client.forkserver.estream.fd: - var nl = false + const BufferSize = 4096 const prefix = "STDERR: " - var s = prefix + var buffer {.noinit.}: array[BufferSize, char] + let estream = client.forkserver.estream + var hadlf = true while true: try: - let c = client.forkserver.estream.readChar() - if nl and s.len > prefix.len: - client.console.err.write(s) - s = prefix - nl = false - s &= c - nl = c == '\n' - except IOError: + let n = estream.recvData(addr buffer[0], BufferSize) + var i = 0 + while i < n: + var j = n + var found = false + for k in i ..< n: + if buffer[k] == '\n': + j = k + 1 + found = true + break + if hadlf: + client.console.err.write(prefix) + if j - i > 0: + client.console.err.writeData(addr buffer[i], j - i) + i = j + hadlf = found + except ErrorAgain: break - if s.len > prefix.len: - client.console.err.write(s) + if not hadlf: + client.console.err.write('\n') client.console.err.flush() elif fd in client.loader.connecting: client.loader.onConnected(fd) |