Class: PuppetEditorServices::Server::Stdio
- Inherits:
-
Base
- Object
- Base
- PuppetEditorServices::Server::Stdio
show all
- Defined in:
- lib/puppet_editor_services/server/stdio.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#connection_options, #handler_options, #protocol_options, #server_options
Instance Method Summary
collapse
Methods inherited from Base
#log
Constructor Details
#initialize(server_options, protocol_options, handler_options) ⇒ Stdio
Returns a new instance of Stdio.
17
18
19
20
|
# File 'lib/puppet_editor_services/server/stdio.rb', line 17
def initialize(server_options, protocol_options, handler_options)
super(server_options, {}, protocol_options, handler_options)
@exiting = false
end
|
Instance Attribute Details
#exiting ⇒ Object
Returns the value of attribute exiting.
11
12
13
|
# File 'lib/puppet_editor_services/server/stdio.rb', line 11
def exiting
@exiting
end
|
Instance Method Details
#close_connection ⇒ Object
57
58
59
|
# File 'lib/puppet_editor_services/server/stdio.rb', line 57
def close_connection
stop
end
|
#connection(connection_id) ⇒ Object
53
54
55
|
# File 'lib/puppet_editor_services/server/stdio.rb', line 53
def connection(connection_id)
@client_connection unless @client_connection.nil? || @client_connection.id != connection_id
end
|
#name ⇒ Object
13
14
15
|
# File 'lib/puppet_editor_services/server/stdio.rb', line 13
def name
'STDIOSRV'
end
|
#pipe_is_readable?(stream, timeout = 0.5) ⇒ Boolean
61
62
63
64
|
# File 'lib/puppet_editor_services/server/stdio.rb', line 61
def pipe_is_readable?(stream, timeout = 0.5)
read_ready = IO.select([stream], [], [], timeout)
read_ready && stream == read_ready[0][0]
end
|
#read_from_pipe(pipe, timeout = 0.1, &_block) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/puppet_editor_services/server/stdio.rb', line 66
def read_from_pipe(pipe, timeout = 0.1, &_block)
if pipe_is_readable?(pipe, timeout)
l = nil
begin
l = pipe.readpartial(4096)
rescue EOFError
log('Reading from pipe has reached End of File. Exiting STDIO server')
stop
rescue end
yield l unless l.nil?
end
nil
end
|
#start ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/puppet_editor_services/server/stdio.rb', line 22
def start
$VERBOSE = nil
$editor_services_stdout = $stdout $stdout = File.open(File::NULL, 'w')
$editor_services_stdout.sync = true $editor_services_stdout.binmode unless $editor_services_stdout.binmode
@client_connection = PuppetEditorServices::Connection::Stdio.new(self)
log('Starting STDIO server...')
loop do
inbound_data = nil
read_from_pipe($stdin, 2) { |data| inbound_data = data }
break if @exiting
@client_connection.receive_data(inbound_data) unless inbound_data.nil?
break if @exiting
end
log('STDIO server stopped')
end
|
#stop ⇒ Object
48
49
50
51
|
# File 'lib/puppet_editor_services/server/stdio.rb', line 48
def stop
log('Stopping STDIO server...')
@exiting = true
end
|