Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
prsocket.c File Reference
#include "primpl.h"
#include <string.h>
#include "obsolete/probslet.h"

Go to the source code of this file.

Defines

#define LOCAL_MAXIOV   8
#define PD_INCR   20

Functions

static PRInt32 PR_CALLBACK SocketWritev (PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTime timeout)
 PR_IMPLEMENT (PRFileDesc *)
static const PRIOMethodsPR_GetSocketPollFdMethods (void)
 PR_IMPLEMENT (PRStatus)
static PRStatus PR_CALLBACK SocketConnect (PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
static PRStatus PR_CALLBACK SocketConnectContinue (PRFileDesc *fd, PRInt16 out_flags)
static PRFileDesc *PR_CALLBACK SocketAccept (PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout)
static PRStatus PR_CALLBACK SocketBind (PRFileDesc *fd, const PRNetAddr *addr)
static PRStatus PR_CALLBACK SocketListen (PRFileDesc *fd, PRIntn backlog)
static PRStatus PR_CALLBACK SocketShutdown (PRFileDesc *fd, PRIntn how)
static PRInt32 PR_CALLBACK SocketRecv (PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PRIntervalTime timeout)
static PRInt32 PR_CALLBACK SocketRead (PRFileDesc *fd, void *buf, PRInt32 amount)
static PRInt32 PR_CALLBACK SocketSend (PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, PRIntervalTime timeout)
static PRInt32 PR_CALLBACK SocketWrite (PRFileDesc *fd, const void *buf, PRInt32 amount)
static PRStatus PR_CALLBACK SocketClose (PRFileDesc *fd)
static PRInt32 PR_CALLBACK SocketAvailable (PRFileDesc *fd)
static PRInt64 PR_CALLBACK SocketAvailable64 (PRFileDesc *fd)
static PRStatus PR_CALLBACK SocketSync (PRFileDesc *fd)
static PRInt32 PR_CALLBACK SocketSendTo (PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout)
static PRInt32 PR_CALLBACK SocketRecvFrom (PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
static PRInt32 PR_CALLBACK SocketAcceptRead (PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout)
static PRInt32 PR_CALLBACK SocketSendFile (PRFileDesc *sd, PRSendFileData *sfd, PRTransmitFileFlags flags, PRIntervalTime timeout)
static PRInt32 PR_CALLBACK SocketTransmitFile (PRFileDesc *sd, PRFileDesc *fd, const void *headers, PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime timeout)
static PRStatus PR_CALLBACK SocketGetName (PRFileDesc *fd, PRNetAddr *addr)
static PRStatus PR_CALLBACK SocketGetPeerName (PRFileDesc *fd, PRNetAddr *addr)
static PRInt16 PR_CALLBACK SocketPoll (PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags)
 PR_IMPLEMENT (const PRIOMethods *)
 PR_EXTERN (PRStatus)
 PR_FileDesc2NativeHandle (PRFileDesc *fd)
 PR_ChangeFileDescNativeHandle (PRFileDesc *fd, PRInt32 handle)
 PR_IMPLEMENT (void)
 PR_IMPLEMENT (PRInt32)
static PRPollDesc_pr_setfd (PR_fd_set *set, PRInt16 flags, PRPollDesc *polldesc)

Variables

static PRIOMethods tcpMethods
static PRIOMethods udpMethods
static PRIOMethods socketpollfdMethods

Define Documentation

#define PD_INCR   20

Definition at line 1701 of file prsocket.c.


Function Documentation

static PRPollDesc* _pr_setfd ( PR_fd_set set,
PRInt16  flags,
PRPollDesc polldesc 
) [static]

Definition at line 1703 of file prsocket.c.

{
    PRUintn fsidx, pdidx;
    PRPollDesc *poll = polldesc;

    if (NULL == set) return poll;

       /* First set the pr file handle osfds */
       for (fsidx = 0; fsidx < set->hsize; fsidx++)
       {
           for (pdidx = 0; 1; pdidx++)
        {
            if ((PRFileDesc*)-1 == poll[pdidx].fd)
            {
                /* our vector is full - extend and condition it */
                poll = (PRPollDesc*)PR_Realloc(
                    poll, (pdidx + 1 + PD_INCR) * sizeof(PRPollDesc));
                if (NULL == poll) goto out_of_memory;
                memset(
                    poll + pdidx * sizeof(PRPollDesc),
                    0, PD_INCR * sizeof(PRPollDesc));
                poll[pdidx + PD_INCR].fd = (PRFileDesc*)-1;
            }
            if ((NULL == poll[pdidx].fd)
            || (poll[pdidx].fd == set->harray[fsidx]))
            {
                /* PR_ASSERT(0 == (poll[pdidx].in_flags & flags)); */
                /* either empty or prevously defined */
                poll[pdidx].fd = set->harray[fsidx];  /* possibly redundant */
                poll[pdidx].in_flags |= flags;  /* possibly redundant */
                break;
            }
        }
       }

#if 0
       /* Second set the native osfds */
       for (fsidx = 0; fsidx < set->nsize; fsidx++)
       {
           for (pdidx = 0; ((PRFileDesc*)-1 != poll[pdidx].fd); pdidx++)
        {
            if ((PRFileDesc*)-1 == poll[pdidx].fd)
            {
                /* our vector is full - extend and condition it */
                poll = PR_Realloc(
                    poll, (pdidx + PD_INCR) * sizeof(PRPollDesc));
                if (NULL == poll) goto out_of_memory;
                memset(
                    poll + pdidx * sizeof(PRPollDesc),
                    0, PD_INCR * sizeof(PRPollDesc));
                poll[(pdidx + PD_INCR)].fd = (PRFileDesc*)-1;
            }
            if ((NULL == poll[pdidx].fd)
            || (poll[pdidx].fd == set->narray[fsidx]))
            {
                /* either empty or prevously defined */
                poll[pdidx].fd = set->narray[fsidx];
                PR_ASSERT(0 == (poll[pdidx].in_flags & flags));
                poll[pdidx].in_flags |= flags;
                break;
            }
        }
       }
#endif /* 0 */

       return poll;

out_of_memory:
    if (NULL != polldesc) PR_DELETE(polldesc);
    return NULL;
}  /* _pr_setfd */

Here is the call graph for this function:

Definition at line 1615 of file prsocket.c.

{
       if (fd)
              fd->secret->md.osfd = handle;
}

Definition at line 1265 of file prsocket.c.

{
PRInt32 osfd;

       osfd = _PR_MD_SOCKET(AF_INET6, SOCK_STREAM, 0);
       if (osfd != -1) {
              _PR_MD_CLOSE_SOCKET(osfd);
              return PR_TRUE;
       }
       return PR_FALSE;
}
#endif /* _PR_INET6_PROBE */

#endif

PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
{
       PRInt32 osfd;
       PRFileDesc *fd;
       PRInt32 tmp_domain = domain;

       if (!_pr_initialized) _PR_ImplicitInitialization();
       if (PR_AF_INET != domain
                     && PR_AF_INET6 != domain
#if defined(XP_UNIX) || defined(XP_OS2_EMX)
                     && PR_AF_LOCAL != domain
#endif
                     ) {
              PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
              return NULL;
       }

#if defined(_PR_INET6_PROBE)
       if (PR_AF_INET6 == domain) {
              if (_pr_ipv6_is_present == PR_FALSE) 
                     domain = AF_INET;
              else
                     domain = AF_INET6;
       }
#elif defined(_PR_INET6)
       if (PR_AF_INET6 == domain)
              domain = AF_INET6;
#else
       if (PR_AF_INET6 == domain)
              domain = AF_INET;
#endif /* _PR_INET6 */
       osfd = _PR_MD_SOCKET(domain, type, proto);
       if (osfd == -1) {
              return 0;
       }
       if (type == SOCK_STREAM)
              fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
       else
              fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods());
       /*
        * Make the sockets non-blocking
        */
       if (fd != NULL) {
              _PR_MD_MAKE_NONBLOCK(fd);
              _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
#ifdef _PR_NEED_SECRET_AF
              fd->secret->af = domain;
#endif
#if defined(_PR_INET6_PROBE) || !defined(_PR_INET6)
              /*
               * For platforms with no support for IPv6 
               * create layered socket for IPv4-mapped IPv6 addresses
               */
              if (PR_AF_INET6 == tmp_domain && PR_AF_INET == domain) {
                     if (PR_FAILURE == _pr_push_ipv6toipv4_layer(fd)) {
                            PR_Close(fd);
                            fd = NULL;
                     }
              }
#endif
       } else
              _PR_MD_CLOSE_SOCKET(osfd);

       return fd;
}

Definition at line 1602 of file prsocket.c.

{
    if (fd) {
        fd = PR_GetIdentitiesLayer(fd, PR_NSPR_IO_LAYER);
    }
    if (!fd) {
        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
        return -1;
    }
    return fd->secret->md.osfd;
}

Here is the caller graph for this function:

Definition at line 1259 of file prsocket.c.

{
    return &socketpollfdMethods;
}  /* PR_GetSocketPollFdMethods */

Definition at line 193 of file prsocket.c.

{
PRFileDesc *fd;

       if (!_pr_initialized) _PR_ImplicitInitialization();
       fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
       if (fd != NULL) {
              _PR_MD_MAKE_NONBLOCK(fd);
              _PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
#ifdef _PR_NEED_SECRET_AF
              /* this means we can only import IPv4 sockets here.
               * but this is what the function in ptio.c does.
               * We need a way to import IPv6 sockets, too.
               */
              fd->secret->af = AF_INET;
#endif
       } else
              _PR_MD_CLOSE_SOCKET(osfd);
       return(fd);
}

Here is the call graph for this function:

Definition at line 251 of file prsocket.c.

{
    if (NULL == fd)
    {
        PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
        return PR_FAILURE;
    }
    fd->secret->state = _PR_FILEDESC_CLOSED;
    _PR_Putfd(fd);
    return PR_SUCCESS;
}  /* PR_DestroySocketPollFd */

Here is the call graph for this function:

Definition at line 1249 of file prsocket.c.

{
       return &tcpMethods;
}

Definition at line 1626 of file prsocket.c.

{
       memset(set, 0, sizeof(PR_fd_set));
}

Here is the call graph for this function:

Definition at line 1652 of file prsocket.c.

{
       PRUint32 index;
       for (index = 0; index<set->hsize; index++)
              if (set->harray[index] == fh) {
                     return 1;
              }
       return 0;
}
static PRFileDesc* PR_CALLBACK SocketAccept ( PRFileDesc fd,
PRNetAddr addr,
PRIntervalTime  timeout 
) [static]

Definition at line 404 of file prsocket.c.

{
       PRInt32 osfd;
       PRFileDesc *fd2;
       PRUint32 al;
       PRThread *me = _PR_MD_CURRENT_THREAD();
#ifdef WINNT
       PRNetAddr addrCopy;
#endif

       if (_PR_PENDING_INTERRUPT(me)) {
              me->flags &= ~_PR_INTERRUPT;
              PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
              return 0;
       }
       if (_PR_IO_PENDING(me)) {
              PR_SetError(PR_IO_PENDING_ERROR, 0);
              return 0;
       }

#ifdef WINNT
       if (addr == NULL) {
              addr = &addrCopy;
       }
#endif
       al = sizeof(PRNetAddr);
       osfd = _PR_MD_ACCEPT(fd, addr, &al, timeout);
       if (osfd == -1)
              return 0;

       fd2 = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
       if (!fd2) {
              _PR_MD_CLOSE_SOCKET(osfd);
              return NULL;
       }

       fd2->secret->nonblocking = fd->secret->nonblocking;
       fd2->secret->inheritable = fd->secret->inheritable;
#ifdef WINNT
       if (!fd2->secret->nonblocking && fd2->secret->inheritable != _PR_TRI_TRUE) {
              /*
               * The new socket has been associated with an I/O
               * completion port.  There is no going back.
               */
              fd2->secret->md.io_model_committed = PR_TRUE;
       }
       PR_ASSERT(al == PR_NETADDR_SIZE(addr));
       fd2->secret->md.accepted_socket = PR_TRUE;
       memcpy(&fd2->secret->md.peer_addr, addr, al);
#endif

       /*
        * On some platforms, the new socket created by accept()
        * inherits the nonblocking (or overlapped io) attribute
        * of the listening socket.  As an optimization, these
        * platforms can skip the following _PR_MD_MAKE_NONBLOCK
        * call.
        * 
        * On Mac, we MUST make this call, because _PR_MD_MAKE_NONBLOCK
        * (which maps to _MD_makenonblock, see macsockotpt.c)
        * installs the async notifier routine needed to make blocking
        * I/O work properly.
        */
#if !defined(SOLARIS) && !defined(IRIX) && !defined(WINNT)
       _PR_MD_MAKE_NONBLOCK(fd2);
#endif

#ifdef _PR_INET6
       if (addr && (AF_INET6 == addr->raw.family))
        addr->raw.family = PR_AF_INET6;
#endif
       PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
       PR_ASSERT(IsValidNetAddrLen(addr, al) == PR_TRUE);

       return fd2;
}

Here is the call graph for this function:

static PRInt32 PR_CALLBACK SocketAcceptRead ( PRFileDesc sd,
PRFileDesc **  nd,
PRNetAddr **  raddr,
void buf,
PRInt32  amount,
PRIntervalTime  timeout 
) [static]

Definition at line 853 of file prsocket.c.

{
       PRInt32 rv;
       PRThread *me = _PR_MD_CURRENT_THREAD();

       if (_PR_PENDING_INTERRUPT(me)) {
              me->flags &= ~_PR_INTERRUPT;
              PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
              return -1;
       }
       if (_PR_IO_PENDING(me)) {
              PR_SetError(PR_IO_PENDING_ERROR, 0);
              return -1;
       }
       /* The socket must be in blocking mode. */
       if (sd->secret->nonblocking) {
              PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
              return -1;
       }
       *nd = NULL;

#if defined(WINNT)
       {
       PRInt32 newSock;
       PRNetAddr *raddrCopy;

       if (raddr == NULL) {
              raddr = &raddrCopy;
       }
       rv = _PR_MD_ACCEPT_READ(sd, &newSock, raddr, buf, amount, timeout);
       if (rv < 0) {
              rv = -1;
       } else {
              /* Successfully accepted and read; create the new PRFileDesc */
              *nd = PR_AllocFileDesc(newSock, PR_GetTCPMethods());
              if (*nd == 0) {
                     _PR_MD_CLOSE_SOCKET(newSock);
                     /* PR_AllocFileDesc() has invoked PR_SetError(). */
                     rv = -1;
              } else {
                     (*nd)->secret->md.io_model_committed = PR_TRUE;
                     (*nd)->secret->md.accepted_socket = PR_TRUE;
                     memcpy(&(*nd)->secret->md.peer_addr, *raddr,
                            PR_NETADDR_SIZE(*raddr));
#ifdef _PR_INET6
                     if (AF_INET6 == *raddr->raw.family)
                     *raddr->raw.family = PR_AF_INET6;
#endif
              }
       }
       }
#else
       rv = PR_EmulateAcceptRead(sd, nd, raddr, buf, amount, timeout);
#endif
       return rv;
}

Here is the call graph for this function:

static PRInt32 PR_CALLBACK SocketAvailable ( PRFileDesc fd) [static]

Definition at line 745 of file prsocket.c.

{
       PRInt32 rv;
#ifdef _PR_HAVE_PEEK_BUFFER
       if (fd->secret->peekBytes != 0) {
              return fd->secret->peekBytes;
       }
#endif
       rv =  _PR_MD_SOCKETAVAILABLE(fd);
       return rv;           
}
static PRInt64 PR_CALLBACK SocketAvailable64 ( PRFileDesc fd) [static]

Definition at line 757 of file prsocket.c.

{
    PRInt64 rv;
#ifdef _PR_HAVE_PEEK_BUFFER
    if (fd->secret->peekBytes != 0) {
        LL_I2L(rv, fd->secret->peekBytes);
        return rv;
    }
#endif
    LL_I2L(rv, _PR_MD_SOCKETAVAILABLE(fd));
       return rv;           
}
static PRStatus PR_CALLBACK SocketBind ( PRFileDesc fd,
const PRNetAddr addr 
) [static]

Definition at line 533 of file prsocket.c.

{
       PRInt32 result;
    const PRNetAddr *addrp = addr;
#if defined(_PR_INET6)
       PRNetAddr addrCopy;
#endif

       PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);

#ifdef XP_UNIX
       if (addr->raw.family == AF_UNIX) {
              /* Disallow relative pathnames */
              if (addr->local.path[0] != '/') {
                     PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
                     return PR_FAILURE;
              }
       }
#endif /* XP_UNIX */

#if defined(_PR_INET6)
       if (addr->raw.family == PR_AF_INET6) {
              addrCopy = *addr;
              addrCopy.raw.family = AF_INET6;
              addrp = &addrCopy;
       }
#endif
       result = _PR_MD_BIND(fd, addrp, PR_NETADDR_SIZE(addr));
       if (result < 0) {
              return PR_FAILURE;
       }
       return PR_SUCCESS;
}

