195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
...
246
247
248
249
250
251
252
253
254
255
256
257
258
259
...
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
cmd.cmd = m.cmd.none
end
terra m.emperor:mallack() return lib.mem.heapa(m.ack, self:countpeers()) end
terra m.emperor.methods.decree :: {
&m.emperor, uint64, rawstring, m.cmd.t, uint64, &m.ack
} -> {}
terra m.emperor:decree(
tgtclid: uint64, tgtname: rawstring,
cmd: m.cmd.t, operand: uint64,
result: &m.ack
): {}
if self.client then lib.bail('client attempted to issue IPC decree') end
var dem = m.demand {
cmd = cmd;
operand = operand;
empq = self.msqid; -- register to receive replies
}
var npeers = self:countpeers()
if npeers == 0 then lib.bail('no processes connected to control bus') end
if tgtclid == 0 and tgtname == nil then
lib.dbg('sending to all instances, waiting for edict to become writable')
self.edict:sem(0) -- wait for all locks on edict to resolve
lib.dbg('locking edict')
self.edict:sem(npeers) -- place a read lock for each peer
self.edict.demand = dem
lib.dbg('sending edict')
................................................................................
found = true
tgt = acks(i).cliq
end
end
acks:free()
if not found then
lib.warn('no such instance is currently online and responding to IPC calls')
else
lib.dbg('located instance, sending command')
if mq.msgsnd(tgt, &dem, sizeof(m.demand), 0) == -1 then
lib.bail('could not send command to target process')
end
while true do
var ack: m.ack
................................................................................
lib.dbg('got response, writing out and returning')
@result = ack
break
else lib.warn('got spurious response, ignoring') end
end
end
end
end
terra m.demand:ack(emp: &m.emperor, a: &m.ack)
a.clid = emp.clid
a.cliq = emp.msqid
mq.msgsnd(self.empq, a, sizeof(m.ack), 0)
end
|
|
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
...
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
...
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
cmd.cmd = m.cmd.none
end
terra m.emperor:mallack() return lib.mem.heapa(m.ack, self:countpeers()) end
terra m.emperor.methods.decree :: {
&m.emperor, uint64, rawstring, m.cmd.t, uint64, &m.ack
} -> bool
terra m.emperor:decree(
tgtclid: uint64, tgtname: rawstring,
cmd: m.cmd.t, operand: uint64,
result: &m.ack
): bool
if self.client then lib.bail('client attempted to issue IPC decree') end
var dem = m.demand {
cmd = cmd;
operand = operand;
empq = self.msqid; -- register to receive replies
}
var npeers = self:countpeers()
if npeers == 0 then lib.warn('no processes connected to control bus') return false end
if tgtclid == 0 and tgtname == nil then
lib.dbg('sending to all instances, waiting for edict to become writable')
self.edict:sem(0) -- wait for all locks on edict to resolve
lib.dbg('locking edict')
self.edict:sem(npeers) -- place a read lock for each peer
self.edict.demand = dem
lib.dbg('sending edict')
................................................................................
found = true
tgt = acks(i).cliq
end
end
acks:free()
if not found then
lib.warn('no such instance is currently online and responding to IPC calls')
return false
else
lib.dbg('located instance, sending command')
if mq.msgsnd(tgt, &dem, sizeof(m.demand), 0) == -1 then
lib.bail('could not send command to target process')
end
while true do
var ack: m.ack
................................................................................
lib.dbg('got response, writing out and returning')
@result = ack
break
else lib.warn('got spurious response, ignoring') end
end
end
end
return true
end
terra m.demand:ack(emp: &m.emperor, a: &m.ack)
a.clid = emp.clid
a.cliq = emp.msqid
mq.msgsnd(self.empq, a, sizeof(m.ack), 0)
end
|