Changeset f47c5505c30559e53309acf51db69912dec55033

Show
Ignore:
Timestamp:
02/09/12 12:32:29 (3 months ago)
Author:
David C. Lonie <loniedavid@…>
Parents:
0d27765b65ba66dea0413789ed7b3c83d0486c9b
Children:
3b1426dce275c146696e284ef7e2a97e29f16847
git-committer:
David C. Lonie <loniedavid@…> (02/09/12 12:32:29)
Message:

Add a timeout to execute ssh commands.

This seems to be necessary for newer version of libssh.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/globalsearch/sshconnection.cpp

    r2c6c6bd7 rf47c5505  
    8080    } 
    8181 
    82     // Set a three timeout, check every 50 ms for new data. 
     82    // Set a three second timeout, check every 50 ms for new data. 
    8383    int bytesAvail; 
    8484    int timeout = 3000; 
     
    410410    // Read output 
    411411    char buffer[SSH_BUFFER_SIZE]; 
    412     int len; 
    413     while ((len = channel_read(channel, buffer, sizeof(buffer), 0)) > 0) { 
    414       ossout.write(buffer,len); 
     412    int bytesAvail; 
     413    // Wait three seconds for output 
     414    int timeout = 3000; 
     415    do { 
     416      bytesAvail = channel_poll(channel, 0); 
     417      if (bytesAvail == 0) { 
     418        GS_MSLEEP(50); 
     419        timeout -= 50; 
     420      } 
     421    } 
     422    while (timeout > 0 && bytesAvail == 0); 
     423 
     424    if (bytesAvail == SSH_ERROR) { 
     425      qWarning() << "Poll returns error:" << ssh_get_error(m_session); 
     426      channel_close(channel); 
     427      channel_free(channel); 
     428      END; 
     429      return false; 
     430    } 
     431 
     432    while ((bytesAvail = channel_read(channel, buffer, sizeof(buffer), 0)) > 0) { 
     433      ossout.write(buffer,bytesAvail); 
    415434    } 
    416435    stdout_str = QString(ossout.str().c_str()); 
    417     while ((len = channel_read(channel, buffer, sizeof(buffer), 1)) > 0) { 
    418       osserr.write(buffer,len); 
     436    while ((bytesAvail = channel_read(channel, buffer, sizeof(buffer), 1)) > 0) { 
     437      osserr.write(buffer,bytesAvail); 
    419438    } 
    420439    stderr_str = QString(osserr.str().c_str());