1
0
mirror of https://github.com/ShadowKatStudios/OC-Minitel.git synced 2024-11-23 10:38:05 +11:00

Merge pull request #14 from ShadowKatStudios/kos-update

Update the KOS NEO version of Minitel. Closes #14
This commit is contained in:
Izaya 2018-08-11 14:01:42 +10:00 committed by GitHub
commit 2a2e347663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View File

@ -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
@ -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("minitel")(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

View File

@ -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