Bug 134099: Worked around two BeOS bugs. 1. connect does not implicitly NSPRPUB_PRE_4_2_CLIENT_BRANCH
authorwtc%netscape.com
Tue, 11 Jun 2002 20:08:10 +0000
branchNSPRPUB_PRE_4_2_CLIENT_BRANCH
changeset 2380 2bf1053be6c06e7edff19b6bcd5dfa2c4ae2f5cb
parent 2376 cab24bf314f22793d7e3ec1f4e8a7fa7dde97c0c
child 2381 7363f40bdf2db99fbba7ff55625551d11a45730e
push idunknown
push userunknown
push dateunknown
bugs134099
Bug 134099: Worked around two BeOS bugs. 1. connect does not implicitly bind the socket. 2. accept does not return the peer's address. Modified files: _beos.h prsocket.c bnet.c Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
pr/include/md/_beos.h
pr/src/io/prsocket.c
pr/src/md/beos/bnet.c
--- a/pr/include/md/_beos.h
+++ b/pr/include/md/_beos.h
@@ -86,16 +86,17 @@
 
 #define HAVE_CVAR_BUILT_ON_SEM
 #define _PR_GLOBAL_THREADS_ONLY
 #define _PR_BTHREADS
 #define _PR_NEED_FAKE_POLL
 #define _PR_HAVE_PEEK_BUFFER
 #define _PR_PEEK_BUFFER_MAX (16 * 1024)
 #define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) 1
+#define _PR_CONNECT_DOES_NOT_BIND
 
 /* Define threading functions and objects as native BeOS */
 struct _MDThread {
     thread_id	tid;	/* BeOS thread handle */
 	sem_id		joinSem;	/* sems used to synchronzie joining */
 	PRBool	is_joining;	/* TRUE if someone is currently waiting to
 						   join this thread */
 };
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -1511,16 +1511,27 @@ failed:
     port = ntohs(selfAddr.inet.port);
     if (PR_Listen(listenSock, 5) == PR_FAILURE) {
         goto failed;
     }
     f[0] = PR_NewTCPSocket();
     if (f[0] == NULL) {
         goto failed;
     }
+#ifdef _PR_CONNECT_DOES_NOT_BIND
+    /*
+     * If connect does not implicitly bind the socket (e.g., on
+     * BeOS), we have to bind the socket so that we can get its
+     * port with getsockname later.
+     */
+    PR_InitializeNetAddr(PR_IpAddrLoopback, 0, &selfAddr);
+    if (PR_Bind(f[0], &selfAddr) == PR_FAILURE) {
+        goto failed;
+    }
+#endif
     PR_InitializeNetAddr(PR_IpAddrLoopback, port, &selfAddr);
 
     /*
      * Only a thread is used to do the connect and accept.
      * I am relying on the fact that PR_Connect returns
      * successfully as soon as the connect request is put
      * into the listen queue (but before PR_Accept is called).
      * This is the behavior of the BSD socket code.  If
--- a/pr/src/md/beos/bnet.c
+++ b/pr/src/md/beos/bnet.c
@@ -486,26 +486,26 @@ PRInt32
         } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
             continue;
         } else {
             break;
         }
     }
     if (rv < 0) {
         _PR_MD_MAP_ACCEPT_ERROR(err);
+    } else if (addr != NULL) {
+        /* bug 134099 */
+        err = getpeername(rv, (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
     }
 done:
 #ifdef _PR_HAVE_SOCKADDR_LEN
     if (rv != -1) {
         /* Mask off the first byte of struct sockaddr (the length field) */
         if (addr) {
             addr->raw.family = ((struct sockaddr *) addr)->sa_family;
-#ifdef IS_LITTLE_ENDIAN
-            addr->raw.family = ntohs(addr->raw.family);
-#endif
         }
     }
 #endif /* _PR_HAVE_SOCKADDR_LEN */
     return(rv);
 }
 
 PRInt32
 _MD_connect (PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,