Revision 7eb27319

b/vncauthproxy/proxy.py
24 24
DEFAULT_LOG_FILE = "/var/log/vncauthproxy/vncauthproxy.log"
25 25
DEFAULT_PID_FILE = "/var/run/vncauthproxy/vncauthproxy.pid"
26 26
DEFAULT_CONNECT_TIMEOUT = 30
27
DEFAULT_CONNECT_RETRIES = 3
28
DEFAULT_RETRY_WAIT = 0.1
27 29
# Default values per http://www.iana.org/assignments/port-numbers
28 30
DEFAULT_MIN_PORT = 49152 
29 31
DEFAULT_MAX_PORT = 65535
......
315 317
    
316 318
    return sockets
317 319

  
318
def perform_server_handshake(daddr, dport):
320
def perform_server_handshake(daddr, dport, tries, retry_wait):
319 321
    """
320 322
    Initiate a connection with the backend server and perform basic
321 323
    RFB 3.8 handshake with it.
......
324 326

  
325 327
    """
326 328
    server = None
327
    # Try to connect to the server
328
    tries = 50
329 329

  
330 330
    while tries:
331 331
        tries -= 1
......
354 354
            break
355 355

  
356 356
        # Wait and retry
357
        sleep(0.2)
357
        sleep(retry_wait)
358 358

  
359 359
    if server is None:
360 360
        raise Exception("Failed to connect to server")
......
411 411
    parser.add_option("-t", "--connect-timeout", dest="connect_timeout",
412 412
                      default=DEFAULT_CONNECT_TIMEOUT, type="int", metavar="SECONDS",
413 413
                      help="How long to listen for clients to forward")
414
    parser.add_option("-r", "--connect-retries", dest="connect_retries",
415
                      default=DEFAULT_CONNECT_RETRIES, type="int",
416
                      metavar="RETRIES",
417
                      help="How many times to try to connect to the server")
418
    parser.add_option("-w", "--retry-wait", dest="retry_wait",
419
                      default=DEFAULT_RETRY_WAIT, type="float", metavar="SECONDS",
420
                      help="How long to wait between retrying to connect to the server")
414 421
    parser.add_option("-p", "--min-port", dest="min_port",
415 422
                      default=DEFAULT_MIN_PORT, type="int", metavar="MIN_PORT",
416 423
                      help="The minimum port to use for automatically-allocated ephemeral ports")
......
546 553
                    pool = None
547 554

  
548 555
                listeners = get_listening_sockets(sport)
549
                server = perform_server_handshake(daddr, dport)
556
                server = perform_server_handshake(daddr, dport,
557
                    opts.connect_retries, opts.retry_wait)
550 558

  
551 559
                VncAuthProxy.spawn(logger, listeners, pool, daddr, dport,
552 560
                    server, password, opts.connect_timeout)

Also available in: Unified diff