docs: public synchronized boolean connect ( long timeout ) throws TransportException {
          int st = this.state;
          try {
              switch ( st ) {
              case 0:
                  break;
              case 1:
                  // already connecting
                  this.thread.wait(timeout); /* wait for doConnect */
                  st = this.state;
                  switch ( st ) {
                  case 1: /* doConnect never returned */
                      this.state = 6;
                      cleanupThread(timeout);
                      throw new ConnectionTimeoutException("Connection timeout");
                  case 2:
                      if ( this.te != null ) { /* doConnect throw Exception */
                          this.state = 4; /* error */
                          cleanupThread(timeout);
                          throw this.te;
                      }
                      this.state = 3; /* Success! */
                      return true;
                  }
                  break;
              case 3:
                  return true; // already connected
              case 4:
                  this.state = 6;
                  throw new TransportException("Connection in error", this.te);
              case 5:
              case 6:
                  log.debug("Trying to connect a disconnected transport");
                  return false;
              default:
                  TransportException tex = new TransportException("Invalid state: " + st);
                  throw tex;
              }
  
              if ( log.isDebugEnabled() ) {
                  log.debug("Connecting " + this.name);
              }
  
              this.state = 1;
              this.te = null;
  
              Thread t = new Thread(this, this.name);
              t.setDaemon(true);
              this.thread = t;
  
              synchronized ( this.thread ) {
                  t.start();
                  t.wait(timeout); /* wait for doConnect */
  
                  st = this.state;
                  switch ( st ) {
                  case 1: /* doConnect never returned */
                      this.state = 6;
                      throw new ConnectionTimeoutException("Connection timeout");
                  case 2:
                      if ( this.te != null ) { /* doConnect throw Exception */
                          this.state = 4; /* error */
                          throw this.te;
                      }
                      this.state = 3; /* Success! */
                      return true;
                  case 3:
                      return true;
                  default:
                      return false;
                  }
              }
          }
          catch ( ConnectionTimeoutException e ) {
              cleanupThread(timeout);
              // allow to retry the connection
              this.state = 0;
              throw e;
          }
          catch ( InterruptedException ie ) {
              this.state = 6;
              cleanupThread(timeout);
              throw new TransportException(ie);
          }
          catch ( TransportException e ) {
              cleanupThread(timeout);
              throw e;
          }
          finally {
              /*
               * This guarantees that we leave in a valid state
               */
              st = this.state;
              if ( st != 0 && st != 3 && st != 4 && st != 5 && st != 6 ) {
                  log.error("Invalid state: " + st);
                  this.state = 6;
                  cleanupThread(timeout);
              }
          }
      }