Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions muduo/net/Buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <errno.h>
#include <sys/uio.h>
#include <unistd.h>

using namespace muduo;
using namespace muduo::net;
Expand Down Expand Up @@ -56,3 +57,12 @@ ssize_t Buffer::readFd(int fd, int* savedErrno)
return n;
}

ssize_t Buffer::writeFd(int fd, int* savedErrno)
{
ssize_t n = ::write(fd, peek(), readableBytes());
if (n < 0)
{
*savedErrno = errno;
}
return n;
}
3 changes: 3 additions & 0 deletions muduo/net/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ class Buffer : public muduo::copyable
/// @return result of read(2), @c errno is saved
ssize_t readFd(int fd, int* savedErrno);

// Send data by fd.
ssize_t writeFd(int fd, int* savedErrno);

private:

char* begin()
Expand Down
5 changes: 2 additions & 3 deletions muduo/net/TcpConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,8 @@ void TcpConnection::handleWrite()
loop_->assertInLoopThread();
if (channel_->isWriting())
{
ssize_t n = sockets::write(channel_->fd(),
outputBuffer_.peek(),
outputBuffer_.readableBytes());
int savedErrno = 0;
ssize_t n = outputBuffer_.writeFd(channel_->fd(), &savedErrno);
if (n > 0)
{
outputBuffer_.retrieve(n);
Expand Down