util/chpty.cc
/// Write string to the remote program, but do not block for more than
/// m_wtimeout. Multiple calls to write will automatically be issued
/// for an especially long string.  Returns the number of bytes
/// written (0 if timeout).  Any error on write, or a closed pty will
/// throw an exception.
///
/// * May throw Chpty_write_exception
///
Write string to the remote program, but do not block for more than
m_wtimeout. Multiple calls to write will automatically be issued
for an especially long string.  Returns the number of bytes
written (0 if timeout).  Any error on write, or a closed pty will
throw an exception.


Write string to the remote program but do not block for more than m_wtimeout . Multiple calls to write will automatically be issued for an especially long string . Returns the number of bytes written ( 0 if timeout ) . Any error on write or a closed pty will throw an exception .
ssize_t Pty_controller::write_nb( const std::string &str )
{
    if (non_fd == m_cfd) {
        throw Chpty_write_exception();
    }
    ssize_t nb = static_cast<ssize_t>(str.size());
    ssize_t nwritten = 0;
    const char *s = str.c_str();
    while (nwritten < nb) {
        if (0 == can_write()) break;
        ssize_t rc = write( m_cfd, s, nb );
        if (libc_err == rc) {
            throw Chpty_write_exception();
        }
        if (0 == rc) break;
        nwritten += rc;
        nb -= rc;
        s += rc;
    }
    return nwritten;
}
ssize_t Pty_controller :: write_nb ( const std :: string & str ) { if ( non_fd == m_cfd ) { throw Chpty_write_exception ( ) ; } ssize_t nb = static_cast < ssize_t > ( str . size ( ) ) ; ssize_t nwritten = 0 ; const char * s = str . c_str ( ) ; while ( nwritten < nb ) { if ( 0 == can_write ( ) ) break ; ssize_t rc = write ( m_cfd , s , nb ) ; if ( libc_err == rc ) { throw Chpty_write_exception ( ) ; } if ( 0 == rc ) break ; nwritten += rc ; nb -= rc ; s += rc ; } return nwritten ; }
Write string to the remote program, but do not block for more than
m_wtimeout.
Write string to the remote program but do not block for more than m_wtimeout .