about summary refs log tree commit diff stats
path: root/src/local/client.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-09-22 12:30:11 +0200
committerbptato <nincsnevem662@gmail.com>2024-09-22 12:30:27 +0200
commit9386feca5e39b89676dd410f6331553c37434239 (patch)
tree281f2333f7977cd6ffb58ac2346ecfe8b8f37665 /src/local/client.nim
parent9c544ac50b271eef7533663082beb69ff65f6bea (diff)
downloadchawan-9386feca5e39b89676dd410f6331553c37434239.tar.gz
client: seqify fdmap
Diffstat (limited to 'src/local/client.nim')
-rw-r--r--src/local/client.nim10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/local/client.nim b/src/local/client.nim
index bf276aa3..c8bf9b24 100644
--- a/src/local/client.nim
+++ b/src/local/client.nim
@@ -57,7 +57,7 @@ type
     alive: bool
     config {.jsget.}: Config
     consoleWrapper: ConsoleWrapper
-    fdmap: Table[int, Container]
+    fdmap: seq[Container]
     feednext: bool
     pager {.jsget.}: Pager
     pressed: tuple[col: int; row: int]
@@ -380,7 +380,7 @@ proc acceptBuffers(client: Client) =
       let stream = container.iface.stream
       let fd = int(stream.source.fd)
       client.selector.unregister(fd)
-      client.fdmap.del(fd)
+      client.fdmap[fd] = nil
       stream.sclose()
     elif container.process != -1: # connecting to buffer process
       let i = pager.findProcMapItem(container.process)
@@ -441,6 +441,8 @@ proc acceptBuffers(client: Client) =
       loader.shareCachedItem(container.cacheId, loader.clientPid)
       container.setCloneStream(stream, registerFun)
     let fd = int(stream.fd)
+    if client.fdmap.len <= fd:
+      client.fdmap.setLen(fd + 1)
     client.fdmap[fd] = container
     client.selector.registerHandle(fd, {Read}, 0)
     pager.handleEvents(container)
@@ -524,14 +526,14 @@ proc handleError(client: Client; fd: int) =
   elif (let i = client.pager.findConnectingContainer(fd); i != -1):
     client.pager.handleConnectingContainerError(i)
   else:
-    if fd in client.fdmap:
+    if fd < client.fdmap.len and client.fdmap[fd] != nil:
       let container = client.fdmap[fd]
       if container != client.consoleWrapper.container:
         client.console.error("Error in buffer", $container.url)
       else:
         client.consoleWrapper.container = nil
       client.selector.unregister(fd)
-      client.fdmap.del(fd)
+      client.fdmap[fd] = nil
     if client.consoleWrapper.container != nil:
       client.showConsole()
     else: