mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
There are two different places in write_tcp_data() that advance the send_queue; however, they are slightly different and only the first one properly uses a while loop. Consolidate both into a single function that DTTR. (Patch from the Google tree.)
This commit is contained in:
parent
d0de9663e2
commit
c1a475e708
@ -62,6 +62,8 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds,
|
|||||||
ares_socket_t read_fd, time_t now);
|
ares_socket_t read_fd, time_t now);
|
||||||
static void read_udp_packets(ares_channel channel, fd_set *read_fds,
|
static void read_udp_packets(ares_channel channel, fd_set *read_fds,
|
||||||
ares_socket_t read_fd, time_t now);
|
ares_socket_t read_fd, time_t now);
|
||||||
|
static void advance_tcp_send_queue(ares_channel channel, int whichserver,
|
||||||
|
ssize_t num_bytes);
|
||||||
static void process_timeouts(ares_channel channel, time_t now);
|
static void process_timeouts(ares_channel channel, time_t now);
|
||||||
static void process_broken_connections(ares_channel channel, time_t now);
|
static void process_broken_connections(ares_channel channel, time_t now);
|
||||||
static void process_answer(ares_channel channel, unsigned char *abuf,
|
static void process_answer(ares_channel channel, unsigned char *abuf,
|
||||||
@ -208,29 +210,7 @@ static void write_tcp_data(ares_channel channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Advance the send queue by as many bytes as we sent. */
|
/* Advance the send queue by as many bytes as we sent. */
|
||||||
while (wcount)
|
advance_tcp_send_queue(channel, i, wcount);
|
||||||
{
|
|
||||||
sendreq = server->qhead;
|
|
||||||
if ((size_t)wcount >= sendreq->len)
|
|
||||||
{
|
|
||||||
wcount -= sendreq->len;
|
|
||||||
server->qhead = sendreq->next;
|
|
||||||
if (server->qhead == NULL)
|
|
||||||
{
|
|
||||||
SOCK_STATE_CALLBACK(channel, server->tcp_socket, 1, 0);
|
|
||||||
server->qtail = NULL;
|
|
||||||
}
|
|
||||||
if (sendreq->data_storage != NULL)
|
|
||||||
free(sendreq->data_storage);
|
|
||||||
free(sendreq);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sendreq->data += wcount;
|
|
||||||
sendreq->len -= wcount;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -246,27 +226,42 @@ static void write_tcp_data(ares_channel channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Advance the send queue by as many bytes as we sent. */
|
/* Advance the send queue by as many bytes as we sent. */
|
||||||
if ((size_t)scount == sendreq->len)
|
advance_tcp_send_queue(channel, i, scount);
|
||||||
{
|
|
||||||
server->qhead = sendreq->next;
|
|
||||||
if (server->qhead == NULL)
|
|
||||||
{
|
|
||||||
SOCK_STATE_CALLBACK(channel, server->tcp_socket, 1, 0);
|
|
||||||
server->qtail = NULL;
|
|
||||||
}
|
|
||||||
if (sendreq->data_storage != NULL)
|
|
||||||
free(sendreq->data_storage);
|
|
||||||
free(sendreq);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sendreq->data += scount;
|
|
||||||
sendreq->len -= scount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Consume the given number of bytes from the head of the TCP send queue. */
|
||||||
|
static void advance_tcp_send_queue(ares_channel channel, int whichserver,
|
||||||
|
ssize_t num_bytes)
|
||||||
|
{
|
||||||
|
struct send_request *sendreq;
|
||||||
|
struct server_state *server = &channel->servers[whichserver];
|
||||||
|
while (num_bytes > 0)
|
||||||
|
{
|
||||||
|
sendreq = server->qhead;
|
||||||
|
if ((size_t)num_bytes >= sendreq->len)
|
||||||
|
{
|
||||||
|
num_bytes -= sendreq->len;
|
||||||
|
server->qhead = sendreq->next;
|
||||||
|
if (server->qhead == NULL)
|
||||||
|
{
|
||||||
|
SOCK_STATE_CALLBACK(channel, server->tcp_socket, 1, 0);
|
||||||
|
server->qtail = NULL;
|
||||||
|
}
|
||||||
|
if (sendreq->data_storage != NULL)
|
||||||
|
free(sendreq->data_storage);
|
||||||
|
free(sendreq);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sendreq->data += num_bytes;
|
||||||
|
sendreq->len -= num_bytes;
|
||||||
|
num_bytes = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* If any TCP socket selects true for reading, read some data,
|
/* If any TCP socket selects true for reading, read some data,
|
||||||
* allocate a buffer if we finish reading the length word, and process
|
* allocate a buffer if we finish reading the length word, and process
|
||||||
* a packet if we finish reading one.
|
* a packet if we finish reading one.
|
||||||
|
Loading…
Reference in New Issue
Block a user