Module: Asciidoctor::Diagram::OfficeServer
- Defined in:
- lib/asciidoctor-diagram-office/extension.rb
Class Method Summary collapse
Class Method Details
.is_port_open? ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/asciidoctor-diagram-office/extension.rb', line 28 def self.is_port_open?() begin Timeout::timeout(10) do begin s = TCPSocket.open('localhost', 2002) s.close return true rescue sleep(1) retry end end rescue Timeout::Error raise 'Failed to start office listener' end end |
.listen ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/asciidoctor-diagram-office/extension.rb', line 12 def self.listen unless defined?(@office_listener) && @office_listener pid = spawn('unoconv --listener > /dev/null 2>&1') thr = Process.detach(pid) is_port_open? at_exit do begin Process.kill(:TERM, pid) rescue => e end end @office_listener = true end end |