Sha256: f20401369f13ca8753cc5a3777f5490bd815fb6bd8fc88829d5477e7ee75f359

Contents?: true

Size: 900 Bytes

Versions: 3

Compression:

Stored size: 900 Bytes

Contents

class Knj::X11VNC
	def initialize(args = {})
		@args = ArrayExt.hash_sym(args)
		@open = true
		
		cmd = "x11vnc -q"
		cmd += " -shared" if @args[:shared] or !@args.has_key?(:shared)
		cmd += " -forever" if @args[:forever] or !@args.has_key?(:forever)
		cmd += " -rfbport #{@args[:port]}" if @args[:port]
		cmd += " -nolookup" if @args[:nolookup] or !@args.has_key?(:nolookup)
		
		print cmd + "\n"
		
		@thread = Knj::Thread.new do
			IO.popen(cmd) do |process|
				@pid = process.pid
				process.sync
				
				while	read = process.read
					break if read.length == 0
					#print read
				end
				
				@open = false
				@pid = nil
				@thread = nil
			end
		end
		
		Kernel.at_exit do
			self.close
		end
	end
	
	def open?
		return @open
	end
	
	def close
		return nil if !@thread
		
		Process.kill("HUP", @pid) if @pid
		@thread.exit if @thread
		@thread = nil
		@open = false
		@pid = nil
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
knjrbfw-0.0.7 lib/knj/x11vnc.rb
knjrbfw-0.0.4 lib/knj/x11vnc.rb
knjrbfw-0.0.3 lib/knj/x11vnc.rb