Class: ServerEngine::SocketManager::Server
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#share_sockets_with_another_server
Constructor Details
#initialize(path, start: true) ⇒ Server
Returns a new instance of Server.
106
107
108
109
110
111
|
# File 'lib/serverengine/socket_manager.rb', line 106
def initialize(path, start: true)
@tcp_sockets = {}
@udp_sockets = {}
@mutex = Mutex.new
@path = start ? start_server(path) : path
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
113
114
115
|
# File 'lib/serverengine/socket_manager.rb', line 113
def path
@path
end
|
#tcp_sockets ⇒ Object
114
115
116
|
# File 'lib/serverengine/socket_manager.rb', line 114
def tcp_sockets
@tcp_sockets
end
|
#udp_sockets ⇒ Object
114
115
116
|
# File 'lib/serverengine/socket_manager.rb', line 114
def udp_sockets
@udp_sockets
end
|
Class Method Details
.generate_path ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/serverengine/socket_manager.rb', line 75
def self.generate_path
if ServerEngine.windows?
port = ENV['SERVERENGINE_SOCKETMANAGER_PORT']
return port.to_i if port
excluded_port_ranges = get_excluded_port_ranges
get_dynamic_port_range
.reject { |port| excluded_port_ranges.any? { |range| range.cover?(port) } }
.find { |port| `netstat -na | findstr "#{port}"`.length == 0 }
else
base_dir = (ENV['SERVERENGINE_SOCKETMANAGER_SOCK_DIR'] || '/tmp')
File.join(base_dir, 'SERVERENGINE_SOCKETMANAGER_' + Time.now.utc.iso8601 + '_' + Process.pid.to_s)
end
end
|
.open(path = nil) ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'lib/serverengine/socket_manager.rb', line 90
def self.open(path = nil)
return new(path) unless path.nil?
if ServerEngine.windows?
new(0)
else
new(self.generate_path)
end
end
|
.share_sockets_with_another_server(path) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/serverengine/socket_manager.rb', line 99
def self.share_sockets_with_another_server(path)
raise NotImplementedError, "Not supported on Windows." if ServerEngine.windows?
server = new(path, start: false)
server.share_sockets_with_another_server
server
end
|
Instance Method Details
#close ⇒ Object
125
126
127
128
|
# File 'lib/serverengine/socket_manager.rb', line 125
def close
stop_server
nil
end
|
#new_client ⇒ Object
116
117
118
|
# File 'lib/serverengine/socket_manager.rb', line 116
def new_client
Client.new(@path)
end
|
#start ⇒ Object
120
121
122
123
|
# File 'lib/serverengine/socket_manager.rb', line 120
def start
start_server(path)
nil
end
|