Here is the call graph for this function:

static PRStatus PR_CALLBACK SocketClose ( PRFileDesc fd) [static]

Definition at line 716 of file prsocket.c.

{
       if (!fd || !fd->secret
                     || (fd->secret->state != _PR_FILEDESC_OPEN
                     && fd->secret->state != _PR_FILEDESC_CLOSED)) {
              PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
              return PR_FAILURE;
       }

       if (fd->secret->state == _PR_FILEDESC_OPEN) {
              if (_PR_MD_CLOSE_SOCKET(fd->secret->md.osfd) < 0) {
                     return PR_FAILURE;
              }
              fd->secret->state = _PR_FILEDESC_CLOSED;
       }

#ifdef _PR_HAVE_PEEK_BUFFER
       if (fd->secret->peekBuffer) {
              PR_ASSERT(fd->secret->peekBufSize > 0);
              PR_DELETE(fd->secret->peekBuffer);
              fd->secret->peekBufSize = 0;
              fd->secret->peekBytes = 0;
       }
#endif

       PR_FreeFileDesc(fd);
       return PR_SUCCESS;
}
static PRStatus PR_CALLBACK SocketConnect ( PRFileDesc fd,
const PRNetAddr addr,
PRIntervalTime  timeout 
) [static]

Definition at line 263 of file prsocket.c.

