summaryrefslogtreecommitdiff
path: root/windows_port.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-07-24 21:47:49 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-07-24 21:47:49 +0000
commite8e8d3a4077add2afb6dec9400178921efd9db6f (patch)
tree935200a887984a4580f7cd0cf5c2d85422833b04 /windows_port.c
parent58f74b0549f33791b2d3e773472f5c8b2e69efea (diff)
downloadc-ares-e8e8d3a4077add2afb6dec9400178921efd9db6f.tar.gz
c-ares-e8e8d3a4077add2afb6dec9400178921efd9db6f.tar.bz2
c-ares-e8e8d3a4077add2afb6dec9400178921efd9db6f.zip
Gisle Vanem:
Basically in loops like handle_errors(), 'query->next' was assigned a local variable and then query was referenced after the memory was freed by next_server(). I've changed that so next_server() and end_query() returns the next query. So callers should use this ret-value. The next problem was that 'server->tcp_buffer_pos' had a random value at entry to 1st recv() (luckily causing Winsock to return ENOBUFS). I've also added a ares_writev() for Windows to streamline the code a bit more.
Diffstat (limited to 'windows_port.c')
-rw-r--r--windows_port.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/windows_port.c b/windows_port.c
index 9611e05..ac6ffb2 100644
--- a/windows_port.c
+++ b/windows_port.c
@@ -5,6 +5,8 @@
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
+#include <errno.h>
+#include <malloc.h>
#include "nameser.h"
@@ -52,4 +54,36 @@ ares_gettimeofday(struct timeval *tv, struct timezone *tz)
return 0;
}
+int
+ares_writev (SOCKET s, const struct iovec *vector, size_t count)
+{
+ char *buffer, *bp;
+ size_t i, bytes = 0;
+
+ /* Find the total number of bytes to write
+ */
+ for (i = 0; i < count; i++)
+ bytes += vector[i].iov_len;
+
+ if (bytes == 0) /* not an error */
+ return (0);
+
+ /* Allocate a temporary buffer to hold the data
+ */
+ buffer = bp = (char*) alloca (bytes);
+ if (!buffer)
+ {
+ errno = ENOMEM;
+ return (-1);
+ }
+
+ /* Copy the data into buffer.
+ */
+ for (i = 0; i < count; ++i)
+ {
+ memcpy (bp, vector[i].iov_base, vector[i].iov_len);
+ bp += vector[i].iov_len;
+ }
+ return send (s, (const void*)buffer, bytes, 0);
+}
#endif /* WIN32 builds only */