From 27bc1c6fc3c2bbef38c9a1b9144e148e80d0cea3 Mon Sep 17 00:00:00 2001 From: Izaya Date: Fri, 10 Aug 2018 23:06:17 +1000 Subject: [PATCH 1/2] update the KOS NEO versions of the core stuff --- KittenOS/README.md | 7 +++---- KittenOS/libs/net.lua | 11 +++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/KittenOS/README.md b/KittenOS/README.md index ec28a09..7c4c2aa 100644 --- a/KittenOS/README.md +++ b/KittenOS/README.md @@ -24,13 +24,12 @@ Due to how KittenOS's security model works, you have to initialise the library i ``` local minitel = neo.requireAccess("x.svc.minitel","minitel daemon access") -local computer = neo.requireAccess("k.computer","pushing packets") local event = require("event")(neo) -local net = require("net")(event,computer,minitel) +local net = require("net")(event,minitel) ``` -This gives access to the event API, computer API and Minitel service to the net library. +This gives access to the event API and Minitel service to the net library. ### API @@ -42,7 +41,7 @@ Being a direct port of the OpenOS version, the API is the same. *net.usend(host, port, data, pid)* - Sends an unreliable packet to *host* on *port* containing *data*, optionally with the packet ID *pid*. -*net.rsend(host, port, data)* - Sends a reliable packet to *host* on *port* containing *data*. +*net.rsend(host, port, data, block)* - Sends a reliable packet to *host* on *port* containing *data*. If *block* is true, don't wait for a reply. #### Layer 4 diff --git a/KittenOS/libs/net.lua b/KittenOS/libs/net.lua index 619d939..d3183d4 100644 --- a/KittenOS/libs/net.lua +++ b/KittenOS/libs/net.lua @@ -1,6 +1,8 @@ -function returnNet(event,computer,minitel) +function returnNet(event,minitel) local dbug = false +local computer = {} +computer.uptime = os.uptime function print(...) if dbug then @@ -49,9 +51,10 @@ function net.usend(to,port,data,npID) minitel.sendPacket(0,to,port,data,npID) end -function net.rsend(to,port,data) +function net.rsend(to,port,data,block) local pid, stime = net.genPacketID(), computer.uptime() + net.streamdelay - computer.pushSignal("net_send",1,to,port,data,pid) + minitel.sendPacket(1,to,port,data,pid) + if block then return pid end repeat _,rpid = svcpull("net_ack") until rpid == pid or computer.uptime() > stime @@ -117,7 +120,7 @@ local function socket(addr,port,sclose) -- todo, add remote closing of sockets end function net.open(to,port) - net.rsend(to,port,"openstream") + if not net.rsend(to,port,"openstream") then return false, "no ack from host" end local st = computer.uptime()+net.streamdelay local est = false while true do From cd613e857df7cb7ecebbf00529dba79673d75fab Mon Sep 17 00:00:00 2001 From: Izaya Date: Fri, 10 Aug 2018 23:08:10 +1000 Subject: [PATCH 2/2] move net.lua -> minitel.lua --- KittenOS/README.md | 6 +++--- KittenOS/libs/{net.lua => minitel.lua} | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename KittenOS/libs/{net.lua => minitel.lua} (100%) diff --git a/KittenOS/README.md b/KittenOS/README.md index 7c4c2aa..4551c1f 100644 --- a/KittenOS/README.md +++ b/KittenOS/README.md @@ -1,5 +1,5 @@ # Minitel for KittenOS NEO -This package includes the Minitel service, in apps/svc-minitel.lua, and the net library, in libs/net.lua. +This package includes the Minitel service, in apps/svc-minitel.lua, and the net library, in libs/minitel.lua. ## Minitel service @@ -16,7 +16,7 @@ The net library provides an easy way of interacting with the minitel service, an ### Installation -Place libs/net.lua into `NEO Disk/libs/net.lua` +Place libs/minitel.lua into `NEO Disk/libs/minitel.lua` ### Usage @@ -26,7 +26,7 @@ Due to how KittenOS's security model works, you have to initialise the library i local minitel = neo.requireAccess("x.svc.minitel","minitel daemon access") local event = require("event")(neo) -local net = require("net")(event,minitel) +local net = require("minitel")(event,minitel) ``` This gives access to the event API and Minitel service to the net library. diff --git a/KittenOS/libs/net.lua b/KittenOS/libs/minitel.lua similarity index 100% rename from KittenOS/libs/net.lua rename to KittenOS/libs/minitel.lua