void CHttpConn::OnWrite() { if (!m_busy) return; int ret = netlib_send(m_sock_handle, m_out_buf.GetBuffer(), m_out_buf.GetWriteOffset()); if (ret <= 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { ret = 0; } else { log("close on error=%d", errno); OnClose(); return; } } int out_buf_size = (int) m_out_buf.GetWriteOffset(); m_out_buf.Read(NULL, ret); if (ret < out_buf_size) { m_busy = true; // log("not send all, remain=%d", m_out_buf.GetWriteOffset()); } else { m_busy = false; OnSendComplete(); } }
int CHttpConn::Send(void* data, int len) { m_last_send_tick = get_tick_count(); if (m_busy) { m_out_buf.Write(data, len); return len; } int ret = netlib_send(m_sock_handle, data, len); if (ret <= 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { ret = 0; } else { log("close on error=%d", errno); OnClose(); return -1; } } if (ret < len) { m_out_buf.Write((char*) data + ret, len - ret); m_busy = true; //log("not send all, remain=%d", m_out_buf.GetWriteOffset()); } else { OnSendComplete(); } return len; }
int CHttpConn::Send(void* data, int len) { m_last_send_tick = get_tick_count(); if (m_busy) { m_out_buf.Write(data, len); return len; } int ret = netlib_send(m_sock_handle, data, len); if (ret < 0) ret = 0; if (ret < len) { m_out_buf.Write((char*) data + ret, len - ret); m_busy = true; //log("not send all, remain=%d", m_out_buf.GetWriteOffset()); } else { OnSendComplete(); } return len; }
void CHttpConn::OnWrite() { if (!m_busy) return; int ret = netlib_send(m_sock_handle, m_out_buf.GetBuffer(), m_out_buf.GetWriteOffset()); if (ret < 0) ret = 0; int out_buf_size = (int) m_out_buf.GetWriteOffset(); m_out_buf.Read(NULL, ret); if (ret < out_buf_size) { m_busy = true; // log("not send all, remain=%d", m_out_buf.GetWriteOffset()); } else { m_busy = false; OnSendComplete(); } }
int CPeerLink::DoWrite( long long llCount ) { int nSendCount = 0; if (m_nPeerState == PS_ESTABLISHED) { for (; (m_strSendBuffer.size() > 0) && (nSendCount < llCount); ) { int nSendSize = m_strSendBuffer.size(); if (nSendSize > llCount) { nSendSize = llCount; } int nRet = send(GetHandle(), m_strSendBuffer.data(), nSendSize, 0); if (nRet == -1) { int nErrCode = WSAGetLastError(); if (nErrCode == WSAEINTR || nErrCode == WSAEWOULDBLOCK ) { m_bCanWrite = false; } else { CloseLink(); return nSendCount; } break; } nSendCount += nRet; m_nUploadCount += nRet; m_pPeerManager->GetTorrentTask()->AddUploadCount(nRet); m_strSendBuffer.erase(0, nRet); if (m_strSendBuffer.size() == 0) { OnSendComplete(); break; } } } if (m_bCanWrite) { if (GetHandleMask() & WRITE_MASK) { RemoveHandleMask(WRITE_MASK); } } else { if (!(GetHandleMask() & WRITE_MASK)) { SetHandleMask(WRITE_MASK); } } return nSendCount; }