{
       PRInt32 rv;    /* Return value of _PR_MD_CONNECT */
    const PRNetAddr *addrp = addr;
#if defined(_PR_INET6)
       PRNetAddr addrCopy;
#endif
       PRThread *me = _PR_MD_CURRENT_THREAD();

       if (_PR_PENDING_INTERRUPT(me)) {
              me->flags &= ~_PR_INTERRUPT;
              PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
              return PR_FAILURE;
       }
#if defined(_PR_INET6)
       if (addr->raw.family == PR_AF_INET6) {
              addrCopy = *addr;
              addrCopy.raw.family = AF_INET6;
              addrp = &addrCopy;
       }
#endif

       rv = _PR_MD_CONNECT(fd, addrp, PR_NETADDR_SIZE(addr), timeout);
       PR_LOG(_pr_io_lm, PR_LOG_MAX, ("connect -> %d", rv));
       if (rv == 0)
              return PR_SUCCESS;
       else
              return PR_FAILURE;
}
static PRStatus PR_CALLBACK SocketConnectContinue ( PRFileDesc fd,
PRInt16  out_flags 
) [static]

Definition at line 294 of file prsocket.c.

{
    PRInt32 osfd;
    int err;

    if (out_flags & PR_POLL_NVAL) {
        PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
        return PR_FAILURE;
    }
    if ((out_flags & (PR_POLL_WRITE | PR_POLL_EXCEPT | PR_POLL_ERR)) == 0) {
        PR_ASSERT(out_flags == 0);
        PR_SetError(PR_IN_PROGRESS_ERROR, 0);
        return PR_FAILURE;
    }

    osfd = fd->secret->md.osfd;

#if defined(XP_UNIX)

    err = _MD_unix_get_nonblocking_connect_error(osfd);
    if (err != 0) {
        _PR_MD_MAP_CONNECT_ERROR(err);
        return PR_FAILURE;
    }
    return PR_SUCCESS;

#elif defined(WIN32) || defined(WIN16)

#if defined(WIN32)
    /*
     * The sleep circumvents a bug in Win32 WinSock.
     * See Microsoft Knowledge Base article ID: Q165989.
     */
    Sleep(0);
#endif /* WIN32 */

    if (out_flags & PR_POLL_EXCEPT) {
        int len = sizeof(err);
        if (getsockopt(osfd, (int)SOL_SOCKET, SO_ERROR, (char *) &err, &len)
                == SOCKET_ERROR) {
            _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
            return PR_FAILURE;
        }
        if (err != 0) {
            _PR_MD_MAP_CONNECT_ERROR(err);
        } else {
            PR_SetError(PR_UNKNOWN_ERROR, 0);
        }
        return PR_FAILURE;
    }

    PR_ASSERT(out_flags & PR_POLL_WRITE);
    return PR_SUCCESS;

#elif defined(XP_OS2)

    err = _MD_os2_get_nonblocking_connect_error(osfd);
    if (err != 0) {
        _PR_MD_MAP_CONNECT_ERROR(err);
        return PR_FAILURE;
    }
    return PR_SUCCESS;

#elif defined(XP_MAC)

    err = _MD_mac_get_nonblocking_connect_error(fd);
    if (err == -1)
        return PR_FAILURE;
       else     
              return PR_SUCCESS;

#elif defined(XP_BEOS)

#ifdef BONE_VERSION  /* bug 122364 */
    /* temporary workaround until getsockopt(SO_ERROR) works in BONE */
    if (out_flags & PR_POLL_EXCEPT) {
        PR_SetError(PR_CONNECT_REFUSED_ERROR, 0);
        return PR_FAILURE;
    }
    PR_ASSERT(out_flags & PR_POLL_WRITE);
    return PR_SUCCESS;
#else
    err = _MD_beos_get_nonblocking_connect_error(fd);
    if( err != 0 ) {
        _PR_MD_MAP_CONNECT_ERROR(err);
        return PR_FAILURE;
    }
    else
        return PR_SUCCESS;
#endif /* BONE_VERSION */

#else
    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
    return PR_FAILURE;
#endif
}

