harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r722955 - /harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c
Date Wed, 03 Dec 2008 16:20:06 GMT
Author: tellison
Date: Wed Dec  3 08:20:05 2008
New Revision: 722955

URL: http://svn.apache.org/viewvc?rev=722955&view=rev
Log:
Code tidy-up for readability.  Functionally equivalent.

Modified:
    harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c

Modified: harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c?rev=722955&r1=722954&r2=722955&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/portlib/src/main/native/port/windows/hysock.c
Wed Dec  3 08:20:05 2008
@@ -748,143 +748,129 @@
 /* IPv6 - we may have more than one open socket at this point, an IPv6 and an IPv4.  Now
  * that we are connect to a specific address we can determine whether to use the IPv4
  * or IPv6 address and close the other address.
- *
  */
 I_32 VMCALL
-hysock_connect (struct HyPortLibrary * portLibrary, hysocket_t sock,
-		hysockaddr_t addr)
+hysock_connect (struct HyPortLibrary * portLibrary, hysocket_t sock, hysockaddr_t addr)
 {
   I_32 rc = 0;
   DWORD socketType;
-  int socketTypeLen = sizeof (DWORD);
+  int socketTypeLen = sizeof(DWORD);
   byte nAddrBytes[HYSOCK_INADDR6_LEN];
 
-  /* get the socket type, it should be the same for both sockets and one of the two should
be open */
-  if (sock->flags & SOCKET_IPV4_OPEN_MASK)
-    {
-      if (getsockopt
-	  (sock->ipv4, SOL_SOCKET, SO_TYPE, (char *) &socketType,
-	   &socketTypeLen) == SOCKET_ERROR)
-	{
-	  rc = WSAGetLastError ();
-	  return portLibrary->error_set_last_error (portLibrary, rc,
-						    findError (rc));
-	}
+  /* Get the socket type.  It should be the same for both sockets
+   * and one of the two should be open.
+   */
+  if (sock->flags & SOCKET_IPV4_OPEN_MASK) {
+    if (getsockopt(sock->ipv4, SOL_SOCKET, SO_TYPE,
+          (char *) &socketType, &socketTypeLen) == SOCKET_ERROR) {
+      rc = WSAGetLastError();
+      return portLibrary->error_set_last_error(portLibrary, rc, findError(rc));
     }
-  else
-    {
-      if (getsockopt
-	  (sock->ipv6, SOL_SOCKET, SO_TYPE, (char *) &socketType,
-	   &socketTypeLen) == SOCKET_ERROR)
-	{
-	  rc = WSAGetLastError ();
-	  return portLibrary->error_set_last_error (portLibrary, rc,
-						    findError (rc));
-	}
+  } else {
+    if (getsockopt(sock->ipv6, SOL_SOCKET, SO_TYPE,
+        (char *) &socketType, &socketTypeLen) == SOCKET_ERROR) {
+      rc = WSAGetLastError();
+      return portLibrary->error_set_last_error(portLibrary, rc, findError(rc));
     }
+  }
 
-  /* here we need to do the connect based on the type of addressed passed in as well as the
sockets which are open. If 
-     a socket with a type that matches the type of the address passed in is open then we
use that one.  Otherwise we
-     use the socket that is open */
+  /* Here we need to do the connect based on the type of address
+   * passed in as well as the sockets which are open.
+   * If a socket with a type that matches the type of the address
+   * passed in is open then we use that one.  Otherwise we use the
+   * socket that is open.
+   */
   if (((((OSSOCKADDR *) & addr->addr)->sin_family != OS_AF_UNSPEC) &&
-       ((((OSSOCKADDR *) & addr->addr)->sin_family == OS_AF_INET4) ||
-	!(sock->flags & SOCKET_IPV6_OPEN_MASK)) &&
-       (sock->flags & SOCKET_IPV4_OPEN_MASK)))
-    {
-      rc =
-	connect (sock->ipv4, (const struct sockaddr FAR *) &addr->addr,
-		 sizeof (addr->addr));
-      if (socketType != SOCK_DGRAM)
-	{
-	  internalCloseSocket (portLibrary, sock, FALSE);
-	}
-      else
-	{
-	  /* we don't acutally want to close the sockets as connect can be called again on a datagram
socket  but we 
-	     still need to set the flag that tells us which socket to use */
-	  sock->flags = sock->flags | SOCKET_USE_IPV4_MASK;
-	}
-    }
-  else if (((OSSOCKADDR *) & addr->addr)->sin_family == OS_AF_INET6)
-    {
-      rc =
-	connect (sock->ipv6, (const struct sockaddr FAR *) &addr->addr,
-		 sizeof (addr->addr));
-      if (socketType != SOCK_DGRAM)
-	{
-	  internalCloseSocket (portLibrary, sock, TRUE);
-	}
-      else
-	{
-	  /* we don't acutally want to close the sockets as connect can be called again on a datagram
socket  but we 
-	     still need to set the flag that tells us which socket to use. */
-	  sock->flags = sock->flags & ~SOCKET_USE_IPV4_MASK;
-	}
-    }
-  else
-    {
-      if (socketType != SOCK_DGRAM)
-	{
-	  /* this should never occur */
-	  return HYPORT_ERROR_SOCKET_BADAF;
-	}
+      ((((OSSOCKADDR *) & addr->addr)->sin_family == OS_AF_INET4) ||
+      !(sock->flags & SOCKET_IPV6_OPEN_MASK)) &&
+       (sock->flags & SOCKET_IPV4_OPEN_MASK))) {
 
-      /* for windows it seems to want to have it connect with an IN_ADDR any instead of with
an 
-         UNSPEC familty type so lets be accomodating */
+    rc = connect(sock->ipv4, (const struct sockaddr FAR *) &addr->addr,
+                 sizeof (addr->addr));
 
-      /* we need to disconnect on both sockets and swallow any expected errors */
-      memset (nAddrBytes, 0, HYSOCK_INADDR6_LEN);
-      if (sock->flags & SOCKET_IPV4_OPEN_MASK)
-	{
-	  hysock_sockaddr_init6 (portLibrary, addr, (U_8 *) nAddrBytes,
-				 HYSOCK_INADDR_LEN, HYADDR_FAMILY_AFINET4, 0,
-				 0, 0, sock);
-	  rc =
-	    connect (sock->ipv4, (const struct sockaddr FAR *) &addr->addr,
-		     sizeof (addr->addr));
-	}
-
-      /* filter out acceptable errors */
-      if (rc == SOCKET_ERROR)
-	{
-	  rc = WSAGetLastError ();
-	  if (rc == WSAEAFNOSUPPORT || rc == WSAEADDRNOTAVAIL)
-	    {
-	      rc = 0;
-	    }
-	}
+    if (socketType != SOCK_DGRAM) {
+      internalCloseSocket(portLibrary, sock, FALSE);
+    } else {
+      /* We don't acutally want to close the sockets as connect can
+       * be called again on a datagram socket  but we still need to
+       * set the flag that tells us which socket to use.
+       */
+      sock->flags = sock->flags | SOCKET_USE_IPV4_MASK;
+    }
+  } else if (((OSSOCKADDR *) & addr->addr)->sin_family == OS_AF_INET6) {
+    rc = connect(sock->ipv6, (const struct sockaddr FAR *) &addr->addr,
+                 sizeof (addr->addr));
+    if (socketType != SOCK_DGRAM) {
+      internalCloseSocket(portLibrary, sock, TRUE);
+    } else {
+      /* We don't acutally want to close the sockets as connect can
+       * be called again on a datagram socket  but we still need to
+       * set the flag that tells us which socket to use.
+       */
+      sock->flags = sock->flags & ~SOCKET_USE_IPV4_MASK;
+    }
+  } else {
+    if (socketType != SOCK_DGRAM) {
+      /* This should never occur. */
+      return HYPORT_ERROR_SOCKET_BADAF;
+    }
+
+    /* For windows it seems to want to have it connect with an
+     * IN_ADDR any instead of with an UNSPEC family type, so
+     * lets be accommodating.
+     */
+
+    /* We need to connect on both sockets and swallow any
+     * expected errors.
+     */
+    memset(nAddrBytes, 0, HYSOCK_INADDR6_LEN);
+    if (sock->flags & SOCKET_IPV4_OPEN_MASK) {
+      hysock_sockaddr_init6(portLibrary, addr, (U_8 *) nAddrBytes,
+                            HYSOCK_INADDR_LEN, HYADDR_FAMILY_AFINET4,
+                            0, 0, 0, sock);
+      rc = connect(sock->ipv4, (const struct sockaddr FAR *) &addr->addr,
+                   sizeof (addr->addr));
+    }
+
+    /* Filter out acceptable errors */
+    if (rc == SOCKET_ERROR) {
+      rc = WSAGetLastError();
+      if (rc == WSAEAFNOSUPPORT || rc == WSAEADDRNOTAVAIL) {
+        rc = 0;
+      }
+    }
 
-      if (rc == 0 && sock->flags & SOCKET_IPV6_OPEN_MASK)
-	{
-	  hysock_sockaddr_init6 (portLibrary, addr, (U_8 *) nAddrBytes,
-				 HYSOCK_INADDR_LEN, HYADDR_FAMILY_AFINET6, 0,
-				 0, 0, sock);
-	  connect (sock->ipv6, (const struct sockaddr FAR *) &addr->addr,
-		   sizeof (addr->addr));
-	}
+    if (rc == 0 && sock->flags & SOCKET_IPV6_OPEN_MASK) {
+      hysock_sockaddr_init6(portLibrary, addr, (U_8 *) nAddrBytes,
+                            HYSOCK_INADDR_LEN, HYADDR_FAMILY_AFINET6,
+                              0, 0, 0, sock);
+      connect(sock->ipv6, (const struct sockaddr FAR *) &addr->addr,
+              sizeof (addr->addr));
     }
+  }
 
-  if (rc == SOCKET_ERROR)
-    {
-      rc = WSAGetLastError ();
-      HYSOCKDEBUG ("<connect failed, err=%d>\n", rc);
-      switch (rc)
-	{
-	case WSAEINVAL:
-	  return portLibrary->error_set_last_error (portLibrary, rc,
-						    HYPORT_ERROR_SOCKET_ALREADYBOUND);
-	case WSAEAFNOSUPPORT:
-	  /* if it is a SOCK_DGRAM this is ok as posix says this may be returned when disconnecting
*/
-	  if (socketType == SOCK_DGRAM)
-	    {
-	      return 0;
-	    }
-	  /* no break here as default is what we want if we do not return above */
-	default:
-	  return portLibrary->error_set_last_error (portLibrary, rc,
-						    findError (rc));
-	}
+  if (rc == SOCKET_ERROR) {
+    rc = WSAGetLastError();
+    HYSOCKDEBUG ("<connect failed, err=%d>\n", rc);
+    switch (rc) {
+      case WSAEINVAL :
+        return portLibrary->error_set_last_error(
+          portLibrary, rc, HYPORT_ERROR_SOCKET_ALREADYBOUND);
+      case WSAEAFNOSUPPORT :
+        /* If it is a SOCK_DGRAM this is ok as posix says
+         * this may be returned when disconnecting.
+         */
+        if (socketType == SOCK_DGRAM) {
+          return 0;
+        }
+        /* No break here as default is what we want if we
+         * do not return above.
+         */
+     default :
+       return portLibrary->error_set_last_error(
+         portLibrary, rc, findError(rc));
     }
+  }
   return rc;
 }
 



Mime
View raw message