Skip to content

Commit

Permalink
Don't use errno in socket accept code.
Browse files Browse the repository at this point in the history
Switch to using non-inlined lastError() function. When we switch stacks for
fibers we might using an old cached pointer to the errno memory value. This is
due to how errno is implemented on Linux.
  • Loading branch information
mtanski committed Nov 6, 2013
1 parent 5e19aa5 commit ee88c22
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions mordor/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ Socket::connect(const Address &to)
// Worked first time
return;
}
if (errno == EINPROGRESS) {
if (lastError() == EINPROGRESS) {
m_ioManager->registerEvent(m_sock, IOManager::WRITE);
if (m_cancelledSend) {
MORDOR_LOG_ERROR(g_log) << this << " connect(" << m_sock << ", " << to
Expand Down Expand Up @@ -744,7 +744,7 @@ Socket::accept(Socket &target)
error_t error;
do {
newsock = ::accept(m_sock, NULL, NULL);
error = errno;
error = lastError();
} while (newsock == -1 && error == EINTR);
while (newsock == -1 && error == EAGAIN) {
m_ioManager->registerEvent(m_sock, IOManager::READ);
Expand All @@ -770,7 +770,7 @@ Socket::accept(Socket &target)
}
do {
newsock = ::accept(m_sock, NULL, NULL);
error = errno;
error = lastError();
} while (newsock == -1 && error == EINTR);
}
if (newsock == -1) {
Expand Down Expand Up @@ -956,7 +956,7 @@ Socket::doIO(iovec *buffers, size_t length, int &flags, Address *address)
error_t error;
do {
rc = isSend ? sendmsg(m_sock, &msg, flags) : recvmsg(m_sock, &msg, flags);
error = errno;
error = lastError();
} while (rc == -1 && error == EINTR);
while (m_ioManager && rc == -1 && error == EAGAIN) {
m_ioManager->registerEvent(m_sock, event);
Expand All @@ -974,7 +974,7 @@ Socket::doIO(iovec *buffers, size_t length, int &flags, Address *address)
}
do {
rc = isSend ? sendmsg(m_sock, &msg, flags) : recvmsg(m_sock, &msg, flags);
error = errno;
error = lastError();
} while (rc == -1 && error == EINTR);
}
MORDOR_SOCKET_LOG(rc, error);
Expand Down
8 changes: 4 additions & 4 deletions mordor/streams/fd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ FDStream::read(Buffer &buffer, size_t length)
length = 0xfffffffe;
std::vector<iovec> iovs = buffer.writeBuffers(length);
int rc = readv(m_fd, &iovs[0], iovs.size());
while (rc < 0 && errno == EAGAIN && m_ioManager) {
while (rc < 0 && lastError() == EAGAIN && m_ioManager) {
MORDOR_LOG_TRACE(g_log) << this << " readv(" << m_fd << ", " << length
<< "): " << rc << " (EAGAIN)";
m_ioManager->registerEvent(m_fd, IOManager::READ);
Expand Down Expand Up @@ -112,7 +112,7 @@ FDStream::read(void *buffer, size_t length)
if (length > 0xfffffffe)
length = 0xfffffffe;
int rc = ::read(m_fd, buffer, length);
while (rc < 0 && errno == EAGAIN && m_ioManager) {
while (rc < 0 && lastError() == EAGAIN && m_ioManager) {
MORDOR_LOG_TRACE(g_log) << this << " read(" << m_fd << ", " << length
<< "): " << rc << " (EAGAIN)";
m_ioManager->registerEvent(m_fd, IOManager::READ);
Expand Down Expand Up @@ -149,7 +149,7 @@ FDStream::write(const Buffer &buffer, size_t length)
length = 0xfffffffe;
const std::vector<iovec> iovs = buffer.readBuffers(length);
int rc = writev(m_fd, &iovs[0], iovs.size());
while (rc < 0 && errno == EAGAIN && m_ioManager) {
while (rc < 0 && lastError() == EAGAIN && m_ioManager) {
MORDOR_LOG_TRACE(g_log) << this << " writev(" << m_fd << ", " << length
<< "): " << rc << " (EAGAIN)";
m_ioManager->registerEvent(m_fd, IOManager::WRITE);
Expand Down Expand Up @@ -179,7 +179,7 @@ FDStream::write(const void *buffer, size_t length)
if (length > 0xfffffffe)
length = 0xfffffffe;
int rc = ::write(m_fd, buffer, length);
while (rc < 0 && errno == EAGAIN && m_ioManager) {
while (rc < 0 && lastError() == EAGAIN && m_ioManager) {
MORDOR_LOG_TRACE(g_log) << this << " write(" << m_fd << ", " << length
<< "): " << rc << " (EAGAIN)";
m_ioManager->registerEvent(m_fd, IOManager::WRITE);
Expand Down

0 comments on commit ee88c22

Please sign in to comment.