|
| 1 | +## The IPC "master". This is just an abstraction over the IPC server. |
| 2 | +## It essentially allows you to do anything with your own group of processes (renderer, JS runtime, CSS/HTML parsers, etc.) |
| 3 | +## This includes summoning them, telling them to do a task, telling them to exit, et cetera. |
| 4 | + |
1 | 5 | import |
2 | 6 | std/ |
3 | 7 | [os, logging, osproc, strutils, options, base64, net, sets, terminal, posix, tables] |
@@ -25,6 +29,8 @@ type MasterProcess* = ref object |
25 | 29 | server*: IPCServer |
26 | 30 | urls*: Table[uint, URL] |
27 | 31 |
|
| 32 | + alive*: bool = true |
| 33 | + |
28 | 34 | proc initialize*(master: MasterProcess) {.inline.} = |
29 | 35 | master.server.add(FerusGroup()) |
30 | 36 | # TODO: multi-tab support, although we could just keep adding more FerusGroup(s) and it should *theoretically* scale |
@@ -515,8 +521,20 @@ proc packetHandler*( |
515 | 521 | master.server.reportBadMessage( |
516 | 522 | process, "Non-renderer process sent `feRendererExit` opcode", High |
517 | 523 | ) |
| 524 | + return |
| 525 | + |
| 526 | + info "The renderer has shut down. Beginning cleanup." |
| 527 | + |
| 528 | + # Here, we start sending "goodbye" packets to all processes. |
| 529 | + # We're essentially telling them, "Hey, start cleaning up and die." |
| 530 | + for i, group in master.server.groups: |
| 531 | + for process in group: |
| 532 | + debug "Telling PID " & $process.pid & " (group " & $i & "'s " & $process.kind & |
| 533 | + ") to exit" |
| 534 | + master.server.send(process.socket, GoodbyePacket()) |
518 | 535 |
|
519 | | - debug "The renderer has shut down." |
| 536 | + info "Cleanup completed. Adios!" |
| 537 | + master.alive = false |
520 | 538 | else: |
521 | 539 | warn "Unhandled IPC protocol magic: " & $kind |
522 | 540 | return |
|
0 commit comments