Add a blocking variant of poll() and a helper, wait(), to invoke it

Add a blocking variant of poll() and a helper, wait(), to invoke it.  Replace poll() with wait() where we need the exit status.  Without this, the exit code may not be available and file uploads/downloads will "fail" when they really succeeded (but the return value just didn't propagate yet).