bool LocalClient::writeMore() { bool ret = true; int written = 0; #ifdef HAVE_NOSIGNAL const int sendflags = MSG_NOSIGNAL; #else const int sendflags = 0; #endif for (;;) { if (mBuffers.empty()) { EventLoop::instance()->removeFileDescriptor(mFd, EventLoop::Write); break; } const String& front = mBuffers.front(); int w; eintrwrap(w, ::send(mFd, &front[mBufferIdx], front.size() - mBufferIdx, sendflags)); if (w == -1) { ret = (errno == EWOULDBLOCK || errno == EAGAIN); // apparently these can be different break; } written += w; mBufferIdx += w; if (mBufferIdx == front.size()) { assert(!mBuffers.empty()); mBuffers.pop_front(); mBufferIdx = 0; continue; } } if (written) mBytesWritten(this, written); return ret; }
bool SocketClient::writeMore() { bool ret = true; int written = 0; #ifdef HAVE_NOSIGNAL const int sendflags = MSG_NOSIGNAL; #else const int sendflags = 0; #endif for (;;) { if (mBuffers.empty()) { EventLoop::instance()->removeFileDescriptor(mFd, EventLoop::Write); break; } const sockaddr_in& addr = mBuffers.front().first; const String& front = mBuffers.front().second; int w; if (!addr.sin_port) { eintrwrap(w, ::send(mFd, &front[mBufferIdx], front.size() - mBufferIdx, sendflags)); } else { eintrwrap(w, ::sendto(mFd, &front[mBufferIdx], front.size() - mBufferIdx, sendflags, reinterpret_cast<const sockaddr*>(&addr), sizeof(sockaddr_in))); } if (w == -1) { ret = (errno == EWOULDBLOCK || errno == EAGAIN); // apparently these can be different break; } written += w; mBufferIdx += w; if (mBufferIdx == front.size()) { assert(!mBuffers.empty()); mBuffers.pop_front(); mBufferIdx = 0; continue; } } if (written) mBytesWritten(this, written); return ret; }