Create dedicated class for messages.
This commit is contained in:
parent
ae67dc6889
commit
13922373d6
|
@ -1,6 +1,12 @@
|
|||
require 'mach/port'
|
||||
require 'mach/semaphore'
|
||||
require 'mach/task'
|
||||
require 'mach/functions'
|
||||
|
||||
module Mach
|
||||
# @return [Port] the original bootstrap port; different from that
|
||||
# affected by {get,set}_special_port
|
||||
def self.bootstrap_port
|
||||
@bootstrap_port ||= Mach::Port.new(:port => Mach::Functions::bootstrap_port)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,23 @@ module Mach
|
|||
class Port
|
||||
include Functions
|
||||
|
||||
class SendRightMsg < FFI::Struct
|
||||
include Functions
|
||||
|
||||
layout(:header, MsgHeader,
|
||||
:body, MsgBody,
|
||||
:port, MsgPortDescriptor)
|
||||
end
|
||||
|
||||
class ReceiveRightMsg < FFI::Struct
|
||||
include Functions
|
||||
|
||||
layout(:header, MsgHeader,
|
||||
:body, MsgBody,
|
||||
:port, MsgPortDescriptor,
|
||||
:trailer, MsgTrailer)
|
||||
end
|
||||
|
||||
attr_reader :ipc_space, :port
|
||||
|
||||
# @param [Hash] opts
|
||||
|
@ -21,7 +38,6 @@ module Mach
|
|||
# is wrapped in a new Port object; otherwise a new port is
|
||||
# allocated according to the other options
|
||||
def initialize(opts = {})
|
||||
if opts.kind_of? Hash
|
||||
@ipc_space = opts[:ipc_space] || mach_task_self
|
||||
right = opts[:right] || :receive
|
||||
|
||||
|
@ -33,7 +49,6 @@ module Mach
|
|||
mem.get_uint(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# With this alias, we can call #to_i on either bare Integer ports
|
||||
# or wrapped Port objects when passing the arg to a foreign
|
||||
|
@ -81,17 +96,14 @@ module Mach
|
|||
# must already have the requisite rights allowing it to send
|
||||
# +right+.
|
||||
def send_right(right, remote_port)
|
||||
msg = FFI::Struct.new(nil,
|
||||
:header, MsgHeader,
|
||||
:body, MsgBody,
|
||||
:port, MsgPortDescriptor)
|
||||
msg = SendRightMsg.new
|
||||
|
||||
msg[:header].tap do |h|
|
||||
h[:remote_port] = remote_port.to_i
|
||||
h[:local_port] = MACH_PORT_NULL
|
||||
h[:bits] =
|
||||
(MachMsgType[right] | (0 << 8)) | 0x80000000 # MACH_MSGH_BITS_COMPLEX
|
||||
h[:size] = msg.size
|
||||
h[:size] = 40 # msg.size
|
||||
end
|
||||
|
||||
msg[:body][:descriptor_count] = 1
|
||||
|
@ -115,11 +127,7 @@ module Mach
|
|||
# Create a new Port by receiving a port right message on this
|
||||
# port.
|
||||
def receive_right
|
||||
msg = FFI::Struct.new(nil,
|
||||
:header, MsgHeader,
|
||||
:body, MsgBody,
|
||||
:port, MsgPortDescriptor,
|
||||
:trailer, MsgTrailer)
|
||||
msg = ReceiveRightMsg.new
|
||||
|
||||
mach_msg(msg,
|
||||
2, # MACH_RCV_MSG,
|
||||
|
|
Loading…
Reference in New Issue