Replace send() and recv() with swrite() and sread() macros.

This commit is contained in:
Yang Tse
2006-07-28 18:01:23 +00:00
parent b05a63758c
commit 283737c856
2 changed files with 10 additions and 13 deletions
+9 -12
View File
@@ -197,9 +197,7 @@ static void write_tcp_data(ares_channel channel, fd_set *write_fds, time_t now)
/* Can't allocate iovecs; just send the first request. */ /* Can't allocate iovecs; just send the first request. */
sendreq = server->qhead; sendreq = server->qhead;
scount = send(server->tcp_socket, (void *)sendreq->data, scount = swrite(server->tcp_socket, sendreq->data, sendreq->len);
sendreq->len, 0);
if (scount < 0) if (scount < 0)
{ {
if (!try_again(GET_ERRNO())) if (!try_again(GET_ERRNO()))
@@ -249,9 +247,9 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now)
/* We haven't yet read a length word, so read that (or /* We haven't yet read a length word, so read that (or
* what's left to read of it). * what's left to read of it).
*/ */
count = recv(server->tcp_socket, count = sread(server->tcp_socket,
(void *)(server->tcp_lenbuf + server->tcp_lenbuf_pos), server->tcp_lenbuf + server->tcp_lenbuf_pos,
2 - server->tcp_lenbuf_pos, 0); 2 - server->tcp_lenbuf_pos);
if (count <= 0) if (count <= 0)
{ {
if (!(count == -1 && try_again(GET_ERRNO()))) if (!(count == -1 && try_again(GET_ERRNO())))
@@ -276,9 +274,9 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds, time_t now)
else else
{ {
/* Read data into the allocated buffer. */ /* Read data into the allocated buffer. */
count = recv(server->tcp_socket, count = sread(server->tcp_socket,
(void *)(server->tcp_buffer + server->tcp_buffer_pos), server->tcp_buffer + server->tcp_buffer_pos,
server->tcp_length - server->tcp_buffer_pos, 0); server->tcp_length - server->tcp_buffer_pos);
if (count <= 0) if (count <= 0)
{ {
if (!(count == -1 && try_again(GET_ERRNO()))) if (!(count == -1 && try_again(GET_ERRNO())))
@@ -320,7 +318,7 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
!FD_ISSET(server->udp_socket, read_fds)) !FD_ISSET(server->udp_socket, read_fds))
continue; continue;
count = recv(server->udp_socket, (void *)buf, sizeof(buf), 0); count = sread(server->udp_socket, buf, sizeof(buf));
if (count == -1 && try_again(GET_ERRNO())) if (count == -1 && try_again(GET_ERRNO()))
continue; continue;
else if (count <= 0) else if (count <= 0)
@@ -510,8 +508,7 @@ void ares__send_query(ares_channel channel, struct query *query, time_t now)
return; return;
} }
} }
if (send(server->udp_socket, (void *)query->qbuf, if (swrite(server->udp_socket, query->qbuf, query->qlen) == -1)
query->qlen, 0) == -1)
{ {
/* FIXME: Handle EAGAIN here since it likely can happen. */ /* FIXME: Handle EAGAIN here since it likely can happen. */
query->skip_server[query->server] = 1; query->skip_server[query->server] = 1;
+1 -1
View File
@@ -102,6 +102,6 @@ ares_writev (ares_socket_t s, const struct iovec *vector, size_t count)
memcpy (bp, vector[i].iov_base, vector[i].iov_len); memcpy (bp, vector[i].iov_base, vector[i].iov_len);
bp += vector[i].iov_len; bp += vector[i].iov_len;
} }
return send (s, (const void*)buffer, bytes, 0); return (int)swrite(s, buffer, bytes);
} }
#endif /* WIN32 builds only */ #endif /* WIN32 builds only */