Esempio n. 1
0
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
    {
        OnWriteCompelete();
    }

	return len;
}
Esempio n. 2
0
int CImConn::Send(void *data, int len) {
	m_last_send_tick = get_tick_count();
	++g_send_pkt_cnt;

	if (m_busy) {
		m_out_buff.Write(data, len);
		return len;
	}

	int offset = 0;
	int remain = len;
	while (remain > 0) {
		int send_size = remain;
		if (send_size > NETLIB_MAX_SOCKET_BUF_SIZE) {
			send_size = NETLIB_MAX_SOCKET_BUF_SIZE;
		}

		int ret = netlib_send(m_handle, (char*) data + offset, send_size);
		if (ret <= 0) {
			ret = 0;
			break;
		}

		offset += ret;
		remain -= ret;
	}

	if (remain > 0) {
		m_out_buff.Write((char*) data + offset, remain);
		m_busy = true;
	}
	return len;
}
Esempio n. 3
0
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;
        OnWriteCompelete();
	}
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
int CImConn::Send(void* data, int len)
{
	if (m_busy)
	{
		m_out_buf.Write(data, len);
		return len;
	}

	int offset = 0;
	int remain = len;
	while (remain > 0) {
		int send_size = remain;
		if (send_size > NETLIB_MAX_SOCKET_BUF_SIZE) {
			send_size = NETLIB_MAX_SOCKET_BUF_SIZE;
		}

		int ret = netlib_send(m_handle, (char*)data + offset, send_size);
		if (ret <= 0) {
			ret = 0;
			break;
		}

		offset += ret;
		remain -= ret;
	}

	if (remain > 0)
	{
		m_out_buf.Write((char*)data + offset, remain);
		m_busy = true;
		LOG__(NET,  _T("send busy, remain=%d"), m_out_buf.GetWriteOffset());
	}

	return len;
}
Esempio n. 6
0
void CImConn::OnWrite()
{
	if (!m_busy)
		return;

	while (m_out_buf.GetWriteOffset() > 0) {
		int send_size = m_out_buf.GetWriteOffset();
		if (send_size > NETLIB_MAX_SOCKET_BUF_SIZE) {
			send_size = NETLIB_MAX_SOCKET_BUF_SIZE;
		}

		int ret = netlib_send(m_handle, m_out_buf.GetBuffer(), send_size);
		if (ret <= 0) {
			ret = 0;
			break;
		}

		m_out_buf.Read(NULL, ret);
	}

	if (m_out_buf.GetWriteOffset() == 0) {
		m_busy = false;
	}

	log("onWrite, remain=%d\n", m_out_buf.GetWriteOffset());
}
Esempio n. 7
0
void CImConn::OnWrite()
{
	// CAutoLock autoLock(&s_send_lock);
	if (!m_busy)
		return;

	while (m_out_buf.GetWriteOffset() > 0) {
		int send_size = m_out_buf.GetWriteOffset();
		if (send_size > NETLIB_MAX_SOCKET_BUF_SIZE) {
			send_size = NETLIB_MAX_SOCKET_BUF_SIZE;
		}

		int ret = netlib_send(m_handle, m_out_buf.GetBuffer(), send_size);
		if (ret <= 0) {
			if (errno == EAGAIN || errno == EWOULDBLOCK) {
				break;
			} else {
				log("close on error=%d", errno);
				OnClose();
				return;
			}
		}

		m_out_buf.Read(NULL, ret);
	}

	if (m_out_buf.GetWriteOffset() == 0) {
		m_busy = false;
	}

	log("onWrite, remain=%d ", m_out_buf.GetWriteOffset());
}
Esempio n. 8
0
int CImConn::Send(void* data, int len)
{
	// CAutoLock autoLock(&s_send_lock);
	m_last_send_tick = get_tick_count();
//	++g_send_pkt_cnt;

	if (m_busy)
	{
		m_out_buf.Write(data, len);
		return len;
	}

	int offset = 0;
	int remain = len;
	while (remain > 0) {
		int send_size = remain;
		if (send_size > NETLIB_MAX_SOCKET_BUF_SIZE) {
			send_size = NETLIB_MAX_SOCKET_BUF_SIZE;
		}

		int ret = netlib_send(m_handle, (char*)data + offset , send_size);
		if (ret <= 0) {
			if (errno == EAGAIN || errno == EWOULDBLOCK) {
				ret = 0;
			} else {
				log("close on error=%d", errno);
				OnClose();
				return -1;
			}
		}

		offset += ret;
		remain -= ret;
	}

	if (remain > 0)
	{
		m_out_buf.Write((char*)data + offset, remain);
		m_busy = true;
		log("send busy, remain=%d ", m_out_buf.GetWriteOffset());
	}
    else
    {
        OnWriteCompelete();
    }

	return len;
}
Esempio n. 9
0
void CHttpConn::OnWrite()
{
    if (!m_busy)
        return;

    int ret = netlib_send(m_sockHandle, m_outBuf.GetBuffer(), m_outBuf.GetWriteOffset());
    if (ret < 0)
        ret = 0;

    int out_buf_size = (int)m_outBuf.GetWriteOffset();

    m_outBuf.Read(NULL, ret);

    if (ret < out_buf_size){
        m_busy = true;
        Logger.Log(INFO, "not send all, remain=%d ", m_outBuf.GetWriteOffset());
    }else{
        m_busy = false;
        OnWriteCompelete();
    }
}
Esempio n. 10
0
int CHttpConn::Send(void* data, int len)
{
    m_lastSendTick = get_tick_count();

    if (m_busy){
        m_outBuf.Write(data, len);
        return len;
    }

    int ret = netlib_send(m_sockHandle, data, len);
    if (ret < 0)
        ret = 0;

    if (ret < len){
        m_outBuf.Write((char*)data + ret, len - ret);
        m_busy = true;
        Logger.Log(INFO, "not send all, remain=%d ", m_outBuf.GetWriteOffset());
    }else{
        OnWriteCompelete();
    }

    return len;
}