Index: src/gnet-private.c
===================================================================
RCS file: /cvs/gnome/gnet/src/gnet-private.c,v
retrieving revision 1.35
diff -p -u -2 -r1.35 gnet-private.c
--- src/gnet-private.c	27 Sep 2004 02:04:49 -0000	1.35
+++ src/gnet-private.c	13 Jun 2005 23:58:23 -0000
@@ -135,17 +135,4 @@ gnet_private_io_channel_new (SOCKET sock
 #ifdef GNET_WIN32
 
-static WNDCLASSEX gnetWndClass;
-HWND  gnet_hWnd; 
-static guint gnet_io_watch_ID;
-static GIOChannel *gnet_iochannel;
-
-int gnet_MainCallBack(GIOChannel *iochannel, GIOCondition condition, void *nodata);
-
-LRESULT CALLBACK
-GnetWndProc(HWND hwnd,
-	    UINT uMsg,
-	    WPARAM wParam,
-	    LPARAM lParam);
-
 BOOL WINAPI 
 DllMain(HINSTANCE hinstDLL,
@@ -153,68 +140,4 @@ DllMain(HINSTANCE hinstDLL,
 	LPVOID lpvReserved);
 
-/* This function is still necessary (even though it does nothing) since it 
-	presence works around an issue in the Glib main loop. */
-
-int 
-gnet_MainCallBack(GIOChannel *iochannel, GIOCondition condition, void *nodata)
-{
-  MSG msg;
-  int i;
-
-  while ((i = PeekMessage (&msg, gnet_hWnd, 0, 0, PM_REMOVE)))
-  {
-	switch (msg.message) 
-    {
-		case IA_NEW_MSG:
-		{
-			break;
-		}
-		case GET_NAME_MSG:
-		{
-			break;
-		}
-	} /* switch */
-  } /* while */
-
-  return 1;
-}
-
-/* Not used but required*/
-LRESULT CALLBACK
-GnetWndProc(HWND hwnd,        /* handle to window */
-	    UINT uMsg,        /* message identifier */
-	    WPARAM wParam,    /* first message parameter */
-	    LPARAM lParam)    /* second message parameter */
-{ 
-
-    switch (uMsg) 
-    { 
-        case WM_CREATE: 
-            /* Initialize the window. */
-            return 0; 
- 
-        case WM_PAINT: 
-            /* Paint the window's client area. */ 
-            return 0; 
- 
-        case WM_SIZE: 
-            /* Set the size and position of the window. */ 
-            return 0; 
- 
-        case WM_DESTROY: 
-            /* Clean up window-specific data objects. */
-            return 0; 
- 
-        /* 
-          Process other messages. 
-        */ 
- 
-        default: 
-            return DefWindowProc(hwnd, uMsg, wParam, lParam); 
-    } 
-    return 0; 
-} 
-
-
 BOOL WINAPI 
 DllMain(HINSTANCE hinstDLL,  /* handle to DLL module */
@@ -235,54 +158,4 @@ DllMain(HINSTANCE hinstDLL,  /* handle t
  
 	/* The WinSock DLL is acceptable. Proceed. */
-
-	/* Setup and register a windows class that we use for our GIOchannel */
-	gnetWndClass.cbSize = sizeof(WNDCLASSEX); 
-	gnetWndClass.style = CS_SAVEBITS; /* doesn't matter, need something? */ 
-	gnetWndClass.lpfnWndProc = (WNDPROC) GnetWndProc; 
-	gnetWndClass.cbClsExtra = 0; 
-	gnetWndClass.cbWndExtra = 0; 
-	gnetWndClass.hInstance = hinstDLL; 
-	gnetWndClass.hIcon = NULL; 
-	gnetWndClass.hCursor = NULL; 
-	gnetWndClass.hbrBackground = NULL; 
-	gnetWndClass.lpszMenuName = NULL; 
-	gnetWndClass.lpszClassName = "Gnet"; 
-	gnetWndClass.hIconSm = NULL; 
-
-	if (!RegisterClassEx(&gnetWndClass))
-	  {
-	    if (GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
-			return FALSE;
-	  }
-
-	gnet_hWnd  = CreateWindowEx
-	  (
-	   0,
-	   "Gnet", 
-	   "none",
-	   WS_OVERLAPPEDWINDOW, 
-	   CW_USEDEFAULT, 
-	   CW_USEDEFAULT, 
-	   CW_USEDEFAULT, 
-	   CW_USEDEFAULT, 
-	   (HWND) NULL, 
-	   (HMENU) NULL, 
-	   hinstDLL, 
-	   (LPVOID) NULL);  
-
-	if (!gnet_hWnd) 
-	  {
-	    return FALSE;
-	  }
-
-	gnet_iochannel = g_io_channel_win32_new_messages((unsigned int)gnet_hWnd);
-
-	/* Add a watch */
-	
-	gnet_io_watch_ID = g_io_add_watch(gnet_iochannel,
-					  (GIOCondition)(G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL),
-					  gnet_MainCallBack, 
-					  NULL);
-					  
 	break;
       }
@@ -302,8 +175,4 @@ DllMain(HINSTANCE hinstDLL,  /* handle t
       /* The DLL unmapped from process's address space. Do necessary cleanup */
       {
-	g_source_remove(gnet_io_watch_ID);
-	g_free(gnet_iochannel);
- 	DestroyWindow(gnet_hWnd); 
-
 	/*CleanUp WinSock 2 */
 	WSACleanup();
Index: src/gnet-private.h
===================================================================
RCS file: /cvs/gnome/gnet/src/gnet-private.h,v
retrieving revision 1.60
diff -p -u -2 -r1.60 gnet-private.h
--- src/gnet-private.h	25 Apr 2005 15:39:27 -0000	1.60
+++ src/gnet-private.h	13 Jun 2005 23:58:23 -0000
@@ -83,4 +83,8 @@ struct sockaddr_storage {
 #endif
 
+#define STATUS_IS_SOCKET_ERROR(status) ((status) < 0)
+
+#define ERROR_IS_CONNECT_IN_PROGRESS() (errno == EINPROGRESS)
+
 #ifndef socklen_t
 #  ifdef GNET_APPLE_DARWIN
@@ -100,7 +104,5 @@ struct sockaddr_storage {
 #else	/*********** Windows specific ***********/
 
-#include <windows.h>
-#include <winbase.h>
-#include <winuser.h>
+#include <winsock2.h>
 #include <ws2tcpip.h>
 
@@ -108,4 +110,8 @@ struct sockaddr_storage {
 #define in_addr_t guint32
 
+#define STATUS_IS_SOCKET_ERROR(status) ((status) == SOCKET_ERROR)
+
+#define ERROR_IS_CONNECT_IN_PROGRESS() (WSAGetLastError () == WSAEWOULDBLOCK)
+
 #define GNET_IS_SOCKET_VALID(S) ((S) != INVALID_SOCKET)
 
@@ -290,8 +296,7 @@ typedef struct _GInetAddrNewListState 
   gpointer 	data;
 
-#ifndef GNET_WIN32		/* UNIX */
   gboolean 	in_callback;
 #ifdef G_THREADS_ENABLED
-  GStaticMutex mutex;
+  GStaticMutex	mutex;
   gboolean	is_cancelled;
   gboolean	lookup_failed;
@@ -307,11 +312,4 @@ typedef struct _GInetAddrNewListState 
 
 #endif
-#else				/* Windows */
-  gboolean 	in_callback;
-  CRITICAL_SECTION mutex;
-  gboolean	is_cancelled;
-  gboolean	lookup_failed;
-  guint 	source;
-#endif
 
 } GInetAddrNewListState;
@@ -339,5 +337,4 @@ typedef struct _GInetAddrReverseAsyncSta
   gpointer data;
   gboolean in_callback;
-#ifndef GNET_WIN32		/* UNIX 	*/
 #ifdef G_THREADS_ENABLED
   GStaticMutex mutex;
@@ -353,15 +350,4 @@ typedef struct _GInetAddrReverseAsyncSta
   guchar	buffer[256 + 1];/* Names can only be 256 characters? */
   int 		len;
-#else				/* WINDOWS */
-  int WSAhandle;
-  char hostentBuffer[MAXGETHOSTSTRUCT];
-  int errorcode;
-
-  CRITICAL_SECTION mutex;
-  gboolean	is_cancelled;
-  gchar*	name;
-  guint 	source;
-
-#endif
 
 } GInetAddrReverseAsyncState;
@@ -409,9 +395,4 @@ typedef struct _GTcpSocketConnectState 
 
 #ifdef GNET_WIN32
-
-extern HWND  gnet_hWnd; 
-extern GHashTable *gnet_hash;
-#define IA_NEW_MSG 100		/* gnet_inetaddr_new_async */
-#define GET_NAME_MSG 101	/* gnet_inetaddr_get_name_async */
 
 /* Name-mangled IPv6 structures for primarily Mingw and a few VC .NET 2002 */
Index: src/gnet.c
===================================================================
RCS file: /cvs/gnome/gnet/src/gnet.c,v
retrieving revision 1.21
diff -p -u -2 -r1.21 gnet.c
--- src/gnet.c	10 Mar 2005 14:24:26 -0000	1.21
+++ src/gnet.c	13 Jun 2005 23:58:23 -0000
@@ -30,5 +30,5 @@ const guint gnet_binary_age = GNET_BINAR
 
 
-#ifdef HAVE_IPV6
+#if !defined(GNET_WIN32) && defined(HAVE_IPV6)
 static gboolean ipv6_detect_envvar (void);
 static gboolean ipv6_detect_iface (void);
@@ -70,8 +70,6 @@ gnet_init (void)
 
 #ifdef G_THREADS_ENABLED
-#ifndef GNET_WIN32 
   if (!g_thread_supported ()) 
     g_thread_init (NULL);
-#endif
 #endif /* G_THREADS_ENABLED */
 
@@ -129,5 +127,5 @@ gnet_init (void)
 
 
-#ifdef HAVE_IPV6
+#if !defined(GNET_WIN32) && defined(HAVE_IPV6)
 /* 
 
Index: src/inetaddr.c
===================================================================
RCS file: /cvs/gnome/gnet/src/inetaddr.c,v
retrieving revision 1.85
diff -p -u -2 -r1.85 inetaddr.c
--- src/inetaddr.c	25 Apr 2005 15:39:27 -0000	1.85
+++ src/inetaddr.c	13 Jun 2005 23:58:24 -0000
@@ -32,21 +32,46 @@
 
 #ifdef GNET_WIN32
-#include <process.h>
 
 static int inet_pton(int af, const char* src, void* dst);
 static const char* inet_ntop(int af, const void *src, char *dst, size_t size);
 
-/* TODO: Use Window's inet_pton/inet_ntop if they ever implement it. */
 static int
 inet_pton(int af, const char* src, void* dst)
 {
-  in_addr_t addr;
+  int address_length;
+  struct sockaddr_storage sa;
+  struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
+  struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
+
+  switch (af)
+    {
+    case AF_INET:
+      address_length = sizeof (struct sockaddr_in);
+      break;
+      
+    case AF_INET6:
+      address_length = sizeof (struct sockaddr_in6);
+      break;
+      
+    default:
+      return -1;
+    }
 
-  addr = inet_addr(src);
-  if (addr == INADDR_NONE && strcmp(src, "255.255.255.255"))
-    return 0;
+  if (WSAStringToAddress ((LPTSTR) src, af, NULL, (LPSOCKADDR) &sa, &address_length) == 0)
+    {
+      switch (af)
+	{
+	case AF_INET:
+	  memcpy (dst, &sin->sin_addr, sizeof (struct in_addr));
+	  break;
+
+	case AF_INET6:
+	  memcpy (dst, &sin6->sin6_addr, sizeof (struct in6_addr));
+	  break;
+	}
+      return 1;
+    }
 
-  *((in_addr_t*) dst) = addr;
-  return 1;
+  return 0;
 }
 
@@ -54,16 +79,35 @@ static const char* 
 inet_ntop(int af, const void* src, char* dst, size_t size)
 {
-  struct in_addr addr = *(struct in_addr*) src;
-  const char* buf;
+  int address_length;
+  DWORD string_length = size;
+  struct sockaddr_storage sa;
+  struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
+  struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
+
+  memset (&sa, 0, sizeof (sa));
+  switch (af)
+    {
+    case AF_INET:
+      address_length = sizeof (struct sockaddr_in);
+      sin->sin_family = af;
+      memcpy (&sin->sin_addr, src, sizeof (struct in_addr));
+      break;
+      
+    case AF_INET6:
+      address_length = sizeof (struct sockaddr_in6);
+      sin6->sin6_family = af;
+      memcpy (&sin6->sin6_addr, src, sizeof (struct in6_addr));
+      break;
 
-  buf = inet_ntoa(addr);
-  if (buf == NULL)
-    return NULL;
+    default:
+      return NULL;
+    }
 
-  strcpy(dst, buf);
+  if (WSAAddressToString ((LPSOCKADDR) &sa, address_length, NULL,
+			  dst, &string_length) == 0)
+    return dst;
 
-  return dst;
+  return NULL;
 }
-
 #endif /* GNET_WIN32 */
 
@@ -120,5 +164,4 @@ hostent2ialist (const struct hostent* he
    sockaddr_storage pointers. */
 
-#ifndef GNET_WIN32
 GList*
 gnet_gethostbyname(const char* hostname)
@@ -322,9 +365,4 @@ gnet_gethostbyname(const char* hostname)
 
 #else 
-#ifdef GNET_WIN32
-  {
-/* moved to own func */
-  }
-#else
   {
     struct hostent* he;
@@ -346,5 +384,4 @@ gnet_gethostbyname(const char* hostname)
 #endif
 #endif
-#endif
 
   if (list)
@@ -354,90 +391,4 @@ gnet_gethostbyname(const char* hostname)
 
 }
-#else /* GNET_WIN32 */
-GList*
-gnet_gethostbyname(const char* hostname)
-{
-	GList* list = NULL;
-
-	if (pfn_getaddrinfo)
-	{
-		struct addrinfo hints;
-		struct addrinfo* res;
-		int rv;
-		GIPv6Policy policy;
-
-		/*  printf("Using pfn_getaddrinfo in gnet_gethostbyname\n"); */
-
-		policy = gnet_ipv6_get_policy();
-
-		memset (&hints, 0, sizeof(hints));
-		hints.ai_socktype = SOCK_STREAM;
-		hints.ai_family = PF_UNSPEC;
-		rv = pfn_getaddrinfo(hostname, NULL, &hints, &res);
-
-		if (rv == 0)
-		{
-			struct addrinfo* i;
-			GList* ipv4_list = NULL;
-			GList* ipv6_list = NULL;
-	
-			for (i = res; i != NULL; i = i->ai_next)
-			{
-				GInetAddr* ia;
-
-				ia = g_new0(GInetAddr, 1);
-				ia->ref_count = 1;
-				memcpy (&ia->sa, i->ai_addr, i->ai_addrlen);
-
-				if (i->ai_family == PF_INET)
-					ipv4_list = g_list_prepend (ipv4_list, ia);
-				else if (i->ai_family == PF_INET6)
-					ipv6_list = g_list_prepend (ipv6_list, ia);
-				else
-					g_free (ia);
-			} /* for */
-
-			if (policy == GIPV6_POLICY_IPV4_ONLY)
-			{
-				list = ipv4_list;
-				g_list_free (ipv6_list);
-			}
-			else if (policy == GIPV6_POLICY_IPV4_THEN_IPV6)
-			{
-				list = g_list_concat (ipv6_list, ipv4_list);
-				/* list will be reversed below */
-			}
-			else if (policy == GIPV6_POLICY_IPV6_ONLY)
-			{
-				list = ipv6_list;
-				g_list_free (ipv4_list);
-			}
-			else if (policy == GIPV6_POLICY_IPV6_THEN_IPV4)
-			{
-				list = g_list_concat (ipv4_list, ipv6_list);
-				/* list will be reversed below */
-			}
-
-			pfn_freeaddrinfo(res);
-		} /* if (rv == 0) */
-	}
-	else
-	{
-		struct hostent* result;
-
-		/* One hostent struct per thread according to MSDN so we do not 
-			have to put a lock around this call. */
-		result = gethostbyname(hostname);
-		if (result != NULL)
-			list = hostent2ialist(result);
-
-	} /* if (pfn_getaddrinfo) */
-
-	if (list)
-		list = g_list_reverse (list);
-	return list;
-}
-#endif
-
 
 /* Free list of GInetAddr's.  We assume name hasn't been allocated. */
@@ -610,36 +561,4 @@ gnet_gethostbyaddr(const struct sockaddr
   }
 #else
-#ifdef GNET_WIN32
-  {
-	if (pfn_getnameinfo)
-	{
-		int gnirv;
-		char host[NI_MAXHOST];
-
-		/* printf("Using pfn_getnameinfo in gnet_gethostbyaddr\n"); */
-		gnirv = pfn_getnameinfo((const struct sockaddr*) sa, 
-			GNET_SOCKADDR_LEN(*sa),
-			host, sizeof(host),
-			NULL, 0, NI_NAMEREQD);
-
-		if (gnirv == 0)
-			rv = g_strdup(host);
-	}
-	else
-	{
-		const char* sa_addr   = GNET_SOCKADDR_ADDRP(*sa);
-		int			sa_len    = GNET_SOCKADDR_ADDRLEN(*sa);
-		int         sa_type   = GNET_SOCKADDR_FAMILY(*sa);
-
-		struct hostent* he;
-
-		/* One hostent struct per thread according to MSDN so we do not 
-			have to put a lock around this call. */
-		he = gethostbyaddr(sa_addr, sa_len, sa_type);
-		if (he != NULL && he->h_name != NULL)
-			rv = g_strdup(he->h_name);
-	}
-  }
-#else
   {
     const char* sa_addr   = GNET_SOCKADDR_ADDRP(*sa);
@@ -659,5 +578,4 @@ gnet_gethostbyaddr(const struct sockaddr
 #endif
 #endif
-#endif
 
   return rv;
@@ -865,6 +783,4 @@ inetaddr_new_async_cb (GList* ialist, gp
 
 
-#ifndef GNET_WIN32  /*********** Unix code ***********/
-
 #ifdef G_THREADS_ENABLED
 static void* inetaddr_new_list_async_gthread (void* arg);
@@ -1165,5 +1081,5 @@ inetaddr_new_list_async_gthread (void* a
   g_static_mutex_unlock (&state->mutex);
 
-  /* Thread exits... */
+ /* Thread exits... */
   return NULL;
 }
@@ -1388,199 +1304,4 @@ gnet_inetaddr_new_list_async_cancel (GIn
 #endif
 
-#else	/*********** Windows code ***********/
-
-static unsigned __stdcall inetaddr_new_list_async_thread (void* arg);
-static gboolean inetaddr_new_list_async_thread_dispatch (gpointer data);
-
-GInetAddrNewListAsyncID
-gnet_inetaddr_new_list_async (const gchar* hostname, gint port, 
-			      GInetAddrNewListAsyncFunc func, 
-			      gpointer data)
-{
-	void** args;
-	HANDLE hThread;
-    unsigned threadID;
-	GInetAddrNewListState* state = NULL;
-
-	g_return_val_if_fail(hostname != NULL, NULL);
-	g_return_val_if_fail(func != NULL, NULL);
-
-    state = g_new0(GInetAddrNewListState, 1);
-
-    args = g_new (void*, 2);
-    args[0] = (void*) g_strdup(hostname);
-    args[1] = state;
-
-	InitializeCriticalSection(&state->mutex);
-	EnterCriticalSection(&state->mutex);
-
-	hThread = (HANDLE)_beginthreadex( NULL, 0, &inetaddr_new_list_async_thread,
-		args, 0, &threadID );
-	
-	if (hThread == 0)
-	{
-	  g_warning ("_beginthreadex in gnet_inetaddr_new_list_async");
-	  LeaveCriticalSection(&state->mutex);
-      DeleteCriticalSection(&state->mutex);
-	  g_free (args[0]);
-	  g_free (state);
-      return NULL;
-	}
-	CloseHandle(hThread);
-
-	g_assert (state);
-	state->port = port;
-	state->func = func;
-	state->data = data;
-
-	LeaveCriticalSection(&state->mutex);
-	return state;
-}
-
-static unsigned __stdcall
-inetaddr_new_list_async_thread (void* arg)
-{
-  void** args = (void**) arg;
-  gchar* name = (gchar*) args[0];
-  GInetAddrNewListState* state = (GInetAddrNewListState*) args[1];
-  GList* ialist;
-
-  g_free (args);
-
-  /* Do lookup */
-  ialist = gnet_gethostbyname (name);
-  g_free (name);
-
-  /* Lock */
-  EnterCriticalSection(&state->mutex);
-
-  /* If cancelled, destroy state and exit.  The main thread is no
-     longer using state. */
-  if (state->is_cancelled)
-    {
-      ialist_free (state->ias);
-
-      LeaveCriticalSection(&state->mutex);
-      DeleteCriticalSection(&state->mutex);
-
-      g_free (state);
-
-      return 0;
-    }
-
-  if (ialist)
-    {
-      GList* i;
-
-      /* Set the port */
-      for (i = ialist; i != NULL; i = i->next)
-	{
-	  GInetAddr* ia = (GInetAddr*) i->data;
-          GNET_INETADDR_PORT_SET(ia, g_htons(state->port));
-	}
-
-      /* Save the list */
-      state->ias = ialist;
-    }
-  else
-    {
-      /* Flag failure */
-      state->lookup_failed = TRUE;
-    }
-
-  /* Add a source for reply */
-  state->source = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, 
-				   inetaddr_new_list_async_thread_dispatch,
-				   state, NULL);
-
-  /* This helps work around an issue in the Glib main loop */
-  if (!PostMessage(gnet_hWnd, IA_NEW_MSG, (WPARAM) NULL, (LPARAM) NULL))
-	  g_warning ("PostMessage in inetaddr_new_list_async_thread");
-
-  /* Unlock */
-  LeaveCriticalSection(&state->mutex);
-
-  /* Thread exits... */
-  return 0;
-}
-
-static gboolean
-inetaddr_new_list_async_thread_dispatch (gpointer data)
-{
-  GInetAddrNewListState* state = (GInetAddrNewListState*) data;
-
-  EnterCriticalSection(&state->mutex);
-
-  state->in_callback = TRUE;
-
-  /* Upcall */
-  if (!state->lookup_failed)
-    (*state->func)(state->ias, state->data);
-  else
-    (*state->func)(NULL, state->data);
-
-  state->in_callback = FALSE;
-
-  /* Delete state */
-  g_source_remove (state->source);
-  LeaveCriticalSection (&state->mutex);
-  DeleteCriticalSection (&state->mutex);
-  g_free (state);
-
-  return FALSE;
-}
-
-void
-gnet_inetaddr_new_list_async_cancel (GInetAddrNewListAsyncID id)
-{
-  GInetAddrNewListState* state = (GInetAddrNewListState*) id;
-
-  g_return_if_fail (state);
-
-  if (state->in_callback)
-    return;
-
-  /* We don't use in_callback because we'd have to get the mutex to
-     access it and if we're in the callback we'd already have the
-     mutex and deadlock.  in_callback was mostly meant to prevent
-     programmer error.  */
-
-  EnterCriticalSection (&state->mutex);
-
-  /* Check if the thread has finished and a reply is pending.  If a
-     reply is pending, cancel it and delete state. */
-  if (state->source)
-    {
-      g_source_remove (state->source);
-
-      ialist_free (state->ias);
-
-      LeaveCriticalSection (&state->mutex);
-      DeleteCriticalSection (&state->mutex);
-
-      g_free (state);
-    }
-
-  /* Otherwise, the thread is still running.  Set the cancelled flag
-     and allow the thread to complete.  When the thread completes, it
-     will delete state. */
-
-  else
-    {
-      state->is_cancelled = TRUE;
-
-      LeaveCriticalSection (&state->mutex);
-    }
-}
-
-gboolean 
-gnet_inetaddr_new_list_async_cb (GIOChannel* iochannel, 
-					  GIOCondition condition, 
-					  gpointer data) { /* do nothing */ return 0;}
-
-#endif		/*********** End Windows code ***********/
-
-
-
 /**
  *  gnet_inetaddr_new_nonblock:
@@ -1818,6 +1539,4 @@ gnet_inetaddr_get_name_nonblock (GInetAd
 
 
-#ifndef GNET_WIN32  /*********** Unix code ***********/
-
 #ifdef G_THREADS_ENABLED
 static void* inetaddr_get_name_async_gthread (void* arg);
@@ -2200,173 +1919,4 @@ gnet_inetaddr_get_name_async_cancel (GIn
 
 
-#else	/*********** Windows code ***********/
-
-static unsigned __stdcall inetaddr_get_name_async_thread (void* arg);
-static gboolean inetaddr_get_name_async_thread_dispatch (gpointer data);
-
-
-GInetAddrGetNameAsyncID
-gnet_inetaddr_get_name_async(GInetAddr* inetaddr,
-			     GInetAddrGetNameAsyncFunc func,
-			     gpointer data)
-{
-  HANDLE hThread;
-  unsigned threadID;
-
-  GInetAddrReverseAsyncState* state = NULL;
-
-  g_return_val_if_fail(inetaddr != NULL, NULL);
-  g_return_val_if_fail(func != NULL, NULL);
-
-  state = g_new0(GInetAddrReverseAsyncState, 1);
-
-  InitializeCriticalSection(&state->mutex);
-  EnterCriticalSection(&state->mutex);
-  
-  hThread = (HANDLE)_beginthreadex( NULL, 0, &inetaddr_get_name_async_thread,
-		state, 0, &threadID );
-  
-  if (hThread == 0)
-  {
-	  g_warning ("_beginthreadex in gnet_inetaddr_get_name_async");
-	  LeaveCriticalSection(&state->mutex);
-      DeleteCriticalSection(&state->mutex);
-	  g_free (state);
-      return NULL;
-  }
-  CloseHandle(hThread);
-
-  /* Set up state for callback */
-  g_assert (state);
-  state->ia = gnet_inetaddr_clone(inetaddr);
-  state->func = func;
-  state->data = data;
-  
-  LeaveCriticalSection (&state->mutex);
-  return state;
-}
-
-
-void
-gnet_inetaddr_get_name_async_cancel(GInetAddrGetNameAsyncID id)
-{
-  GInetAddrReverseAsyncState* state = (GInetAddrReverseAsyncState*) id;
-
-  EnterCriticalSection (&state->mutex);
-
-  /* Check if the thread has finished and a reply is pending.  If a
-     reply is pending, cancel it and delete state. */
-  if (state->source){
-      g_free (state->name);
-
-      g_source_remove (state->source);
-
-      LeaveCriticalSection (&state->mutex);
-      DeleteCriticalSection (&state->mutex);
-
-      g_free (state);
-    }
-
-  /* Otherwise, the thread is still running.  Set the cancelled flag
-     and allow the thread to complete.  When the thread completes, it
-     will delete state.  We can't kill the thread because we'd loose
-     the resources allocated in gethostbyname_r. */
-
-  else
-    {
-      state->is_cancelled = TRUE;
-
-      LeaveCriticalSection (&state->mutex);
-    }
-}
-
-
-static gboolean
-inetaddr_get_name_async_thread_dispatch (gpointer data)
-{
-  GInetAddrReverseAsyncState* state = (GInetAddrReverseAsyncState*) data;
-
-  EnterCriticalSection (&state->mutex);
-
-  /* Upcall */
-  (*state->func)(state->name, state->data);
-
-  /* Delete state */
-  gnet_inetaddr_delete (state->ia);
-  g_source_remove (state->source);
-  LeaveCriticalSection (&state->mutex);
-  DeleteCriticalSection (&state->mutex);
-  memset (state, 0, sizeof(*state));
-  g_free (state);
-
-  return FALSE;
-}
-
-
-static unsigned __stdcall
-inetaddr_get_name_async_thread (void* arg)
-{
-  GInetAddrReverseAsyncState* state = (GInetAddrReverseAsyncState*) arg;
-  gchar* name;
-
-  /* Lock */
-  EnterCriticalSection (&state->mutex);
-     
-  /* Do lookup */
-  if (state->ia->name)
-    name = g_strdup (state->ia->name);
-  else
-    name = gnet_gethostbyaddr(&state->ia->sa);
-
-  /* If cancelled, destroy state and exit.  The main thread is no
-     longer using state. */
-  if (state->is_cancelled)
-    {
-      g_free (name);
-      gnet_inetaddr_delete (state->ia);
-
-      LeaveCriticalSection (&state->mutex);
-      DeleteCriticalSection (&state->mutex);
-
-      g_free (state);
-
-      return 0;
-    }
-
-  /* Copy name to state */
-  if (name)
-  {
-      state->name = name;
-  }
-  else 	/* Lookup failed: name is canonical name */
-    {
-		state->name = gnet_inetaddr_get_canonical_name(state->ia);
-    }
-
-  /* Add a source for reply */
-  state->source = g_idle_add_full (G_PRIORITY_DEFAULT, 
-				   inetaddr_get_name_async_thread_dispatch,
-				   state, NULL);
-
-  /* Helps work around a Glib main loop issue on Windows */
-  if (!PostMessage(gnet_hWnd, GET_NAME_MSG, (WPARAM) NULL, (LPARAM) NULL))
-	  g_warning ("PostMessage in inetaddr_new_list_async_thread");
-
-  /* Unlock */
-  LeaveCriticalSection (&state->mutex);
-
-  /* Thread exits... */
-  return 0;
-}
-
-gboolean 
-gnet_inetaddr_get_name_async_cb (GIOChannel* iochannel, 
-				 GIOCondition condition, 
-				 gpointer data)
-{return 0;} /* do nothing, not used on Windows */
-
-#endif		/*********** End Windows code ***********/
-
-
 /**
  *  gnet_inetaddr_get_length
@@ -2468,25 +2018,8 @@ gnet_inetaddr_get_canonical_name(const G
   g_return_val_if_fail (inetaddr != NULL, NULL);
 
-#ifndef GNET_WIN32
   if (inet_ntop(GNET_INETADDR_FAMILY(inetaddr), 
 		GNET_INETADDR_ADDRP(inetaddr),
 		buffer, sizeof(buffer)) == NULL)
     return NULL;
-#else
-  if (pfn_getnameinfo)
-  {
-	int rv = pfn_getnameinfo((const struct sockaddr FAR *)&inetaddr->sa,
-		(socklen_t)GNET_INETADDR_LEN(inetaddr), buffer, sizeof(buffer), NULL, 0, 
-		NI_NUMERICHOST);
-	if (rv != 0)
-		return NULL;
-  }
-  else
-  {
-    guchar* p = (guchar*) GNET_INETADDR_ADDRP(inetaddr);
-	g_snprintf(buffer, sizeof(buffer), 
-	     "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
-  }
-#endif
   return g_strdup(buffer);
 }
@@ -3002,6 +2535,4 @@ gnet_inetaddr_noport_equal (gconstpointe
 /* **************************************** */
 
-#ifndef GNET_WIN32  /*********** Unix code ***********/
-
 /**
  *  gnet_inetaddr_get_host_name:
@@ -3015,5 +2546,6 @@ gchar*
 gnet_inetaddr_get_host_name (void)
 {
-  gchar* name = NULL;
+  gchar* name;
+#ifndef GNET_WIN32
   struct utsname myname;
   GInetAddr* addr;
@@ -3034,30 +2566,14 @@ gnet_inetaddr_get_host_name (void)
 
   gnet_inetaddr_delete (addr);
-
-  return name;
-}
-
-
-#else	/*********** Windows code ***********/
-/* (Windows doesn't have uname */
-
-gchar*
-gnet_inetaddr_get_host_name (void)
-{
-  gchar* name = NULL;
-  int error = 0;
-
+#else
   name = g_new0(char, 256);
-  error = gethostname(name, 256);
-  if (error)
+  if (gethostname(name, 256))
     {
       g_free(name);
       return NULL;
     }
-
+#endif
   return name;
 }
-
-#endif		/*********** End Windows code ***********/
 
 
Index: src/inetaddr.h
===================================================================
RCS file: /cvs/gnome/gnet/src/inetaddr.h,v
retrieving revision 1.31
diff -p -u -2 -r1.31 inetaddr.h
--- src/inetaddr.h	5 Feb 2003 00:58:49 -0000	1.31
+++ src/inetaddr.h	13 Jun 2005 23:58:24 -0000
@@ -25,8 +25,4 @@
 #include <glib.h>
 
-#ifdef   GNET_WIN32
-#include <winsock2.h>	/* This needs to be here */
-#endif
-
 #ifdef __cplusplus
 extern "C" {
Index: src/mcast.c
===================================================================
RCS file: /cvs/gnome/gnet/src/mcast.c,v
retrieving revision 1.23
diff -p -u -2 -r1.23 mcast.c
--- src/mcast.c	4 Feb 2005 14:44:32 -0000	1.23
+++ src/mcast.c	13 Jun 2005 23:58:24 -0000
@@ -509,5 +509,5 @@ gnet_mcast_socket_is_loopback (const GMc
       flag_size = sizeof (flag);
       rv = getsockopt(socket->sockfd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, 
-		      &flag, &flag_size);
+		      (char *) &flag, &flag_size);
       if (flag)
 	is_loopback = 1;
@@ -574,5 +574,5 @@ gnet_mcast_socket_set_loopback (GMcastSo
 
       rv2 = setsockopt(socket->sockfd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
-		       &flag, sizeof(flag));
+		       (char *) &flag, sizeof(flag));
     }
 #endif
Index: src/tcp.c
===================================================================
RCS file: /cvs/gnome/gnet/src/tcp.c,v
retrieving revision 1.67
diff -p -u -2 -r1.67 tcp.c
--- src/tcp.c	20 May 2004 01:46:01 -0000	1.67
+++ src/tcp.c	13 Jun 2005 23:58:25 -0000
@@ -372,7 +372,4 @@ gnet_tcp_socket_new_async (const GInetAd
 
 
-#ifndef GNET_WIN32  /*********** Unix code ***********/
-
-
 /**
  *  gnet_tcp_socket_new_async_direct
@@ -397,8 +394,13 @@ gnet_tcp_socket_new_async_direct (const 
 				  gpointer data)
 {
-  gint 			sockfd;
+  SOCKET		sockfd;
+#ifndef GNET_WIN32
   gint 			flags;
+#else
+  u_long		arg;
+#endif
   GTcpSocket* 		s;
   GTcpSocketAsyncState* state;
+  gint			status;
 
   g_return_val_if_fail(addr != NULL, NULL);
@@ -413,4 +415,6 @@ gnet_tcp_socket_new_async_direct (const 
     }
 
+  /* Force the socket into non-blocking mode */
+#ifndef GNET_WIN32
   /* Get the flags (should all be 0?) */
   flags = fcntl(sockfd, F_GETFL, 0);
@@ -428,4 +432,8 @@ gnet_tcp_socket_new_async_direct (const 
       return NULL;
     }
+#else
+  arg = 1;
+  ioctlsocket(sockfd, FIONBIO, &arg);
+#endif
 
   /* Create our structure */
@@ -435,8 +443,9 @@ gnet_tcp_socket_new_async_direct (const 
 
   /* Connect (but non-blocking!) */
-  if (connect(s->sockfd, &GNET_INETADDR_SA(addr), 
-	      GNET_INETADDR_LEN(addr)) < 0)
+  status = connect(s->sockfd, &GNET_INETADDR_SA(addr), 
+		   GNET_INETADDR_LEN(addr));
+  if (STATUS_IS_SOCKET_ERROR (status))
     {
-      if (errno != EINPROGRESS)
+      if (!ERROR_IS_CONNECT_IN_PROGRESS ())
 	{
 	  GNET_CLOSE_SOCKET(sockfd);    
@@ -459,6 +468,9 @@ gnet_tcp_socket_new_async_direct (const 
   state->func = func;
   state->data = data;
+#ifndef GNET_WIN32
   state->flags = flags;
-  state->iochannel = gnet_private_io_channel_new(s->sockfd);
+#endif
+  state->iochannel = gnet_tcp_socket_get_io_channel (s);
+  g_io_channel_ref (state->iochannel);
   state->connect_watch = g_io_add_watch(state->iochannel,
 					GNET_ANY_IO_CONDITION,
@@ -483,5 +495,4 @@ gnet_tcp_socket_new_async_cb (GIOChannel
   state->iochannel = NULL;
 
-  errno = 0;
   if (!((condition & G_IO_IN) || (condition & G_IO_OUT)))
     goto error;
@@ -500,4 +511,5 @@ gnet_tcp_socket_new_async_cb (GIOChannel
     goto error;
 
+#ifndef GNET_WIN32
   /* Reset the flags */
   if (fcntl(state->socket->sockfd, F_SETFL, state->flags) != 0)
@@ -506,4 +518,5 @@ gnet_tcp_socket_new_async_cb (GIOChannel
       goto error;
     }
+#endif
 
   /* Success */
@@ -542,108 +555,4 @@ gnet_tcp_socket_new_async_cancel (GTcpSo
   g_free (state);
 }
-
-#else	/*********** Windows code ***********/
-
-
-GTcpSocketNewAsyncID
-gnet_tcp_socket_new_async_direct (const GInetAddr* addr,
-				  GTcpSocketNewAsyncFunc func,
-				  gpointer data)
-{
-  SOCKET sockfd;
-  gint status;
-  GTcpSocket* s;
-  GTcpSocketAsyncState* state;
-  u_long arg;
-
-  g_return_val_if_fail(addr != NULL, NULL);
-  g_return_val_if_fail(func != NULL, NULL);
-
-  /* Create socket */
-  sockfd = socket(GNET_INETADDR_FAMILY(addr), SOCK_STREAM, 0);
-  if (!GNET_IS_SOCKET_VALID(sockfd))
-    {
-      g_warning ("socket() failed");
-      return NULL;
-    }
-	
-  /* Create our structure */
-  s = g_new0(GTcpSocket, 1);
-  s->ref_count = 1;
-  s->sockfd = sockfd;
-
-  /* Force the socket into non-blocking mode */
-  arg = 1;
-  ioctlsocket(sockfd, FIONBIO, &arg);
-
-  status = connect(s->sockfd, &GNET_INETADDR_SA(addr), 
-		   GNET_INETADDR_LEN(addr));
-  if (status == SOCKET_ERROR) /* Returning an error is ok, unless.. */
-    {
-      status = WSAGetLastError();
-      if (status != WSAEWOULDBLOCK)
-	{
-	  g_free(s);
-	  return NULL;
-	}
-    }
-
-  /* Save address */ 
-  s->sa = addr->sa;
-
-  /* Wait for the connection */
-  state = g_new0(GTcpSocketAsyncState, 1);
-  state->socket = s;
-  state->func = func;
-  state->data = data;
-  state->socket->sockfd = sockfd;
-
-  state->connect_watch = 
-    g_io_add_watch(gnet_private_io_channel_new(s->sockfd),
-		   GNET_ANY_IO_CONDITION,
-		   gnet_tcp_socket_new_async_cb, 
-		   state);
-
-  if (state->connect_watch <= 0)
-      return NULL;
-
-  return state;
-}
-
-
-
-gboolean
-gnet_tcp_socket_new_async_cb (GIOChannel* iochannel,
-			      GIOCondition condition,
-			      gpointer data)
-{
-  GTcpSocketAsyncState* state = (GTcpSocketAsyncState*) data;
-
-  if (condition & G_IO_ERR)
-    goto error;
-
-  (*state->func)(state->socket, state->data);
-  g_free (state);
-  return FALSE;
-
- error:
-  (*state->func)(NULL, state->data);
-  gnet_tcp_socket_delete (state->socket);
-  g_free (state);
-  return FALSE;
-}
-
-
-void
-gnet_tcp_socket_new_async_cancel (GTcpSocketNewAsyncID id)
-{
-  GTcpSocketAsyncState* state = (GTcpSocketAsyncState*) id;
-	
-  g_source_remove(state->connect_watch);
-  gnet_tcp_socket_delete(state->socket);
-  g_free (state);
-}
-
-#endif		/*********** End Windows code ***********/
 
 
Index: tests/conn_http_test.c
===================================================================
RCS file: /cvs/gnome/gnet/tests/conn_http_test.c,v
retrieving revision 1.6
diff -p -u -2 -r1.6 conn_http_test.c
--- tests/conn_http_test.c	25 Apr 2005 14:47:21 -0000	1.6
+++ tests/conn_http_test.c	13 Jun 2005 23:58:25 -0000
@@ -1,2 +1,3 @@
+#include <windows.h>
 /***************************************************************************
  *
@@ -508,5 +509,5 @@ test_post (const gchar *artist, const gc
 	return TRUE;
 }
-
+#if 0
 /***************************************************************************
  *
@@ -522,5 +523,5 @@ foo (gpointer baz)
 	return TRUE;
 }
-
+#endif
 
 /***************************************************************************
@@ -535,4 +536,6 @@ main (int argc, char **argv)
 	verbose = FALSE;
 
+	g_print ("%#lx:main() starting\n", GetCurrentThreadId ());
+
 	gnet_init ();
 
@@ -547,6 +550,7 @@ main (int argc, char **argv)
 	/* without this, the GLib mainloop 
 	 * doesn't seem to get started?! */
+#if 0
 	g_timeout_add(50, foo, NULL); 
-
+#endif
 	if (argc > 1)
 	{
@@ -559,5 +563,5 @@ main (int argc, char **argv)
 		g_print ("------------------------------------------------------------\n");
 		
-		g_assert (ok == TRUE);
+		return (ok == TRUE) ? 0 : 1;
         }
 	else
@@ -600,5 +604,5 @@ main (int argc, char **argv)
 		
 		all_ok = get_ok && binget_ok && async1_ok && async2_ok && post_ok && redir1_ok && redir2_ok && urlget_ok;
-		g_assert (all_ok);
+		return all_ok ? 0 : 1;
 	}
 		
