Skip to content

Commit f370b01

Browse files
committed
more testing.
1 parent ac08510 commit f370b01

File tree

1 file changed

+19
-11
lines changed
  • src/main/kotlin/os_package

1 file changed

+19
-11
lines changed

src/main/kotlin/os_package/Ipc.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
@file:Suppress("UnnecessaryVariable")
2+
13
package os_package
24

35
import environment.reflection.KProcess
46
import internals.Vm
57
import java.util.*
8+
import kotlin.system.exitProcess
69

710

811
/**
@@ -32,15 +35,15 @@ class Ipc {
3235
var idCount = 0
3336
val mailBoxes = mutableMapOf<Int, Stack<Long>>()
3437

35-
fun preposeLink(requester: KProcess, acceptent: KProcess): Int? {
36-
if (requester !in pending) {
37-
pending[requester] = mutableSetOf()
38+
fun preposeLink(requestant: KProcess, acceptent: KProcess): Int? {
39+
if (requestant !in pending) {
40+
pending[requestant] = mutableSetOf()
3841
}
39-
pending[requester]!!.add(acceptent)
40-
if (pending[acceptent]?.contains(requester) == true) {
42+
pending[requestant]!!.add(acceptent)
43+
if (pending[acceptent]?.contains(requestant) == true) {
4144
idCount++
4245
mailBoxes[idCount] = Stack()
43-
requester.ipcPermissions.add(idCount)
46+
requestant.ipcPermissions.add(idCount)
4447
acceptent.ipcPermissions.add(idCount)
4548

4649
return idCount
@@ -68,17 +71,22 @@ class Ipc {
6871
}
6972

7073

71-
fun main() {
74+
fun main() { // TODO add a way to lookup PIDS cause so far processes do not know how to see other ones
7275
val p1 = KProcess(vm = Vm())
7376
val p2 = KProcess(vm = Vm())
7477
val p3 = KProcess(vm = Vm())
7578
val ipc = Ipc.MessagePassing()
7679

77-
ipc.preposeLink(p1, p2)
78-
val o = ipc.preposeLink(p1, p1)!!
80+
val requestant = p1
81+
val acceptent = p2
7982

80-
ipc.send(p1, 29, 24)
81-
println(ipc.receive(p1, 29))
83+
ipc.preposeLink(requestant, acceptent)
84+
val o = ipc.preposeLink(acceptent, requestant)
85+
println("[Link] [${requestant.id},${acceptent.id}]: ${if (o != null) " success " else " failed"} ")
86+
if (o == null) exitProcess(1)
8287

88+
println("[Send] [${requestant.id},${acceptent.id}]: ${if (ipc.send(p1, o, 24)) " success " else " failed"} ")
89+
val x = ipc.receive(p1, o)
90+
println("[Receive] [${requestant.id},${acceptent.id}]: ${if (x == null) "failed" else "$x"}")
8391

8492
}

0 commit comments

Comments
 (0)