Boost logo

Boost Users :

From: Richard, Charles (Charles.Richard1_at_[hidden])
Date: 2023-03-01 16:41:20


Hi,

I've been tasked with trying to figure out why we are getting an error in our log file, the error is "error: End of file". I'm still fairly new to doing real-world C++ development and I struggle with understanding why the code does what it does.

The errors in our log file specifically are:

2023.02.20 08:45:49.470[UTC] [19626:140486796130176] TRACE - Process::CmdRunner::AsyncReadStdout<0x7fc594013b20> len = 0
2023.02.20 08:45:49.470[UTC] [19626:140486796130176] TRACE - Process::CmdRunner::AsyncReadStdout<0x7fc594013b20> error: End of file

At a high level, my understanding is that we use Boost Asio to run python scripts where our C++ process will fork a new child process to run these python scripts. What I don't understand is why the code we have like the below was chosen to implement that functionality and to handle error handling. I've looked at some Asio boost tutorials but I still have gaps between our implementation and the Boost Asio tutorials and documentation.

I'm also wondering why the a_errCode == boost::asio::error::eof is not seemingly catching the end of file.

The code in the method CmdRunner::AsyncReadStdout does the following:

void CmdRunner::AsyncReadStdout(boost::system::error_code a_errCode, size_t a_readSize)

{

    DoLOG(TRACE, "Process::CmdRunner::%s<%p> len = %zu", __func__, this, a_readSize);

    if ( a_errCode ) {

        DoLOG(TRACE, "Process::CmdRunner::%s<%p> error: %s", __func__, this, a_errCode.message().c_str())

    }

    if ( a_readSize > 0 ) {

        DoLOG(TRACE, "Process::CmdRunner::%s<%p> - read this: %zu bytes", __func__, this, a_readSize)

        _stdoutBufList.Copy(_stdoutReadBuf, a_readSize); // Call user callback to push out bytes

        Daemon::Service::DispatchEvent([this]() { _cbHandler(_cbCtxt, false); });

    } else if ( a_errCode == boost::asio::error::eof ) { // Read done, call user callback function!

        DoLOG(TRACE, "Process::CmdRunner::%s<%p> - Child process (%d) STDOUT reached EOF", __func__, this, _childPid)

        _cmdDone = _eofStdout = true;

        _procStdout->close();

        _procStderr->close();

        Daemon::Service::DispatchEvent([this]() { _cbHandler(_cbCtxt, true); });

    } else { // Async-read more, until EOF seen

        _procStdout->async_read_some(boost::asio::buffer(_stdoutReadBuf, PROC_READ_BUF_SIZE),

            [this](boost::system::error_code ec, std::size_t a_readSize)

            {

                AsyncReadStdout(ec, a_readSize);

            });

    }

}

Any hints or specific links to look at to further clarify my understanding would be appreciated.

Thanks!
Chach

Internal Use - Confidential



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net