You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2012/12/22 01:43:53 UTC

svn commit: r1425215 - in /zookeeper/trunk: CHANGES.txt src/c/src/addrvec.c src/c/src/addrvec.h src/c/src/winport.c src/c/src/winport.h src/c/src/zookeeper.c

Author: phunt
Date: Sat Dec 22 00:43:53 2012
New Revision: 1425215

URL: http://svn.apache.org/viewvc?rev=1425215&view=rev
Log:
ZOOKEEPER-1597. Windows build failing (michim via phunt)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/c/src/addrvec.c
    zookeeper/trunk/src/c/src/addrvec.h
    zookeeper/trunk/src/c/src/winport.c
    zookeeper/trunk/src/c/src/winport.h
    zookeeper/trunk/src/c/src/zookeeper.c

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1425215&r1=1425214&r2=1425215&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Sat Dec 22 00:43:53 2012
@@ -299,6 +299,8 @@ BUGFIXES:
   ZOOKEEPER-1603. StaticHostProviderTest testUpdateClientMigrateOrNot
   hangs (Alexander Shraer via phunt)
 
+  ZOOKEEPER-1597. Windows build failing (michim via phunt)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

Modified: zookeeper/trunk/src/c/src/addrvec.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/addrvec.c?rev=1425215&r1=1425214&r2=1425215&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/addrvec.c (original)
+++ zookeeper/trunk/src/c/src/addrvec.c Sat Dec 22 00:43:53 2012
@@ -20,6 +20,10 @@
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
+#ifdef WIN32
+#include <WS2tcpip.h>
+#include "winport.h"
+#endif
 
 #include "addrvec.h"
 