Here is the call graph for this function:

static PRStatus PR_CALLBACK SocketGetName ( PRFileDesc fd,
PRNetAddr addr 
) [static]

Definition at line 1083 of file prsocket.c.

{
       PRInt32 result;
       PRUint32 addrlen;

       addrlen = sizeof(PRNetAddr);
       result = _PR_MD_GETSOCKNAME(fd, addr, &addrlen);
       if (result < 0) {
              return PR_FAILURE;
       }
#ifdef _PR_INET6
       if (AF_INET6 == addr->raw.family)
        addr->raw.family = PR_AF_INET6;
#endif
       PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
       PR_ASSERT(IsValidNetAddrLen(addr, addrlen) == PR_TRUE);
       return PR_SUCCESS;
}

Here is the call graph for this function:

static PRStatus PR_CALLBACK SocketGetPeerName ( PRFileDesc fd,
PRNetAddr addr 
) [static]

Definition at line 1102 of file prsocket.c.

{
       PRInt32 result;
       PRUint32 addrlen;

       addrlen = sizeof(PRNetAddr);
       result = _PR_MD_GETPEERNAME(fd, addr, &addrlen);
       if (result < 0) {
              return PR_FAILURE;
       }
#ifdef _PR_INET6
       if (AF_INET6 == addr->raw.family)
        addr->raw.family = PR_AF_INET6;
#endif
       PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
       PR_ASSERT(IsValidNetAddrLen(addr, addrlen) == PR_TRUE);
       return PR_SUCCESS;
}

