THRIFT-2454: c_glib: There is no gethostbyname_r() in some OS
authorRoger Meier <roger@apache.org>
Tue, 8 Apr 2014 21:52:01 +0000 (23:52 +0200)
committerRoger Meier <roger@apache.org>
Tue, 8 Apr 2014 21:52:01 +0000 (23:52 +0200)
Patch: Jin-wook Jeong

configure.ac
lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c

index 483c283..f4d1869 100755 (executable)
@@ -530,6 +530,7 @@ AC_CHECK_FUNCS([strtoul])
 AC_CHECK_FUNCS([bzero])
 AC_CHECK_FUNCS([ftruncate])
 AC_CHECK_FUNCS([gethostbyname])
+AC_CHECK_FUNCS([gethostbyname_r])
 AC_CHECK_FUNCS([gettimeofday])
 AC_CHECK_FUNCS([memmove])
 AC_CHECK_FUNCS([memset])
index a371ace..68eb21c 100644 (file)
@@ -54,16 +54,24 @@ thrift_socket_is_open (ThriftTransport *transport)
 gboolean
 thrift_socket_open (ThriftTransport *transport, GError **error)
 {
-  struct hostent he, *hp = NULL;
+  struct hostent *hp = NULL;
   struct sockaddr_in pin;
   int err;
+#if defined(HAVE_GETHOSTBYNAME_R)
+  struct hostent he;
   char buf[1024];
+#endif
 
   ThriftSocket *tsocket = THRIFT_SOCKET (transport);
   g_return_val_if_fail (tsocket->sd == 0, FALSE);
 
   /* lookup the destination host */
-  if (gethostbyname_r(tsocket->hostname, &he, buf, 1024, &hp, &err) != 0 || hp == NULL) {
+#if defined(HAVE_GETHOSTBYNAME_R)
+  if (gethostbyname_r (tsocket->hostname, &he, buf, 1024, &hp, &err) != 0 || hp == NULL)
+#else
+  if ((hp = gethostbyname (tsocket->hostname)) == NULL && (err = h_errno))
+#endif
+  {
     /* host lookup failed, bail out with an error */
     g_set_error (error, THRIFT_TRANSPORT_ERROR, THRIFT_TRANSPORT_ERROR_HOST,
                  "host lookup failed for %s:%d - %s",