Megatest

Diff
Login

Differences From Artifact [3830009eae]:

To Artifact [4ef1a2fa98]:


547
548
549
550
551
552
553

554

555
556
557
558
559
560
561
562
563
564
565
566
567
568
569

570
571
572
573
574
575
576
547
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562
563
564
565
566
567



568
569
570
571
572
573
574
575







+
-
+












-
-
-
+







;;  if there is already a serv-listener return the udata
;;
(define (start-server-find-port udata-in #!optional (port 4242)(tries 0))
  (let ((udata (or udata-in (make-udat))))
    (if (udat-serv-listener udata) ;; TODO - add check that the listener is alive and ready?
	udata
	(let ((res (connect-server udata port)))
	  (if res
	  (or res
	      res
	      (begin
		;; (print "Could not connect to " port)
		(if (and (< port  65535)
			 (< tries 10000)) ;; make this number bigger when things are working
		    (start-server-find-port udata (+ port 1)(+ tries 1))
		    #f)))))))

(define (connect-server udata port)
  ;; (tcp-listener-socket LISTENER)(socket-name so)
  ;; sockaddr-address, sockaddr-port, sockaddr->string
  (let* ((tlsn (handle-exceptions
		   exn
		   (begin
		     ;; (print "unable to connect to " port ", exn=" exn)
		     #f)
		   #f ;; NB// NEED BETTER HANDLING HERE ASAP
		 (tcp-listen port 1000 #f))) ;; (tcp-listen TCPPORT [BACKLOG [HOST]])
	 (addr (get-my-best-address))) ;; (hostinfo-addresses (host-information (current-hostname)))
    (if tlsn
	(begin
	  (udat-my-address-set!    udata addr)
	  (udat-my-port-set!       udata port)
	  (udat-my-hostname-set!   udata (get-host-name))