I have been having trouble figuring out what I did to create this staircase effect in my output stream.
void Connection::WriteToSocket() {
if (m_writing) {
m_moreToWrite = true;
return;
}
std::swap(m_outputBuffer, m_bufferBeingWritten);
std::swap(m_outputStream, m_StreamBeingWritten);
m_writing = true;
async_write(m_socket, *m_bufferBeingWritten,
[this](boost::system::error_code err, std::size_t) {
m_writing = false;
// Write
if (err) {
std::cout << "async_write returned error!" << std::endl;
} else if (m_moreToWrite) {
WriteToSocket();
m_moreToWrite = false;
}
});
}
Above is my WriteToSocket function, which takes my current buffer, and if it is not writing swaps it to the buffer that should write, then does an async write with the data I want to send to the client.
void Write(const std::string &message) {
*m_outputStream << message << '\n';
WriteToSocket();
}
void Write(std::vector<std::string> args) {
for (auto i = 0; i < args.size(); ++i) {
*m_outputStream << args.at(i) << std::endl;
}
WriteToSocket();
}
These two functions populate the buffer before I output anything to the client. My mindset was, populate the buffer contents, then output it to the client.
I am wondering how I am ending up with output like the following.
https://i.imgur.com/TvOFOxy.png
Thank you for any assistance. I have been reading both http://www.cplusplus.com/reference/ostream/ostream/ostream/ and http://www.cplusplus.com/reference/streambuf/streambuf/
as well as the boost documentation, and have not seen anything that has me moving in the right direction. My first assumption was that I needed to flush the buffer or something. My second assumption was I was incorrectly appending my new-lines.
Both of those assumptions lead me on some wild-goose-chases and now here I am.
Aucun commentaire:
Enregistrer un commentaire