Class: Steep::Server::CommandSocket::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/server/command_socket.rb

Overview

A connection from a CLI client

#write never raises even if the client is disconnected, because it may be called from the master's write thread, which should keep running for other clients.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ Session

Returns a new instance of Session.



21
22
23
24
25
26
# File 'lib/steep/server/command_socket.rb', line 21

def initialize(socket)
  @socket = socket
  @writer = LSP::Transport::Io::Writer.new(socket)
  @mutex = Mutex.new
  @closed = false
end

Instance Attribute Details

#socketObject (readonly)

Returns the value of attribute socket.



19
20
21
# File 'lib/steep/server/command_socket.rb', line 19

def socket
  @socket
end

Instance Method Details

#closeObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/steep/server/command_socket.rb', line 37

def close
  @mutex.synchronize do
    @closed = true
  end
  begin
    @socket.close
  rescue IOError
    # Already closed
  end
end

#write(message) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/steep/server/command_socket.rb', line 28

def write(message)
  @mutex.synchronize do
    return if @closed
    @writer.write(message)
  end
rescue SystemCallError, IOError
  close()
end