lib/netsoul/client.rb in netsoul-1.9.3 vs lib/netsoul/client.rb in netsoul-2.0.0
- old
+ new
@@ -13,35 +13,35 @@
@config = Config.new(opts)
@started = false
end
def auth_ag
- sock_send(Message.auth_ag)
- fail Netsoul::IdentificationError, 'Identification failed.'.freeze unless sock_get.split(' ')[1] == '002'.freeze
+ send(Message.auth_ag)
+ fail Netsoul::IdentificationError, 'Identification failed.'.freeze unless get.split(' ')[1] == '002'.freeze
end
private :auth_ag
def auth_method
if @config.auth_method == :krb5
- sock_send(Message.kerberos_auth(@config))
+ send(Message.kerberos_auth(@config))
else
- sock_send(Message.standard_auth(@config))
+ send(Message.standard_auth(@config))
end
- fail Netsoul::AuthenticationError, 'Authentication failed. See your config file or environment variables'.freeze unless sock_get.split(' ')[1] == '002'
+ fail Netsoul::AuthenticationError, 'Authentication failed. See your config file or environment variables'.freeze unless get.split(' ')[1] == '002'
end
private :auth_method
def auth_status
- sock_send(Message.attach)
- sock_send(Message.user_state(@config.state, Time.now.to_i))
+ send(Message.attach)
+ send(Message.user_state(@config.state, Time.now.to_i))
end
private :auth_status
def connect
- @sock = TCPSocket.new(@config.server_host, @config.server_port)
- fail Netsoul::SocketError, 'Could not open a socket. Connection is unavailable.'.freeze unless @sock
- _cmd, _socket_num, md5_hash, client_ip, client_port, _server_timestamp = sock_get.split
+ @socket = TCPSocket.new(@config.server_host, @config.server_port)
+ fail Netsoul::SocketError, 'Could not open a socket. Connection is unavailable.'.freeze unless @socket
+ _cmd, _socket_num, md5_hash, client_ip, client_port, _server_timestamp = get.split
@config.build_user_connection_info md5_hash: md5_hash, client_ip: client_ip, client_port: client_port
auth_ag
auth_method
@@ -49,32 +49,32 @@
@started = true
end
def disconnect
- sock_send(Message.ns_exit)
+ send(Message.ns_exit)
ensure
- sock_close
+ close
end
- def sock_send(str)
- _, sock = IO.select(nil, [@sock], nil, SOCKET_WRITE_TIMEOUT)
+ def send(str)
+ _, sock = IO.select(nil, [@socket], nil, SOCKET_WRITE_TIMEOUT)
fail Netsoul::SocketError, 'Timeout or fail on write socket' if sock.nil? || sock.empty?
sock.first.puts str
log :info, "[send] #{str.chomp}"
end
- def sock_get
- sock, = IO.select([@sock], nil, nil, SOCKET_READ_TIMEOUT)
+ def get
+ sock, = IO.select([@socket], nil, nil, SOCKET_READ_TIMEOUT)
fail Netsoul::SocketError, 'Timeout or fail on read socket' if sock.nil? || sock.empty?
res = sock.first.gets
log :info, "[get ] #{res.chomp}" if res
res || ''
end
- def sock_close
+ def close
@started = false
- @sock.close
+ @socket.close
rescue
nil
end
end
end