public Event doWaitTimeout(long timeout){
  Event e=null;
  long towait=0;
  long endtime=-1;
  boolean usetimeout=(timeout > 0);
  if (usetimeout) {
    endtime=System.nanoTime() + timeout * 1000 * 1000;
  }
  if (networkThread.getDone())   return null;
  while (e == null) {
    if (usetimeout) {
      towait=(endtime - System.nanoTime());
      if (towait <= 0) {
        break;
      }
    }
 else {
      if (timeout == 0) {
        return latestEvents.poll();
      }
    }
    try {
      if (usetimeout) {
        e=latestEvents.poll(towait,TimeUnit.NANOSECONDS);
      }
 else {
        e=latestEvents.take();
      }
    }
 catch (    InterruptedException e1) {
    }
    if (e != null && e.t == EType.KILLSENDER) {
      return null;
    }
    if (networkThread.getDone())     return null;
  }
  return e;
}

public Event doWaitTimeout ( long timeout ) { Event e = null ; long towait = 0 ; long endtime = - 1 ; boolean usetimeout = ( timeout > 0 ) ; if ( usetimeout ) { endtime = System . nanoTime ( ) + timeout * 1000 * 1000 ; } if ( networkThread . getDone ( ) ) return null ; while ( e == null ) { if ( usetimeout ) { towait = ( endtime - System . nanoTime ( ) ) ; if ( towait <= 0 ) { break ; } } else { if ( timeout == 0 ) { return latestEvents . poll ( ) ; } } try { if ( usetimeout ) { e = latestEvents . poll ( towait , TimeUnit . NANOSECONDS ) ; } else { e = latestEvents . take ( ) ; } } catch ( InterruptedException e1 ) { } if ( e != null && e . t == EType . KILLSENDER ) { return null ; } if ( networkThread . getDone ( ) ) return null ; } return e ; }
returns the latest event or null if none received within timeout
