VirtualBox

Changeset 101884 in vbox


Ignore:
Timestamp:
Nov 6, 2023 5:52:00 PM (15 months ago)
Author:
vboxsync
Message:

libs/xpcom: Remove unused code from nsprpub, bugref:10545

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/nsprpub/pr/src/io/prlayer.c

    r101872 r101884  
    4949
    5050#include <string.h> /* for memset() */
    51 static PRStatus _PR_DestroyIOLayer(PRFileDesc *stack);
    5251
    5352void PR_CALLBACK pl_FDDestructor(PRFileDesc *fd)
     
    5958}
    6059
    61 /*
    62 ** Default methods that just call down to the next fd.
    63 */
    64 static PRStatus PR_CALLBACK pl_TopClose (PRFileDesc *fd)
    65 {
    66     PRFileDesc *top, *lower;
    67         PRStatus rv;
    68 
    69     PR_ASSERT(fd != NULL);
    70     PR_ASSERT(fd->lower != NULL);
    71     PR_ASSERT(fd->secret == NULL);
    72     PR_ASSERT(fd->methods->file_type == PR_DESC_LAYERED);
    73 
    74         if (PR_IO_LAYER_HEAD == fd->identity) {
    75                 /*
    76                  * new style stack; close all the layers, before deleting the
    77                  * stack head
    78                  */
    79                 rv = fd->lower->methods->close(fd->lower);
    80                 _PR_DestroyIOLayer(fd);
    81                 return rv;
    82         } else if ((fd->higher) && (PR_IO_LAYER_HEAD == fd->higher->identity)) {
    83                 /*
    84                  * lower layers of new style stack
    85                  */
    86                 lower = fd->lower;
    87                 /*
    88                  * pop and cleanup current layer
    89                  */
    90         top = PR_PopIOLayer(fd->higher, PR_TOP_IO_LAYER);
    91                 top->dtor(top);
    92                 /*
    93                  * then call lower layer
    94                  */
    95                 return (lower->methods->close(lower));
    96         } else {
    97                 /* old style stack */
    98         top = PR_PopIOLayer(fd, PR_TOP_IO_LAYER);
    99                 top->dtor(top);
    100                 return (fd->methods->close)(fd);
    101         }
    102 }
    103 
    104 static PRInt32 PR_CALLBACK pl_DefRead (PRFileDesc *fd, void *buf, PRInt32 amount)
    105 {
    106     PR_ASSERT(fd != NULL);
    107     PR_ASSERT(fd->lower != NULL);
    108 
    109     return (fd->lower->methods->read)(fd->lower, buf, amount);
    110 }
    111 
    112 static PRInt32 PR_CALLBACK pl_DefWrite (
    113     PRFileDesc *fd, const void *buf, PRInt32 amount)
    114 {
    115     PR_ASSERT(fd != NULL);
    116     PR_ASSERT(fd->lower != NULL);
    117 
    118     return (fd->lower->methods->write)(fd->lower, buf, amount);
    119 }
    120 
    121 static PRInt32 PR_CALLBACK pl_DefAvailable (PRFileDesc *fd)
    122 {
    123     PR_ASSERT(fd != NULL);
    124     PR_ASSERT(fd->lower != NULL);
    125 
    126     return (fd->lower->methods->available)(fd->lower);
    127 }
    128 
    129 static PRStatus PR_CALLBACK pl_DefFsync (PRFileDesc *fd)
    130 {
    131     PR_ASSERT(fd != NULL);
    132     PR_ASSERT(fd->lower != NULL);
    133 
    134     return (fd->lower->methods->fsync)(fd->lower);
    135 }
    136 
    137 static PRInt32 PR_CALLBACK pl_DefSeek (
    138     PRFileDesc *fd, PRInt32 offset, PRSeekWhence how)
    139 {
    140     PR_ASSERT(fd != NULL);
    141     PR_ASSERT(fd->lower != NULL);
    142 
    143     return (fd->lower->methods->seek)(fd->lower, offset, how);
    144 }
    145 
    146 static PRInt64 PR_CALLBACK pl_DefSeek64 (
    147     PRFileDesc *fd, PRInt64 offset, PRSeekWhence how)
    148 {
    149     PR_ASSERT(fd != NULL);
    150     PR_ASSERT(fd->lower != NULL);
    151 
    152     return (fd->lower->methods->seek64)(fd->lower, offset, how);
    153 }
    154 
    155 static PRStatus PR_CALLBACK pl_DefFileInfo (PRFileDesc *fd, PRFileInfo *info)
    156 {
    157     PR_ASSERT(fd != NULL);
    158     PR_ASSERT(fd->lower != NULL);
    159 
    160     return (fd->lower->methods->fileInfo)(fd->lower, info);
    161 }
    162 
    163 static PRStatus PR_CALLBACK pl_DefFileInfo64 (PRFileDesc *fd, PRFileInfo64 *info)
    164 {
    165     PR_ASSERT(fd != NULL);
    166     PR_ASSERT(fd->lower != NULL);
    167 
    168     return (fd->lower->methods->fileInfo64)(fd->lower, info);
    169 }
    170 
    171 static PRInt32 PR_CALLBACK pl_DefWritev (PRFileDesc *fd, const PRIOVec *iov,
    172     PRInt32 size, PRIntervalTime timeout)
    173 {
    174     PR_ASSERT(fd != NULL);
    175     PR_ASSERT(fd->lower != NULL);
    176 
    177     return (fd->lower->methods->writev)(fd->lower, iov, size, timeout);
    178 }
    179 
    180 static PRStatus PR_CALLBACK pl_DefConnect (
    181     PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
    182 {
    183     PR_ASSERT(fd != NULL);
    184     PR_ASSERT(fd->lower != NULL);
    185 
    186     return (fd->lower->methods->connect)(fd->lower, addr, timeout);
    187 }
    188 
    189 static PRStatus PR_CALLBACK pl_DefConnectcontinue (
    190     PRFileDesc *fd, PRInt16 out_flags)
    191 {
    192     PR_ASSERT(fd != NULL);
    193     PR_ASSERT(fd->lower != NULL);
    194 
    195     return (fd->lower->methods->connectcontinue)(fd->lower, out_flags);
    196 }
    197 
    198 static PRFileDesc* PR_CALLBACK pl_TopAccept (
    199     PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout)
    200 {
    201     PRStatus rv;
    202     PRFileDesc *newfd, *layer = fd;
    203     PRFileDesc *newstack;
    204         PRBool newstyle_stack = PR_FALSE;
    205 
    206     PR_ASSERT(fd != NULL);
    207     PR_ASSERT(fd->lower != NULL);
    208 
    209         /* test for new style stack */
    210         while (NULL != layer->higher)
    211                 layer = layer->higher;
    212         newstyle_stack = (PR_IO_LAYER_HEAD == layer->identity) ? PR_TRUE : PR_FALSE;
    213     newstack = PR_NEW(PRFileDesc);
    214     if (NULL == newstack)
    215     {
    216         PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
    217         return NULL;
    218     }
    219     *newstack = *fd;  /* make a copy of the accepting layer */
    220 
    221     newfd = (fd->lower->methods->accept)(fd->lower, addr, timeout);
    222     if (NULL == newfd)
    223     {
    224         PR_DELETE(newstack);
    225         return NULL;
    226     }
    227 
    228     if (newstyle_stack) {
    229                 newstack->lower = newfd;
    230                 newfd->higher = newstack;
    231                 return newstack;
    232         } else {
    233                 /* this PR_PushIOLayer call cannot fail */
    234                 rv = PR_PushIOLayer(newfd, PR_TOP_IO_LAYER, newstack);
    235                 PR_ASSERT(PR_SUCCESS == rv);
    236         return newfd;  /* that's it */
    237         }
    238 }
    239 
    240 static PRStatus PR_CALLBACK pl_DefBind (PRFileDesc *fd, const PRNetAddr *addr)
    241 {
    242     PR_ASSERT(fd != NULL);
    243     PR_ASSERT(fd->lower != NULL);
    244 
    245     return (fd->lower->methods->bind)(fd->lower, addr);
    246 }
    247 
    248 static PRStatus PR_CALLBACK pl_DefListen (PRFileDesc *fd, PRIntn backlog)
    249 {
    250     PR_ASSERT(fd != NULL);
    251     PR_ASSERT(fd->lower != NULL);
    252 
    253     return (fd->lower->methods->listen)(fd->lower, backlog);
    254 }
    255 
    256 static PRStatus PR_CALLBACK pl_DefShutdown (PRFileDesc *fd, PRIntn how)
    257 {
    258     PR_ASSERT(fd != NULL);
    259     PR_ASSERT(fd->lower != NULL);
    260 
    261     return (fd->lower->methods->shutdown)(fd->lower, how);
    262 }
    263 
    264 static PRInt32 PR_CALLBACK pl_DefRecv (
    265     PRFileDesc *fd, void *buf, PRInt32 amount,
    266     PRIntn flags, PRIntervalTime timeout)
    267 {
    268     PR_ASSERT(fd != NULL);
    269     PR_ASSERT(fd->lower != NULL);
    270 
    271     return (fd->lower->methods->recv)(
    272         fd->lower, buf, amount, flags, timeout);
    273 }
    274 
    275 static PRInt32 PR_CALLBACK pl_DefSend (
    276     PRFileDesc *fd, const void *buf,
    277     PRInt32 amount, PRIntn flags, PRIntervalTime timeout)
    278 {
    279     PR_ASSERT(fd != NULL);
    280     PR_ASSERT(fd->lower != NULL);
    281 
    282     return (fd->lower->methods->send)(fd->lower, buf, amount, flags, timeout);
    283 }
    284 
    285 static PRInt16 PR_CALLBACK pl_DefPoll (
    286     PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags)
    287 {
    288     PR_ASSERT(fd != NULL);
    289     PR_ASSERT(fd->lower != NULL);
    290 
    291     return (fd->lower->methods->poll)(fd->lower, in_flags, out_flags);
    292 }
    293 
    294 static PRStatus PR_CALLBACK pl_DefGetsockname (PRFileDesc *fd, PRNetAddr *addr)
    295 {
    296     PR_ASSERT(fd != NULL);
    297     PR_ASSERT(fd->lower != NULL);
    298 
    299     return (fd->lower->methods->getsockname)(fd->lower, addr);
    300 }
    301 
    302 static PRStatus PR_CALLBACK pl_DefGetpeername (PRFileDesc *fd, PRNetAddr *addr)
    303 {
    304     PR_ASSERT(fd != NULL);
    305     PR_ASSERT(fd->lower != NULL);
    306 
    307     return (fd->lower->methods->getpeername)(fd->lower, addr);
    308 }
    309 
    310 static PRStatus PR_CALLBACK pl_DefGetsocketoption (
    311     PRFileDesc *fd, PRSocketOptionData *data)
    312 {
    313     PR_ASSERT(fd != NULL);
    314     PR_ASSERT(fd->lower != NULL);
    315 
    316     return (fd->lower->methods->getsocketoption)(fd->lower, data);
    317 }
    318 
    319 static PRStatus PR_CALLBACK pl_DefSetsocketoption (
    320     PRFileDesc *fd, const PRSocketOptionData *data)
    321 {
    322     PR_ASSERT(fd != NULL);
    323     PR_ASSERT(fd->lower != NULL);
    324 
    325     return (fd->lower->methods->setsocketoption)(fd->lower, data);
    326 }
    327 
    328 /* Methods for the top of the stack.  Just call down to the next fd. */
    329 static PRIOMethods pl_methods = {
    330     PR_DESC_LAYERED,
    331     pl_TopClose,
    332     pl_DefRead,
    333     pl_DefWrite,
    334     pl_DefAvailable,
    335     pl_DefFsync,
    336     pl_DefSeek,
    337     pl_DefSeek64,
    338     pl_DefFileInfo,
    339     pl_DefFileInfo64,
    340     pl_DefWritev,
    341     pl_DefConnect,
    342     pl_TopAccept,
    343     pl_DefBind,
    344     pl_DefListen,
    345     pl_DefShutdown,
    346     pl_DefRecv,
    347     pl_DefSend,
    348     pl_DefPoll,
    349     pl_DefGetsockname,
    350     pl_DefGetpeername,
    351     (PRReservedFN)_PR_InvalidInt,
    352     (PRReservedFN)_PR_InvalidInt,
    353     pl_DefGetsocketoption,
    354     pl_DefSetsocketoption,
    355     pl_DefConnectcontinue,
    356     (PRReservedFN)_PR_InvalidInt,
    357     (PRReservedFN)_PR_InvalidInt,
    358     (PRReservedFN)_PR_InvalidInt,
    359     (PRReservedFN)_PR_InvalidInt
    360 };
    361 
    362 PR_IMPLEMENT(const PRIOMethods*) PR_GetDefaultIOMethods(void)
    363 {
    364     return &pl_methods;
    365 }  /* PR_GetDefaultIOMethods */
    366 
    36760PR_IMPLEMENT(PRFileDesc*) PR_CreateIOLayerStub(
    36861    PRDescIdentity ident, const PRIOMethods *methods)
     
    38679    return fd;
    38780}  /* PR_CreateIOLayerStub */
    388 
    389 /*
    390  * PR_CreateIOLayer
    391  *              Create a new style stack, where the stack top is a dummy header.
    392  *              Unlike the old style stacks, the contents of the stack head
    393  *              are not modified when a layer is pushed onto or popped from a new
    394  *              style stack.
    395  */
    396 
    397 PR_IMPLEMENT(PRFileDesc*) PR_CreateIOLayer(PRFileDesc *top)
    398 {
    399     PRFileDesc *fd = NULL;
    400 
    401         fd = PR_NEWZAP(PRFileDesc);
    402         if (NULL == fd)
    403                 PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
    404         else
    405         {
    406                 fd->methods = &pl_methods;
    407                 fd->dtor = pl_FDDestructor;
    408                 fd->identity = PR_IO_LAYER_HEAD;
    409                 fd->higher = NULL;
    410                 fd->lower = top;
    411                 top->higher = fd;
    412                 top->lower = NULL;
    413         }
    414     return fd;
    415 }  /* PR_CreateIOLayer */
    41681
    41782/*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette