net: flush queued packets immediately
This commit is contained in:
@@ -277,22 +277,49 @@ int DESC::ProcessOutput()
|
||||
if (bytes_to_write == 0)
|
||||
return 0;
|
||||
|
||||
int result = socket_write(m_sock, (const char *) m_outputBuffer.ReadPtr(), bytes_to_write);
|
||||
int bytes_written = send(m_sock, (const char *) m_outputBuffer.ReadPtr(), bytes_to_write, 0);
|
||||
|
||||
if (result == 0)
|
||||
if (bytes_written > 0)
|
||||
{
|
||||
max_bytes_written = MAX(bytes_to_write, max_bytes_written);
|
||||
max_bytes_written = MAX(bytes_written, max_bytes_written);
|
||||
|
||||
total_bytes_written += bytes_to_write;
|
||||
current_bytes_written += bytes_to_write;
|
||||
total_bytes_written += bytes_written;
|
||||
current_bytes_written += bytes_written;
|
||||
|
||||
m_outputBuffer.Discard(bytes_to_write);
|
||||
m_outputBuffer.Discard(bytes_written);
|
||||
|
||||
if (m_outputBuffer.ReadableBytes() != 0)
|
||||
fdwatch_add_fd(m_lpFdw, m_sock, this, FDW_WRITE, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (result);
|
||||
if (bytes_written == 0)
|
||||
return -1;
|
||||
|
||||
#ifdef EINTR
|
||||
if (errno == EINTR)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
#ifdef EAGAIN
|
||||
if (errno == EAGAIN)
|
||||
{
|
||||
fdwatch_add_fd(m_lpFdw, m_sock, this, FDW_WRITE, true);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef EWOULDBLOCK
|
||||
if (errno == EWOULDBLOCK)
|
||||
{
|
||||
fdwatch_add_fd(m_lpFdw, m_sock, this, FDW_WRITE, true);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
sys_err("ProcessOutput: send failed: %s (fd %d)", strerror(errno), m_sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void DESC::BufferedPacket(const void * c_pvData, int iSize)
|
||||
@@ -370,6 +397,9 @@ void DESC::Packet(const void * c_pvData, int iSize)
|
||||
|
||||
if (m_iPhase != PHASE_CLOSE)
|
||||
fdwatch_add_fd(m_lpFdw, m_sock, this, FDW_WRITE, true);
|
||||
|
||||
if (m_iPhase != PHASE_CLOSE)
|
||||
ProcessOutput();
|
||||
}
|
||||
|
||||
void DESC::LargePacket(const void * c_pvData, int iSize)
|
||||
@@ -779,6 +809,9 @@ void DESC::RawPacket(const void * c_pvData, int iSize)
|
||||
|
||||
if (m_iPhase != PHASE_CLOSE)
|
||||
fdwatch_add_fd(m_lpFdw, m_sock, this, FDW_WRITE, true);
|
||||
|
||||
if (m_iPhase != PHASE_CLOSE)
|
||||
ProcessOutput();
|
||||
}
|
||||
|
||||
void DESC::ChatPacket(BYTE type, const char * format, ...)
|
||||
|
||||
Reference in New Issue
Block a user