Module: UnixSocks::ServerShared

Included in:
DomainSocketServer, TCPSocketServer
Defined in:
lib/unix_socks/server_shared.rb

Overview

Shared server functionality for UnixSocks implementations

This module provides common methods for transmitting messages and parsing JSON responses that are used by both Unix domain socket and TCP socket server implementations.

Instance Method Summary collapse

Instance Method Details

#to_uriURI

Converts the server’s URL representation into a URI object.

This method takes the URL string returned by #to_url and parses it into a URI object for convenient access to the server’s address components.

Returns:

  • (URI)

    A URI object representing the server’s address configuration.



24
25
26
# File 'lib/unix_socks/server_shared.rb', line 24

def to_uri
  URI.parse(to_url)
end

#transmit_with_response(message, close: true) ⇒ Hash?

Sends a message and returns the parsed JSON response.

Parameters:

  • message (Object)

    The message to be sent as JSON.

Returns:

  • (Hash, nil)

    The parsed JSON response or nil if parsing fails.



11
12
13
14
15
16
# File 'lib/unix_socks/server_shared.rb', line 11

def transmit_with_response(message, close: true)
  socket = transmit(message, close: false)
  parse_json_message(socket.gets, socket)
ensure
  close and socket&.close
end