@@ -34,9 +34,9 @@ type address =
34
34
35
35
(* console is listening on a Unix domain socket *)
36
36
37
- (* This module enforces connection limits for VM consoles .
38
- Depending on configuration, only one active connection per VM (including Dom0) is allowed,
39
- or that connections are unlimited . *)
37
+ (* This module limits VNC console sessions to at most one per VM/host .
38
+ Depending on configuration, either unlimited connections are allowed,
39
+ or only a single active connection per VM/host is allowed . *)
40
40
module Connection_limit = struct
41
41
module VMSet = Set. Make (String )
42
42
@@ -162,56 +162,55 @@ let ws_proxy __context _ req protocol address s =
162
162
Db.Pool. get_limit_console_sessions ~__context ~self: pool
163
163
in
164
164
(* Disable connection via websocket if the limit is set *)
165
- if limit_console_sessions = true then (
166
- Http_svr. headers s (Http. http_503_service_unavailable () ) ;
167
- ()
168
- ) ;
169
- let addr = match address with Port p -> string_of_int p | Path p -> p in
170
- let protocol =
171
- match protocol with `rfb -> " rfb" | `vt100 -> " vt100" | `rdp -> " rdp"
172
- in
173
- let real_path = Filename. concat " /var/lib/xcp" " websockproxy" in
174
- let sock =
175
- try Some (Fecomms. open_unix_domain_sock_client real_path)
176
- with e ->
177
- debug " Error connecting to wsproxy (%s)" (Printexc. to_string e) ;
178
- Http_svr. headers s (Http. http_501_method_not_implemented () ) ;
179
- None
180
- in
181
- (* Ensure we always close the socket *)
182
- finally
183
- (fun () ->
184
- let upgrade_successful =
185
- Option. map
186
- (fun sock ->
187
- try
188
- let result = (sock, Some (Ws_helpers. upgrade req s)) in
189
- result
190
- with _ -> (sock, None )
191
- )
192
- sock
193
- in
194
- Option. iter
195
- (function
196
- | sock , Some ty ->
197
- let wsprotocol =
198
- match ty with
199
- | Ws_helpers. Hixie76 ->
200
- " hixie76"
201
- | Ws_helpers. Hybi10 ->
202
- " hybi10"
203
- in
204
- let message =
205
- Printf. sprintf " %s:%s:%s" wsprotocol protocol addr
206
- in
207
- let len = String. length message in
208
- ignore (Unixext. send_fd_substring sock message 0 len [] s)
209
- | _ , None ->
210
- Http_svr. headers s (Http. http_501_method_not_implemented () )
211
- )
212
- upgrade_successful
213
- )
214
- (fun () -> Option. iter (fun sock -> Unix. close sock) sock)
165
+ if limit_console_sessions = true then
166
+ Http_svr. headers s (Http. http_503_service_unavailable () )
167
+ else
168
+ let addr = match address with Port p -> string_of_int p | Path p -> p in
169
+ let protocol =
170
+ match protocol with `rfb -> " rfb" | `vt100 -> " vt100" | `rdp -> " rdp"
171
+ in
172
+ let real_path = Filename. concat " /var/lib/xcp" " websockproxy" in
173
+ let sock =
174
+ try Some (Fecomms. open_unix_domain_sock_client real_path)
175
+ with e ->
176
+ debug " Error connecting to wsproxy (%s)" (Printexc. to_string e) ;
177
+ Http_svr. headers s (Http. http_501_method_not_implemented () ) ;
178
+ None
179
+ in
180
+ (* Ensure we always close the socket *)
181
+ finally
182
+ (fun () ->
183
+ let upgrade_successful =
184
+ Option. map
185
+ (fun sock ->
186
+ try
187
+ let result = (sock, Some (Ws_helpers. upgrade req s)) in
188
+ result
189
+ with _ -> (sock, None )
190
+ )
191
+ sock
192
+ in
193
+ Option. iter
194
+ (function
195
+ | sock , Some ty ->
196
+ let wsprotocol =
197
+ match ty with
198
+ | Ws_helpers. Hixie76 ->
199
+ " hixie76"
200
+ | Ws_helpers. Hybi10 ->
201
+ " hybi10"
202
+ in
203
+ let message =
204
+ Printf. sprintf " %s:%s:%s" wsprotocol protocol addr
205
+ in
206
+ let len = String. length message in
207
+ ignore (Unixext. send_fd_substring sock message 0 len [] s)
208
+ | _ , None ->
209
+ Http_svr. headers s (Http. http_501_method_not_implemented () )
210
+ )
211
+ upgrade_successful
212
+ )
213
+ (fun () -> Option. iter (fun sock -> Unix. close sock) sock)
215
214
216
215
let default_console_of_vm ~__context ~self =
217
216
try
0 commit comments