Bugzilla bug #84100: we need to write our own accept method to copy NSPRPUB_RELEASE_4_1_BRANCH
authorwtc%netscape.com
Wed, 20 Jun 2001 00:16:56 +0000
branchNSPRPUB_RELEASE_4_1_BRANCH
changeset 1953 b985a75456f9148c387b284f10f3a12d5d87dbaf
parent 1952 11aae3863affd3ec0e2767605757089274aea66c
child 1954 73b02b8a9962950c493a032c1bdae7a41f695f28
push idunknown
push userunknown
push dateunknown
bugs84100
Bugzilla bug #84100: we need to write our own accept method to copy the PRFilePrivate structure. Tag: NSPRPUB_RELEASE_4_1_BRANCH
pr/tests/nblayer.c
--- a/pr/tests/nblayer.c
+++ b/pr/tests/nblayer.c
@@ -362,16 +362,58 @@ static PRInt16 PR_CALLBACK MyPoll(
     new_flags = (fd->lower->methods->poll)(fd->lower, my_flags, out_flags);
     if (verbosity > chatty)
         PR_fprintf(
             logFile, "Poll [i: 0x%x, m: 0x%x, o: 0x%x, n: 0x%x]\n",
             in_flags, my_flags, *out_flags, new_flags);
     return new_flags;
 }  /* MyPoll */
 
+static PRFileDesc * PR_CALLBACK MyAccept(
+    PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout)
+{
+    PRStatus rv;
+    PRFileDesc *newfd, *layer = fd;
+    PRFileDesc *newstack;
+    PRFilePrivate *newsecret;
+
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    newstack = PR_NEW(PRFileDesc);
+    if (NULL == newstack)
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return NULL;
+    }
+    newsecret = PR_NEW(PRFilePrivate);
+    if (NULL == newsecret)
+    {
+        PR_DELETE(newstack);
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return NULL;
+    }
+    *newstack = *fd;  /* make a copy of the accepting layer */
+    *newsecret = *fd->secret;
+    newstack->secret = newsecret;
+
+    newfd = (fd->lower->methods->accept)(fd->lower, addr, timeout);
+    if (NULL == newfd)
+    {
+        PR_DELETE(newsecret);
+        PR_DELETE(newstack);
+        return NULL;
+    }
+
+    /* this PR_PushIOLayer call cannot fail */
+    rv = PR_PushIOLayer(newfd, PR_TOP_IO_LAYER, newstack);
+    PR_ASSERT(PR_SUCCESS == rv);
+    return newfd;  /* that's it */
+}
+
 static PRInt32 PR_CALLBACK MyRecv(
     PRFileDesc *fd, void *buf, PRInt32 amount,
     PRIntn flags, PRIntervalTime timeout)
 {
     char *b;
     PRInt32 rv;
     PRFileDesc *lo = fd->lower;
     PRFilePrivate *mine = (PRFilePrivate*)fd->secret;
@@ -537,16 +579,17 @@ PRIntn main(PRIntn argc, char **argv)
     stubMethods = PR_GetDefaultIOMethods();
 
     /*
     ** The protocol we're going to implement is one where in order to initiate
     ** a send, the sender must first solicit permission. Therefore, every
     ** send is really a send - receive - send sequence.
     */
     myMethods = *stubMethods;  /* first get the entire batch */
+    myMethods.accept = MyAccept;  /* then override the ones we care about */
     myMethods.recv = MyRecv;  /* then override the ones we care about */
     myMethods.send = MySend;  /* then override the ones we care about */
     myMethods.close = MyClose;  /* then override the ones we care about */
     myMethods.poll = MyPoll;  /* then override the ones we care about */
 
     if (NULL == server_name)
         rv = PR_InitializeNetAddr(
             PR_IpAddrLoopback, default_port, &server_address);