diff options
Diffstat (limited to 'src/local')
-rw-r--r-- | src/local/client.nim | 45 | ||||
-rw-r--r-- | src/local/container.nim | 1 | ||||
-rw-r--r-- | src/local/pager.nim | 2 |
3 files changed, 29 insertions, 19 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) diff --git a/src/local/container.nim b/src/local/container.nim index 9ad69cc4..d6db15c0 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -20,7 +20,6 @@ import loader/request import local/select import server/buffer import server/forkserver -import types/buffersource import types/cell import types/color import types/cookie diff --git a/src/local/pager.nim b/src/local/pager.nim index 3cdd0226..a6c6c9ad 100644 --- a/src/local/pager.nim +++ b/src/local/pager.nim @@ -31,8 +31,8 @@ import loader/loader import loader/request import local/container import local/select +import server/buffer import server/forkserver -import types/buffersource import types/cell import types/color import types/cookie |