diff options
author | wtc%netscape.com <devnull@localhost> | 2001-06-05 04:31:20 +0000 |
---|---|---|
committer | wtc%netscape.com <devnull@localhost> | 2001-06-05 04:31:20 +0000 |
commit | 48d1de3ad7396cf7f1631293ffc96a543f1f18d0 (patch) | |
tree | 11bdee7e8613e730eb9c125d5d707921789f1216 /pr/tests | |
parent | c94e765f3c6aad4ce3b2f19fe8a0b6219b895bc8 (diff) | |
download | nspr-hg-48d1de3ad7396cf7f1631293ffc96a543f1f18d0.tar.gz |
Bugzilla bug #84100: we need to write our own accept method to copy
the PRFilePrivate structure.
Diffstat (limited to 'pr/tests')
-rw-r--r-- | pr/tests/nblayer.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/pr/tests/nblayer.c b/pr/tests/nblayer.c index db665e4f..15972cf4 100644 --- a/pr/tests/nblayer.c +++ b/pr/tests/nblayer.c @@ -367,6 +367,48 @@ static PRInt16 PR_CALLBACK MyPoll( 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) @@ -542,6 +584,7 @@ PRIntn main(PRIntn argc, char **argv) ** 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 */ |