@@ -64,6 +68,8 @@ int addrvec_alloc_capacity(addrvec_t* av
 
 int addrvec_grow(addrvec_t *avec, uint32_t grow_amount)
 {
+    unsigned int old_capacity = 0;
+    struct sockaddr_storage *old_data = NULL;
     assert(avec);
 
     if (grow_amount == 0)
@@ -72,8 +78,8 @@ int addrvec_grow(addrvec_t *avec, uint32
     }
 
     // Save off old data and capacity in case there is a realloc failure
-    unsigned int old_capacity = avec->capacity;
-    struct sockaddr_storage *old_data = avec->data;
+    old_capacity = avec->capacity;
+    old_data = avec->data;
 
     avec->capacity += grow_amount;
     avec->data = realloc(avec->data, sizeof(*avec->data) * avec->capacity);
@@ -110,12 +116,12 @@ static int addrvec_grow_if_full(addrvec_
 
 int addrvec_contains(const addrvec_t *avec, const struct sockaddr_storage *addr)
 {
+    uint32_t i = 0;
     if (!avec || !addr)
     { 
         return 0;
     }
 
-    int i = 0;
     for (i = 0; i < avec->count; i++)
     {
         if(memcmp(&avec->data[i], addr, INET_ADDRSTRLEN) == 0)
@@ -127,10 +133,11 @@ int addrvec_contains(const addrvec_t *av
 
 int addrvec_append(addrvec_t *avec, const struct sockaddr_storage *addr)
 {
+    int rc = 0;
     assert(avec);
     assert(addr);
 
-    int rc = addrvec_grow_if_full(avec);
+    rc = addrvec_grow_if_full(avec);
     if (rc != 0)
     {
         return rc;
@@ -145,10 +152,11 @@ int addrvec_append(addrvec_t *avec, cons
 
 int addrvec_append_addrinfo(addrvec_t *avec, const struct addrinfo *addrinfo)
 {
+    int rc = 0;
     assert(avec);
     assert(addrinfo);
 
-    int rc = addrvec_grow_if_full(avec);
+    rc = addrvec_grow_if_full(avec);
     if (rc != 0)
     {
         return rc;
@@ -203,12 +211,12 @@ void addrvec_next(addrvec_t *avec, struc
 
 int addrvec_eq(const addrvec_t *a1, const addrvec_t *a2)
 {
+    uint32_t i = 0;
     if (a1->count != a2->count)
     {
         return 0;
     }
 
-    int i;
     for (i = 0; i < a1->count; ++i)
     {
         if (!addrvec_contains(a2, &a1->data[i]))

Modified: zookeeper/trunk/src/c/src/addrvec.h
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/addrvec.h?rev=1425215&r1=1425214&r2=1425215&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/addrvec.h (original)
+++ zookeeper/trunk/src/c/src/addrvec.h Sat Dec 22 00:43:53 2012
@@ -24,6 +24,9 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netdb.h>
+#else
+#include <WinSock2.h>
+#include "winstdint.h"
 #endif
 
 /**

Modified: zookeeper/trunk/src/c/src/winport.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/winport.c?rev=1425215&r1=1425214&r2=1425215&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/winport.c (original)
+++ zookeeper/trunk/src/c/src/winport.c Sat Dec 22 00:43:53 2012
@@ -18,6 +18,7 @@
 
 #ifdef WIN32
 #include "winport.h"
+#include <stdlib.h>
 #include <winsock2.h>
 #include <ws2tcpip.h>
 
@@ -286,6 +287,11 @@ void Win32WSACleanup()
        WSACleanup();
 }
 
+double drand48(void)
+{
+    return (double)(rand()) / RAND_MAX;
+}
+
 #endif //WIN32
 
 

Modified: zookeeper/trunk/src/c/src/winport.h
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/winport.h?rev=1425215&r1=1425214&r2=1425215&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/winport.h (original)
+++ zookeeper/trunk/src/c/src/winport.h Sat Dec 22 00:43:53 2012
@@ -116,6 +116,7 @@ inline int gettimeofday(struct timeval *
 int close(SOCKET fd);
 int Win32WSAStartup();
 void Win32WSACleanup();
+double drand48(void);
 #endif //WIN32
 
 

Modified: zookeeper/trunk/src/c/src/zookeeper.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/zookeeper.c?rev=1425215&r1=1425214&r2=1425215&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/zookeeper.c (original)
+++ zookeeper/trunk/src/c/src/zookeeper.c Sat Dec 22 00:43:53 2012
@@ -51,6 +51,8 @@
 #include <netdb.h>
 #include <unistd.h>
 #include "config.h"
+#else
+#include "winstdint.h"
 #endif
 
 #ifdef HAVE_SYS_UTSNAME_H
@@ -209,7 +211,7 @@ static void *SYNCHRONOUS_MARKER = (void*
 static int isValidPath(const char* path, const int flags);
 
 #ifdef _WINDOWS
-static int zookeeper_send(SOCKET s, const char* buf, int len)
+static int zookeeper_send(SOCKET s, const void* buf, int len)
 #else
 static ssize_t zookeeper_send(int s, const void* buf, size_t len)
 #endif
@@ -463,13 +465,12 @@ static int getaddrinfo_errno(int rc) { 
  */
 static int count_hosts(char *hosts)
 {
+    uint32_t count = 0;
+    char *loc = hosts;
     if (!hosts || strlen(hosts) == 0) {
         return 0;
     }
 
-    uint32_t count = 0;
-    char *loc = hosts;
-
     while ((loc = strchr(loc, ','))) {
         count++;
         loc+=1;
@@ -486,6 +487,10 @@ static int count_hosts(char *hosts)
 int resolve_hosts(const char *hosts_in, addrvec_t *avec)
 {
     int rc = ZOK;
+    char *host = NULL;
+    char *hosts = NULL;
+    int num_hosts = 0;
+    char *strtok_last = NULL;
 
     if (hosts_in == NULL || avec == NULL) {
         return ZBADARGUMENTS;
@@ -494,7 +499,7 @@ int resolve_hosts(const char *hosts_in, 
     // initialize address vector
     addrvec_init(avec);
 
-    char *hosts = strdup(hosts_in);
+    hosts = strdup(hosts_in);
     if (hosts == NULL) {
         LOG_ERROR(("out of memory"));
         errno=ENOMEM;
@@ -502,7 +507,7 @@ int resolve_hosts(const char *hosts_in, 
         goto fail;
     }
 
-    int num_hosts = count_hosts(hosts);
+    num_hosts = count_hosts(hosts);
     if (num_hosts == 0) {
         free(hosts);
         return ZOK;
@@ -517,8 +522,7 @@ int resolve_hosts(const char *hosts_in, 
         goto fail;
     }
 
-    char *strtok_last;
-    char * host = strtok_r(hosts, ",", &strtok_last);
+    host = strtok_r(hosts, ",", &strtok_last);
     while(host) {
         char *port_spec = strrchr(host, ':');
         char *end_port_spec;
@@ -720,6 +724,14 @@ fail:
  */
 int update_addrs(zhandle_t *zh)
 {
+    int rc = ZOK;
+    char *hosts = NULL;
+    uint32_t num_old = 0;
+    uint32_t num_new = 0;
+    uint32_t i = 0;
+    int found_current = 0;
+    addrvec_t resolved = { 0 };
+
     // Verify we have a valid handle
     if (zh == NULL) {
         return ZBADARGUMENTS;
@@ -734,9 +746,6 @@ int update_addrs(zhandle_t *zh)
     // NOTE: guard access to {hostname, addr_cur, addrs, addrs_old, addrs_new}
     lock_reconfig(zh);
 
-    int rc = ZOK;
-    char *hosts = NULL;
-
     // Copy zh->hostname for local use
     hosts = strdup(zh->hostname);
     if (hosts == NULL) {
@@ -744,7 +753,6 @@ int update_addrs(zhandle_t *zh)
         goto fail;
     }
 
-    addrvec_t resolved = { 0 };
     rc = resolve_hosts(hosts, &resolved);
     if (rc != ZOK)
     {
@@ -758,7 +766,7 @@ int update_addrs(zhandle_t *zh)
     }
 
     // Is the server we're connected to in the new resolved list?
-    int found_current = addrvec_contains(&resolved, &zh->addr_cur);
+    found_current = addrvec_contains(&resolved, &zh->addr_cur);
 
     // Clear out old and new address lists
     zh->reconfig = 1;
@@ -766,7 +774,6 @@ int update_addrs(zhandle_t *zh)
     addrvec_free(&zh->addrs_new);
 
     // Divide server list into addrs_old if in previous list and addrs_new if not
-    int i = 0;
     for (i = 0; i < resolved.count; i++)
     {
         struct sockaddr_storage *resolved_address = &resolved.data[i];
@@ -787,8 +794,8 @@ int update_addrs(zhandle_t *zh)
         }
     }
 
-    int num_old = zh->addrs_old.count;
-    int num_new = zh->addrs_new.count;
+    num_old = zh->addrs_old.count;
+    num_new = zh->addrs_new.count;
 
     // Number of servers increased
     if (num_old + num_new > zh->addrs.count)
@@ -1172,11 +1179,13 @@ void zoo_cycle_next_server(zhandle_t *zh
  */
 const char* zoo_get_current_server(zhandle_t* zh)
 {
+    const char *endpoint_info = NULL;
+
     // NOTE: guard access to {hostname, addr_cur, addrs, addrs_old, addrs_new}
     // Need the lock here as it is changed in update_addrs()
     lock_reconfig(zh);
 
-    const char * endpoint_info = format_endpoint_info(&zh->addr_cur);
+    endpoint_info = format_endpoint_info(&zh->addr_cur);
     unlock_reconfig(zh);
     return endpoint_info;
 }
@@ -1870,6 +1879,7 @@ int zookeeper_interest(zhandle_t *zh, in
      struct timeval *tv)
 {
 #endif
+    int rc = 0;
     struct timeval now;
     if(zh==0 || fd==0 ||interest==0 || tv==0)
         return ZBADARGUMENTS;
@@ -1885,7 +1895,7 @@ int zookeeper_interest(zhandle_t *zh, in
     }
     api_prolog(zh);
 
-    int rc = update_addrs(zh);
+    rc = update_addrs(zh);
     if (rc != ZOK) {
         return api_epilog(zh, rc);
     }
@@ -1915,14 +1925,14 @@ int zookeeper_interest(zhandle_t *zh, in
 
         // No need to delay -- grab the next server and attempt connection
         else {
-            zoo_cycle_next_server(zh);
+            int ssoresult;
 
 #ifdef WIN32
             char enable_tcp_nodelay = 1;
 #else
             int enable_tcp_nodelay = 1;
 #endif
-            int ssoresult;
+            zoo_cycle_next_server(zh);
 
             zh->fd = socket(zh->addr_cur.ss_family, SOCK_STREAM, 0);
             if (zh->fd < 0) {