Class: SubSpawn::POSIX::SigSet

Inherits:
Object
  • Object
show all
Defined in:
lib/subspawn/posix/signals.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base = :empty) ⇒ SigSet

Returns a new instance of SigSet.

Raises:

  • (ArgumentError)


2
3
4
5
6
7
8
9
# File 'lib/subspawn/posix/signals.rb', line 2

def initialize(base=:empty)
	base = base.to_sym
	raise ArgumentError, "SigSet only accepts :full, :empty, or :current" unless %i{full empty current}.include? base
	# TODO: warn about current?
	@base = base
	@ops = []
	@ptr = nil
end

Class Method Details

.currentObject



16
17
18
# File 'lib/subspawn/posix/signals.rb', line 16

def self.current
	self.new(:current)
end

.emptyObject



10
11
12
# File 'lib/subspawn/posix/signals.rb', line 10

def self.empty
	self.new(:empty)
end

.fullObject



13
14
15
# File 'lib/subspawn/posix/signals.rb', line 13

def self.full
	self.new(:full)
end

Instance Method Details

#exclude(*signals) ⇒ Object Also known as: -, add



25
26
27
28
29
30
# File 'lib/subspawn/posix/signals.rb', line 25

def exclude(*signals)
	clean_signals(signals).each do |sig|
		@ops << [:rm, sig]
	end
	self
end

#include(*signals) ⇒ Object Also known as: +, del, delete



19
20
21
22
23
24
# File 'lib/subspawn/posix/signals.rb', line 19

def include(*signals)
	clean_signals(signals).each do |sig|
		@ops << [:add, sig]
	end
	self
end

#to_ptr(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/subspawn/posix/signals.rb', line 37

def to_ptr(&block)
	if @ptr.nil?
		# sigset_t is largest on linux, at 128 bytes, so always allocate that much
		if block_given?
			ret = nil
			FFI::MemoryPointer.new(:uint8, 128) {|ptr| alloc_internal(ptr); ret = block.call(ptr)}
			ret
		else
			FFI::MemoryPointer.new(:uint8, 128).tap {|ptr| @ptr = ptr; alloc_internal(ptr)}
		end
	else
		if block_given?
			block.call(@ptr)
		else
			@ptr
		end
	end
end