prlayer.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/* ***** BEGIN LICENSE BLOCK *****
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * The contents of this file are subject to the Mozilla Public License Version
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * 1.1 (the "License"); you may not use this file except in compliance with
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * the License. You may obtain a copy of the License at
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * http://www.mozilla.org/MPL/
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Software distributed under the License is distributed on an "AS IS" basis,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * for the specific language governing rights and limitations under the
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * License.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * The Original Code is the Netscape Portable Runtime (NSPR).
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * The Initial Developer of the Original Code is
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Netscape Communications Corporation.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Portions created by the Initial Developer are Copyright (C) 1998-2000
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * the Initial Developer. All Rights Reserved.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Contributor(s):
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Alternatively, the contents of this file may be used under the terms of
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * either the GNU General Public License Version 2 or later (the "GPL"), or
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * in which case the provisions of the GPL or the LGPL are applicable instead
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * of those above. If you wish to allow use of your version of this file only
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * under the terms of either the GPL or the LGPL, and not to allow others to
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * use your version of this file under the terms of the MPL, indicate your
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * decision by deleting the provisions above and replace them with the notice
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * and other provisions required by the GPL or the LGPL. If you do not delete
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * the provisions above, a recipient may use your version of this file under
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * the terms of any one of the MPL, the GPL or the LGPL.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * ***** END LICENSE BLOCK ***** */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb** File: prlayer.c
7b59d02d2a384be9a08087b14defadd214b3c1ddjb** Description: Routines for handling pushable protocol modules on sockets.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb*/
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb#include "primpl.h"
7b59d02d2a384be9a08087b14defadd214b3c1ddjb#include "prerror.h"
7b59d02d2a384be9a08087b14defadd214b3c1ddjb#include "prmem.h"
7b59d02d2a384be9a08087b14defadd214b3c1ddjb#include "prlock.h"
7b59d02d2a384be9a08087b14defadd214b3c1ddjb#include "prlog.h"
7b59d02d2a384be9a08087b14defadd214b3c1ddjb#include "prio.h"
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb#include <string.h> /* for memset() */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus _PR_DestroyIOLayer(PRFileDesc *stack);
91d7f85e02991954d1e1bd44673df567ad8dcc87Gordon Ross
7b59d02d2a384be9a08087b14defadd214b3c1ddjbvoid PR_CALLBACK pl_FDDestructor(PRFileDesc *fd)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (NULL != fd->lower) fd->lower->higher = fd->higher;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (NULL != fd->higher) fd->higher->lower = fd->lower;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_DELETE(fd);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb** Default methods that just call down to the next fd.
7b59d02d2a384be9a08087b14defadd214b3c1ddjb*/
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_TopClose (PRFileDesc *fd)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *top, *lower;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRStatus rv;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->secret == NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->methods->file_type == PR_DESC_LAYERED);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (PR_IO_LAYER_HEAD == fd->identity) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * new style stack; close all the layers, before deleting the
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * stack head
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb rv = fd->lower->methods->close(fd->lower);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb _PR_DestroyIOLayer(fd);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return rv;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb } else if ((fd->higher) && (PR_IO_LAYER_HEAD == fd->higher->identity)) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /*
8d7e41661dc4633488e93b13363137523ce59977jose borrego * lower layers of new style stack
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb lower = fd->lower;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * pop and cleanup current layer
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb top = PR_PopIOLayer(fd->higher, PR_TOP_IO_LAYER);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb top->dtor(top);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * then call lower layer
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (lower->methods->close(lower));
7b59d02d2a384be9a08087b14defadd214b3c1ddjb } else {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* old style stack */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb top = PR_PopIOLayer(fd, PR_TOP_IO_LAYER);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb top->dtor(top);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->methods->close)(fd);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt32 PR_CALLBACK pl_DefRead (PRFileDesc *fd, void *buf, PRInt32 amount)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->read)(fd->lower, buf, amount);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt32 PR_CALLBACK pl_DefWrite (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd, const void *buf, PRInt32 amount)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->write)(fd->lower, buf, amount);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt32 PR_CALLBACK pl_DefAvailable (PRFileDesc *fd)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->available)(fd->lower);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
8d7e41661dc4633488e93b13363137523ce59977jose borregostatic PRInt64 PR_CALLBACK pl_DefAvailable64 (PRFileDesc *fd)
8d7e41661dc4633488e93b13363137523ce59977jose borrego{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_ASSERT(fd->lower != NULL);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return (fd->lower->methods->available64)(fd->lower);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefFsync (PRFileDesc *fd)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->fsync)(fd->lower);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt32 PR_CALLBACK pl_DefSeek (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd, PRInt32 offset, PRSeekWhence how)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->seek)(fd->lower, offset, how);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt64 PR_CALLBACK pl_DefSeek64 (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd, PRInt64 offset, PRSeekWhence how)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->seek64)(fd->lower, offset, how);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefFileInfo (PRFileDesc *fd, PRFileInfo *info)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->fileInfo)(fd->lower, info);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefFileInfo64 (PRFileDesc *fd, PRFileInfo64 *info)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->fileInfo64)(fd->lower, info);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt32 PR_CALLBACK pl_DefWritev (PRFileDesc *fd, const PRIOVec *iov,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRInt32 size, PRIntervalTime timeout)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->writev)(fd->lower, iov, size, timeout);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefConnect (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->connect)(fd->lower, addr, timeout);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefConnectcontinue (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd, PRInt16 out_flags)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->connectcontinue)(fd->lower, out_flags);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRFileDesc* PR_CALLBACK pl_TopAccept (
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PRStatus rv;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *newfd, *layer = fd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *newstack;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRBool newstyle_stack = PR_FALSE;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States /* test for new style stack */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb while (NULL != layer->higher)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb layer = layer->higher;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb newstyle_stack = (PR_IO_LAYER_HEAD == layer->identity) ? PR_TRUE : PR_FALSE;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb newstack = PR_NEW(PRFileDesc);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (NULL == newstack)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return NULL;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *newstack = *fd; /* make a copy of the accepting layer */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb newfd = (fd->lower->methods->accept)(fd->lower, addr, timeout);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (NULL == newfd)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_DELETE(newstack);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return NULL;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (newstyle_stack) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb newstack->lower = newfd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb newfd->higher = newstack;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return newstack;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb } else {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States /* this PR_PushIOLayer call cannot fail */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States rv = PR_PushIOLayer(newfd, PR_TOP_IO_LAYER, newstack);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PR_ASSERT(PR_SUCCESS == rv);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return newfd; /* that's it */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefBind (PRFileDesc *fd, const PRNetAddr *addr)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (fd->lower->methods->bind)(fd->lower, addr);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic PRStatus PR_CALLBACK pl_DefListen (PRFileDesc *fd, PRIntn backlog)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->listen)(fd->lower, backlog);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefShutdown (PRFileDesc *fd, PRIntn how)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PR_ASSERT(fd != NULL);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PR_ASSERT(fd->lower != NULL);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->shutdown)(fd->lower, how);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt32 PR_CALLBACK pl_DefRecv (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd, void *buf, PRInt32 amount,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRIntn flags, PRIntervalTime timeout)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->recv)(
7b59d02d2a384be9a08087b14defadd214b3c1ddjb fd->lower, buf, amount, flags, timeout);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt32 PR_CALLBACK pl_DefSend (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd, const void *buf,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRInt32 amount, PRIntn flags, PRIntervalTime timeout)
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright{
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright PR_ASSERT(fd != NULL);
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright PR_ASSERT(fd->lower != NULL);
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright return (fd->lower->methods->send)(fd->lower, buf, amount, flags, timeout);
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright}
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wrightstatic PRInt32 PR_CALLBACK pl_DefRecvfrom (
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright PRFileDesc *fd, void *buf, PRInt32 amount,
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright{
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright PR_ASSERT(fd != NULL);
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright PR_ASSERT(fd->lower != NULL);
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright return (fd->lower->methods->recvfrom)(
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright fd->lower, buf, amount, flags, addr, timeout);
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright}
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wrightstatic PRInt32 PR_CALLBACK pl_DefSendto (
fc724630b14603e4c1147df68b7bf45f7de7431fAlan Wright PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb const PRNetAddr *addr, PRIntervalTime timeout)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->sendto)(
7b59d02d2a384be9a08087b14defadd214b3c1ddjb fd->lower, buf, amount, flags, addr, timeout);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt16 PR_CALLBACK pl_DefPoll (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->poll)(fd->lower, in_flags, out_flags);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt32 PR_CALLBACK pl_DefAcceptread (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr, void *buf,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRInt32 amount, PRIntervalTime t)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRInt32 nbytes;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PRStatus rv;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *newstack;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *layer = sd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRBool newstyle_stack = PR_FALSE;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(sd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(sd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* test for new style stack */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb while (NULL != layer->higher)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb layer = layer->higher;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb newstyle_stack = (PR_IO_LAYER_HEAD == layer->identity) ? PR_TRUE : PR_FALSE;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States newstack = PR_NEW(PRFileDesc);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (NULL == newstack)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return -1;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *newstack = *sd; /* make a copy of the accepting layer */
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright
29bd28862cfb8abbd3a0f0a4b17e08bbc3652836Alan Wright nbytes = sd->lower->methods->acceptread(
7b59d02d2a384be9a08087b14defadd214b3c1ddjb sd->lower, nd, raddr, buf, amount, t);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (-1 == nbytes)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_DELETE(newstack);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return nbytes;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (newstyle_stack) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb newstack->lower = *nd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (*nd)->higher = newstack;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *nd = newstack;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return nbytes;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb } else {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* this PR_PushIOLayer call cannot fail */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb rv = PR_PushIOLayer(*nd, PR_TOP_IO_LAYER, newstack);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(PR_SUCCESS == rv);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return nbytes;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRInt32 PR_CALLBACK pl_DefTransmitfile (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *sd, PRFileDesc *fd, const void *headers, PRInt32 hlen,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRTransmitFileFlags flags, PRIntervalTime t)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(sd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(sd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return sd->lower->methods->transmitfile(
7b59d02d2a384be9a08087b14defadd214b3c1ddjb sd->lower, fd, headers, hlen, flags, t);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefGetsockname (PRFileDesc *fd, PRNetAddr *addr)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->getsockname)(fd->lower, addr);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefGetpeername (PRFileDesc *fd, PRNetAddr *addr)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->getpeername)(fd->lower, addr);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefGetsocketoption (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd, PRSocketOptionData *data)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (fd->lower->methods->getsocketoption)(fd->lower, data);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbstatic PRStatus PR_CALLBACK pl_DefSetsocketoption (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd, const PRSocketOptionData *data)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
8d7e41661dc4633488e93b13363137523ce59977jose borrego PR_ASSERT(fd != NULL);
8d7e41661dc4633488e93b13363137523ce59977jose borrego PR_ASSERT(fd->lower != NULL);
8d7e41661dc4633488e93b13363137523ce59977jose borrego
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (fd->lower->methods->setsocketoption)(fd->lower, data);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic PRInt32 PR_CALLBACK pl_DefSendfile (
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *sd, PRSendFileData *sfd,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRTransmitFileFlags flags, PRIntervalTime timeout)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(sd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(sd->lower != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return sd->lower->methods->sendfile(
7b59d02d2a384be9a08087b14defadd214b3c1ddjb sd->lower, sfd, flags, timeout);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/* Methods for the top of the stack. Just call down to the next fd. */
8d7e41661dc4633488e93b13363137523ce59977jose borregostatic PRIOMethods pl_methods = {
8d7e41661dc4633488e93b13363137523ce59977jose borrego PR_DESC_LAYERED,
8d7e41661dc4633488e93b13363137523ce59977jose borrego pl_TopClose,
8d7e41661dc4633488e93b13363137523ce59977jose borrego pl_DefRead,
8d7e41661dc4633488e93b13363137523ce59977jose borrego pl_DefWrite,
8d7e41661dc4633488e93b13363137523ce59977jose borrego pl_DefAvailable,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefAvailable64,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefFsync,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefSeek,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefSeek64,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefFileInfo,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefFileInfo64,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefWritev,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States pl_DefConnect,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States pl_TopAccept,
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego pl_DefBind,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States pl_DefListen,
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego pl_DefShutdown,
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego pl_DefRecv,
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego pl_DefSend,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefRecvfrom,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefSendto,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefPoll,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefAcceptread,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefTransmitfile,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefGetsockname,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefGetpeername,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (PRReservedFN)_PR_InvalidInt,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (PRReservedFN)_PR_InvalidInt,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefGetsocketoption,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb pl_DefSetsocketoption,
8d7e41661dc4633488e93b13363137523ce59977jose borrego pl_DefSendfile,
8d7e41661dc4633488e93b13363137523ce59977jose borrego pl_DefConnectcontinue,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (PRReservedFN)_PR_InvalidInt,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (PRReservedFN)_PR_InvalidInt,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (PRReservedFN)_PR_InvalidInt,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (PRReservedFN)_PR_InvalidInt
7b59d02d2a384be9a08087b14defadd214b3c1ddjb};
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbPR_IMPLEMENT(const PRIOMethods*) PR_GetDefaultIOMethods(void)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return &pl_methods;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States} /* PR_GetDefaultIOMethods */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbPR_IMPLEMENT(PRFileDesc*) PR_CreateIOLayerStub(
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRDescIdentity ident, const PRIOMethods *methods)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *fd = NULL;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT((PR_NSPR_IO_LAYER != ident) && (PR_TOP_IO_LAYER != ident));
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if ((PR_NSPR_IO_LAYER == ident) || (PR_TOP_IO_LAYER == ident))
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb else
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb fd = PR_NEWZAP(PRFileDesc);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (NULL == fd)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb else
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego fd->methods = methods;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego fd->dtor = pl_FDDestructor;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego fd->identity = ident;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return fd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} /* PR_CreateIOLayerStub */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb/*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * PR_CreateIOLayer
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * Create a new style stack, where the stack top is a dummy header.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Unlike the old style stacks, the contents of the stack head
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * are not modified when a layer is pushed onto or popped from a new
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * style stack.
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego */
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borregoPR_IMPLEMENT(PRFileDesc*) PR_CreateIOLayer(PRFileDesc *top)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego{
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PRFileDesc *fd = NULL;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego fd = PR_NEWZAP(PRFileDesc);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (NULL == fd)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego else
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States fd->methods = &pl_methods;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb fd->dtor = pl_FDDestructor;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego fd->identity = PR_IO_LAYER_HEAD;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego fd->higher = NULL;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego fd->lower = top;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego top->higher = fd;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States top->lower = NULL;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return fd;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego} /* PR_CreateIOLayer */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego/*
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego * _PR_DestroyIOLayer
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * Delete the stack head of a new style stack.
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego */
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borregostatic PRStatus _PR_DestroyIOLayer(PRFileDesc *stack)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (NULL == stack)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return PR_FAILURE;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States else {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_DELETE(stack);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return PR_SUCCESS;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} /* _PR_DestroyIOLayer */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbPR_IMPLEMENT(PRStatus) PR_PushIOLayer(
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PRFileDesc *stack, PRDescIdentity id, PRFileDesc *fd)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *insert = PR_GetIdentitiesLayer(stack, id);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(fd != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(stack != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(insert != NULL);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(PR_IO_LAYER_HEAD != id);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if ((NULL == stack) || (NULL == fd) || (NULL == insert))
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return PR_FAILURE;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (stack == insert)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* going on top of the stack */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* old-style stack */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc copy = *stack;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *stack = *fd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb *fd = copy;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb fd->higher = stack;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb stack->lower = fd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb stack->higher = NULL;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb } else {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * going somewhere in the middle of the stack for both old and new
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * style stacks, or going on top of stack for new style stack
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb fd->lower = insert;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States fd->higher = insert->higher;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb insert->higher->lower = fd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb insert->higher = fd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return PR_SUCCESS;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbPR_IMPLEMENT(PRFileDesc*) PR_PopIOLayer(PRFileDesc *stack, PRDescIdentity id)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRFileDesc *extract = PR_GetIdentitiesLayer(stack, id);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(0 != id);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(NULL != stack);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(NULL != extract);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if ((NULL == stack) || (0 == id) || (NULL == extract))
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return NULL;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (extract == stack) {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego /* popping top layer of the stack */
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego /* old style stack */
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PRFileDesc copy = *stack;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego extract = stack->lower;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego *stack = *extract;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego *extract = copy;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego stack->higher = NULL;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego } else if ((PR_IO_LAYER_HEAD == stack->identity) &&
7b59d02d2a384be9a08087b14defadd214b3c1ddjb (extract == stack->lower) && (extract->lower == NULL)) {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /*
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * new style stack
7b59d02d2a384be9a08087b14defadd214b3c1ddjb * popping the only layer in the stack; delete the stack too
7b59d02d2a384be9a08087b14defadd214b3c1ddjb */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb stack->lower = NULL;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb _PR_DestroyIOLayer(stack);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb } else {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* for both kinds of stacks */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb extract->lower->higher = extract->higher;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego extract->higher->lower = extract->lower;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego extract->higher = extract->lower = NULL;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return extract;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} /* PR_PopIOLayer */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego#define ID_CACHE_INCREMENT 16
7f667e74610492ddbce8ce60f52ece95d2401949jose borregotypedef struct _PRIdentity_cache
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRLock *ml;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb char **name;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PRIntn length;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRDescIdentity ident;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} _PRIdentity_cache;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesstatic _PRIdentity_cache identity_cache;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
7b59d02d2a384be9a08087b14defadd214b3c1ddjbPR_IMPLEMENT(PRDescIdentity) PR_GetUniqueIdentity(const char *layer_name)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRDescIdentity identity, length;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb char **names = NULL, *name = NULL, **old = NULL;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (!_pr_initialized) _PR_ImplicitInitialization();
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_ASSERT((PRDescIdentity)0x7fff > identity_cache.ident);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (NULL != layer_name)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego name = (char*)PR_Malloc(strlen(layer_name) + 1);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (NULL == name)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return PR_INVALID_IO_LAYER;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb strcpy(name, layer_name);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
7b59d02d2a384be9a08087b14defadd214b3c1ddjb /* this initial code runs unsafe */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbretry:
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_ASSERT(NULL == names);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego length = identity_cache.length;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (length < (identity_cache.ident + 1))
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb length += ID_CACHE_INCREMENT;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States names = (char**)PR_CALLOC(length * sizeof(char*));
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (NULL == names)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (NULL != name) PR_DELETE(name);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return PR_INVALID_IO_LAYER;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego /* now we get serious about thread safety */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PR_Lock(identity_cache.ml);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_ASSERT(identity_cache.ident <= identity_cache.length);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb identity = identity_cache.ident + 1;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (identity > identity_cache.length) /* there's no room */
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego /* we have to do something - hopefully it's already done */
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if ((NULL != names) && (length >= identity))
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego /* what we did is still okay */
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego memcpy(
7b59d02d2a384be9a08087b14defadd214b3c1ddjb names, identity_cache.name,
7b59d02d2a384be9a08087b14defadd214b3c1ddjb identity_cache.length * sizeof(char*));
7b59d02d2a384be9a08087b14defadd214b3c1ddjb old = identity_cache.name;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego identity_cache.name = names;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego identity_cache.length = length;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego names = NULL;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego else
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_ASSERT(identity_cache.ident <= identity_cache.length);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_Unlock(identity_cache.ml);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (NULL != names) PR_DELETE(names);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego goto retry;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (NULL != name) /* there's a name to be stored */
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb identity_cache.name[identity] = name;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb identity_cache.ident = identity;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_ASSERT(identity_cache.ident <= identity_cache.length);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_Unlock(identity_cache.ml);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (NULL != old) PR_DELETE(old);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (NULL != names) PR_DELETE(names);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return identity;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} /* PR_GetUniqueIdentity */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
7b59d02d2a384be9a08087b14defadd214b3c1ddjbPR_IMPLEMENT(const char*) PR_GetNameForIdentity(PRDescIdentity ident)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (!_pr_initialized) _PR_ImplicitInitialization();
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (PR_TOP_IO_LAYER == ident) return NULL;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_ASSERT(ident <= identity_cache.ident);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return (ident > identity_cache.ident) ? NULL : identity_cache.name[ident];
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} /* PR_GetNameForIdentity */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
7b59d02d2a384be9a08087b14defadd214b3c1ddjbPR_IMPLEMENT(PRDescIdentity) PR_GetLayersIdentity(PRFileDesc* fd)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_ASSERT(NULL != fd);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (PR_IO_LAYER_HEAD == fd->identity) {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PR_ASSERT(NULL != fd->lower);
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return fd->lower->identity;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego } else
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return fd->identity;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego} /* PR_GetLayersIdentity */
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borregoPR_IMPLEMENT(PRFileDesc*) PR_GetIdentitiesLayer(PRFileDesc* fd, PRDescIdentity id)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego{
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego PRFileDesc *layer = fd;
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (PR_TOP_IO_LAYER == id) {
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego if (PR_IO_LAYER_HEAD == fd->identity)
7f667e74610492ddbce8ce60f52ece95d2401949jose borrego return fd->lower;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb else
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return fd;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb for (layer = fd; layer != NULL; layer = layer->lower)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (id == layer->identity) return layer;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb for (layer = fd; layer != NULL; layer = layer->higher)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (id == layer->identity) return layer;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb return NULL;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} /* PR_GetIdentitiesLayer */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
7b59d02d2a384be9a08087b14defadd214b3c1ddjbvoid _PR_InitLayerCache(void)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb memset(&identity_cache, 0, sizeof(identity_cache));
7b59d02d2a384be9a08087b14defadd214b3c1ddjb identity_cache.ml = PR_NewLock();
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PR_ASSERT(NULL != identity_cache.ml);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} /* _PR_InitLayerCache */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjbvoid _PR_CleanupLayerCache(void)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb{
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (identity_cache.ml)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_DestroyLock(identity_cache.ml);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States identity_cache.ml = NULL;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (identity_cache.name)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb {
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PRDescIdentity ident;
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
7b59d02d2a384be9a08087b14defadd214b3c1ddjb for (ident = 0; ident <= identity_cache.ident; ident++)
7b59d02d2a384be9a08087b14defadd214b3c1ddjb PR_DELETE(identity_cache.name[ident]);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States PR_DELETE(identity_cache.name);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb }
7b59d02d2a384be9a08087b14defadd214b3c1ddjb} /* _PR_CleanupLayerCache */
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States/* prlayer.c */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States