Here is the call graph for this function:

static PRStatus PR_CALLBACK SocketListen ( PRFileDesc fd,
PRIntn  backlog 
) [static]

Definition at line 567 of file prsocket.c.

{
       PRInt32 result;

       result = _PR_MD_LISTEN(fd, backlog);
       if (result < 0) {
              return PR_FAILURE;
       }
       return PR_SUCCESS;
}
static PRInt16 PR_CALLBACK SocketPoll ( PRFileDesc fd,
PRInt16  in_flags,
PRInt16 out_flags 
) [static]

Definition at line 1121 of file prsocket.c.

{
#ifdef XP_MAC
#pragma unused( fd, in_flags )
#endif
    *out_flags = 0;
    return in_flags;
}  /* SocketPoll */
static PRInt32 PR_CALLBACK SocketRead ( PRFileDesc fd,
void buf,
PRInt32  amount 
) [static]

Definition at line 667 of file prsocket.c.

Here is the call graph for this function:

static PRInt32 PR_CALLBACK SocketRecv ( PRFileDesc fd,
void buf,
PRInt32  amount,
PRIntn  flags,
PRIntervalTime  timeout 
) [static]

Definition at line 589 of file prsocket.c.

{
       PRInt32 rv;
       PRThread *me = _PR_MD_CURRENT_THREAD();

       if ((flags != 0) && (flags != PR_MSG_PEEK)) {
              PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
              return -1;
       }
       if (_PR_PENDING_INTERRUPT(me)) {
              me->flags &= ~_PR_INTERRUPT;
              PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
              return -1;
       }
       if (_PR_IO_PENDING(me)) {
              PR_SetError(PR_IO_PENDING_ERROR, 0);
              return -1;
       }

       PR_LOG(_pr_io_lm, PR_LOG_MAX, ("recv: fd=%p osfd=%d buf=%p amount=%d flags=%d",
                                                        fd, fd->secret->md.osfd, buf, amount, flags));

#ifdef _PR_HAVE_PEEK_BUFFER
       if (fd->secret->peekBytes != 0) {
              rv = (amount < fd->secret->peekBytes) ?
                     amount : fd->secret->peekBytes;
              memcpy(buf, fd->secret->peekBuffer, rv);
              if (flags == 0) {
                     /* consume the bytes in the peek buffer */
                     fd->secret->peekBytes -= rv;
                     if (fd->secret->peekBytes != 0) {
                            memmove(fd->secret->peekBuffer,
                                   fd->secret->peekBuffer + rv,
                                   fd->secret->peekBytes);
                     }
              }
              return rv;
       }

       /* allocate peek buffer, if necessary */
       if ((PR_MSG_PEEK == flags) && _PR_FD_NEED_EMULATE_MSG_PEEK(fd)) {
              PR_ASSERT(0 == fd->secret->peekBytes);
              /* impose a max size on the peek buffer */
              if (amount > _PR_PEEK_BUFFER_MAX) {
                     amount = _PR_PEEK_BUFFER_MAX;
              }
              if (fd->secret->peekBufSize < amount) {
                     if (fd->secret->peekBuffer) {
                            PR_Free(fd->secret->peekBuffer);
                     }
                     fd->secret->peekBufSize = amount;
                     fd->secret->peekBuffer = PR_Malloc(amount);
                     if (NULL == fd->secret->peekBuffer) {
                            fd->secret->peekBufSize = 0;
                            PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
                            return -1;
                     }
              }
       }
#endif

       rv = _PR_MD_RECV(fd, buf, amount, flags, timeout);
       PR_LOG(_pr_io_lm, PR_LOG_MAX, ("recv -> %d, error = %d, os error = %d",
              rv, PR_GetError(), PR_GetOSError()));

#ifdef _PR_HAVE_PEEK_BUFFER
       if ((PR_MSG_PEEK == flags) && _PR_FD_NEED_EMULATE_MSG_PEEK(fd)) {
              if (rv > 0) {
                     memcpy(fd->secret->peekBuffer, buf, rv);
                     fd->secret->peekBytes = rv;
              }
       }
#endif

       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRInt32 PR_CALLBACK SocketRecvFrom ( PRFileDesc fd,
void buf,
PRInt32  amount,
PRIntn  flags,
PRNetAddr addr,
PRIntervalTime  timeout 
) [static]

Definition at line 827 of file prsocket.c.

{
       PRInt32 rv;
       PRUint32 al;
       PRThread *me = _PR_MD_CURRENT_THREAD();

       if (_PR_PENDING_INTERRUPT(me)) {
              me->flags &= ~_PR_INTERRUPT;
              PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
              return -1;
       }
       if (_PR_IO_PENDING(me)) {
              PR_SetError(PR_IO_PENDING_ERROR, 0);
              return -1;
       }

       al = sizeof(PRNetAddr);
       rv = _PR_MD_RECVFROM(fd, buf, amount, flags, addr, &al, timeout);
#ifdef _PR_INET6
       if (addr && (AF_INET6 == addr->raw.family))
        addr->raw.family = PR_AF_INET6;
#endif
       return rv;
}
static PRInt32 PR_CALLBACK SocketSend ( PRFileDesc fd,
const void buf,
PRInt32  amount,
PRIntn  flags,
PRIntervalTime  timeout 
) [static]

Definition at line 672 of file prsocket.c.

{
       PRInt32 temp, count;
       PRThread *me = _PR_MD_CURRENT_THREAD();

       if (_PR_PENDING_INTERRUPT(me)) {
              me->flags &= ~_PR_INTERRUPT;
              PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
              return -1;
       }
       if (_PR_IO_PENDING(me)) {
              PR_SetError(PR_IO_PENDING_ERROR, 0);
              return -1;
       }

       count = 0;
       while (amount > 0) {
              PR_LOG(_pr_io_lm, PR_LOG_MAX,
                  ("send: fd=%p osfd=%d buf=%p amount=%d",
                  fd, fd->secret->md.osfd, buf, amount));
              temp = _PR_MD_SEND(fd, buf, amount, flags, timeout);
              if (temp < 0) {
                                   count = -1;
                                   break;
                            }

              count += temp;
              if (fd->secret->nonblocking) {
                     break;
              }
              buf = (const void*) ((const char*)buf + temp);

              amount -= temp;
       }
       PR_LOG(_pr_io_lm, PR_LOG_MAX, ("send -> %d", count));
       return count;
}

Here is the caller graph for this function:

static PRInt32 PR_CALLBACK SocketSendFile ( PRFileDesc sd,
PRSendFileData sfd,
PRTransmitFileFlags  flags,
PRIntervalTime  timeout 
) [static]

Definition at line 1028 of file prsocket.c.

{
       PRInt32 rv;
       PRThread *me = _PR_MD_CURRENT_THREAD();

       if (_PR_PENDING_INTERRUPT(me)) {
              me->flags &= ~_PR_INTERRUPT;
              PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
              return -1;
       }
       if (_PR_IO_PENDING(me)) {
              PR_SetError(PR_IO_PENDING_ERROR, 0);
              return -1;
       }
       /* The socket must be in blocking mode. */
       if (sd->secret->nonblocking) {
              PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
              return -1;
       }
#if defined(WINNT)
       rv = _PR_MD_SENDFILE(sd, sfd, flags, timeout);
       if ((rv >= 0) && (flags == PR_TRANSMITFILE_CLOSE_SOCKET)) {
              /*
               * This should be kept the same as SocketClose, except
               * that _PR_MD_CLOSE_SOCKET(sd->secret->md.osfd) should
               * not be called because the socket will be recycled.
               */
              PR_FreeFileDesc(sd);
       }
#else
       rv = PR_EmulateSendFile(sd, sfd, flags, timeout);
#endif /* WINNT */

       return rv;
}

Here is the caller graph for this function:

static PRInt32 PR_CALLBACK SocketSendTo ( PRFileDesc fd,
const void buf,
PRInt32  amount,
PRIntn  flags,
const PRNetAddr addr,
PRIntervalTime  timeout 
) [static]

Definition at line 779 of file prsocket.c.

{
       PRInt32 temp, count;
    const PRNetAddr *addrp = addr;
#if defined(_PR_INET6)
       PRNetAddr addrCopy;
#endif
       PRThread *me = _PR_MD_CURRENT_THREAD();

       if (_PR_PENDING_INTERRUPT(me)) {
              me->flags &= ~_PR_INTERRUPT;
              PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
              return -1;
       }
       if (_PR_IO_PENDING(me)) {
              PR_SetError(PR_IO_PENDING_ERROR, 0);
              return -1;
       }

       PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
#if defined(_PR_INET6)
       if (addr->raw.family == PR_AF_INET6) {
              addrCopy = *addr;
              addrCopy.raw.family = AF_INET6;
              addrp = &addrCopy;
       }
#endif

       count = 0;
       while (amount > 0) {
              temp = _PR_MD_SENDTO(fd, buf, amount, flags,
                  addrp, PR_NETADDR_SIZE(addr), timeout);
              if (temp < 0) {
                                   count = -1;
                                   break;
                            }
              count += temp;
              if (fd->secret->nonblocking) {
                     break;
              }
              buf = (const void*) ((const char*)buf + temp);
              amount -= temp;
       }
       return count;
}

Here is the call graph for this function:

static PRStatus PR_CALLBACK SocketShutdown ( PRFileDesc fd,
PRIntn  how 
) [static]

Definition at line 578 of file prsocket.c.

{
       PRInt32 result;

       result = _PR_MD_SHUTDOWN(fd, how);
       if (result < 0) {
              return PR_FAILURE;
       }
       return PR_SUCCESS;
}
static PRStatus PR_CALLBACK SocketSync ( PRFileDesc fd) [static]

Definition at line 770 of file prsocket.c.

{
#if defined(XP_MAC)
#pragma unused (fd)
#endif

       return PR_SUCCESS;
}
static PRInt32 PR_CALLBACK SocketTransmitFile ( PRFileDesc sd,
PRFileDesc fd,
const void headers,
PRInt32  hlen,
PRTransmitFileFlags  flags,
PRIntervalTime  timeout 
) [static]

Definition at line 1066 of file prsocket.c.

{
       PRSendFileData sfd;

       sfd.fd = fd;
       sfd.file_offset = 0;
       sfd.file_nbytes = 0;
       sfd.header = headers;
       sfd.hlen = hlen;
       sfd.trailer = NULL;
       sfd.tlen = 0;

       return(SocketSendFile(sd, &sfd, flags, timeout));
}

Here is the call graph for this function:

static PRInt32 PR_CALLBACK SocketWrite ( PRFileDesc fd,
const void buf,
PRInt32  amount 
) [static]

Definition at line 711 of file prsocket.c.

Here is the call graph for this function:

static PRInt32 PR_CALLBACK SocketWritev ( PRFileDesc fd,
const PRIOVec iov,
PRInt32  iov_size,
PRIntervalTime  timeout 
) [static]

Definition at line 102 of file prsocket.c.

{
       PRThread *me = _PR_MD_CURRENT_THREAD();
       int w = 0;
       const PRIOVec *tmp_iov;
#define LOCAL_MAXIOV    8
       PRIOVec local_iov[LOCAL_MAXIOV];
       PRIOVec *iov_copy = NULL;
       int tmp_out;
       int index, iov_cnt;
       int count=0, sz = 0;    /* 'count' is the return value. */

       if (_PR_PENDING_INTERRUPT(me)) {
              me->flags &= ~_PR_INTERRUPT;
              PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
              return -1;
       }
       if (_PR_IO_PENDING(me)) {
              PR_SetError(PR_IO_PENDING_ERROR, 0);
              return -1;
       }

    /*
     * Assume the first writev will succeed.  Copy iov's only on
     * failure.
     */
    tmp_iov = iov;
    for (index = 0; index < iov_size; index++)
        sz += iov[index].iov_len;

       iov_cnt = iov_size;

       while (sz > 0) {

              w = _PR_MD_WRITEV(fd, tmp_iov, iov_cnt, timeout);
              if (w < 0) {
                     count = -1;
                     break;
              }
              count += w;
              if (fd->secret->nonblocking) {
                     break;
              }
              sz -= w;

              if (sz > 0) {
                     /* find the next unwritten vector */
                     for ( index = 0, tmp_out = count;
                            tmp_out >= iov[index].iov_len;
                            tmp_out -= iov[index].iov_len, index++){;} /* nothing to execute */

                     if (tmp_iov == iov) {
                            /*
                             * The first writev failed so we
                             * must copy iov's around.
                             * Avoid calloc/free if there
                             * are few enough iov's.
                             */
                            if (iov_size - index <= LOCAL_MAXIOV)
                                   iov_copy = local_iov;
                            else if ((iov_copy = (PRIOVec *) PR_CALLOC((iov_size - index) *
                                   sizeof *iov_copy)) == NULL) {
                                   PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
                                   return -1;
                            }
                            tmp_iov = iov_copy;
                     }

                     PR_ASSERT(tmp_iov == iov_copy);

                     /* fill in the first partial read */
                     iov_copy[0].iov_base = &(((char *)iov[index].iov_base)[tmp_out]);
                     iov_copy[0].iov_len = iov[index].iov_len - tmp_out;
                     index++;

                     /* copy the remaining vectors */
                     for (iov_cnt=1; index<iov_size; iov_cnt++, index++) {
                            iov_copy[iov_cnt].iov_base = iov[index].iov_base;
                            iov_copy[iov_cnt].iov_len = iov[index].iov_len;
                     }
              }
       }

       if (iov_copy != local_iov)
              PR_DELETE(iov_copy);
       return count;
}

Variable Documentation

Definition at line 1210 of file prsocket.c.

Definition at line 1131 of file prsocket.c.

Definition at line 1170 of file prsocket.c.