media/mtransport/third_party/nICEr/src/net/nr_socket.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/mtransport/third_party/nICEr/src/net/nr_socket.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,137 @@
     1.4 +/*
     1.5 +Copyright (c) 2007, Adobe Systems, Incorporated
     1.6 +All rights reserved.
     1.7 +
     1.8 +Redistribution and use in source and binary forms, with or without
     1.9 +modification, are permitted provided that the following conditions are
    1.10 +met:
    1.11 +
    1.12 +* Redistributions of source code must retain the above copyright
    1.13 +  notice, this list of conditions and the following disclaimer.
    1.14 +
    1.15 +* Redistributions in binary form must reproduce the above copyright
    1.16 +  notice, this list of conditions and the following disclaimer in the
    1.17 +  documentation and/or other materials provided with the distribution.
    1.18 +
    1.19 +* Neither the name of Adobe Systems, Network Resonance nor the names of its
    1.20 +  contributors may be used to endorse or promote products derived from
    1.21 +  this software without specific prior written permission.
    1.22 +
    1.23 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.24 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.25 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.26 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.27 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.28 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.29 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.30 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.31 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.32 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.33 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.34 +*/
    1.35 +
    1.36 +
    1.37 +
    1.38 +static char *RCSSTRING __UNUSED__="$Id: nr_socket.c,v 1.2 2008/04/28 17:59:02 ekr Exp $";
    1.39 +
    1.40 +#include <assert.h>
    1.41 +#include <nr_api.h>
    1.42 +#include "nr_socket.h"
    1.43 +#include "local_addr.h"
    1.44 +
    1.45 +#define CHECK_DEFINED(f) assert(sock->vtbl->f); if (!sock->vtbl->f) ERETURN(R_INTERNAL);
    1.46 +int nr_socket_create_int(void *obj, nr_socket_vtbl *vtbl, nr_socket **sockp)
    1.47 +  {
    1.48 +    int _status;
    1.49 +    nr_socket *sock=0;
    1.50 +
    1.51 +    if(!(sock=RCALLOC(sizeof(nr_socket))))
    1.52 +      ABORT(R_NO_MEMORY);
    1.53 +
    1.54 +    assert(vtbl->version == 1);
    1.55 +    if (vtbl->version != 1)
    1.56 +       ABORT(R_INTERNAL);
    1.57 +
    1.58 +    sock->obj=obj;
    1.59 +    sock->vtbl=vtbl;
    1.60 +
    1.61 +    *sockp=sock;
    1.62 +
    1.63 +    _status=0;
    1.64 +  abort:
    1.65 +    return(_status);
    1.66 +  }
    1.67 +
    1.68 +int nr_socket_destroy(nr_socket **sockp)
    1.69 +  {
    1.70 +    nr_socket *sock;
    1.71 +
    1.72 +    if(!sockp || !*sockp)
    1.73 +      return(0);
    1.74 +
    1.75 +
    1.76 +    sock=*sockp;
    1.77 +    *sockp=0;
    1.78 +
    1.79 +    CHECK_DEFINED(destroy);
    1.80 +
    1.81 +    assert(sock->vtbl);
    1.82 +    if (sock->vtbl)
    1.83 +      sock->vtbl->destroy(&sock->obj);
    1.84 +
    1.85 +    RFREE(sock);
    1.86 +
    1.87 +    return(0);
    1.88 +  }
    1.89 +
    1.90 +int nr_socket_sendto(nr_socket *sock,const void *msg, size_t len, int flags,
    1.91 +  nr_transport_addr *addr)
    1.92 +  {
    1.93 +    CHECK_DEFINED(ssendto);
    1.94 +    return sock->vtbl->ssendto(sock->obj,msg,len,flags,addr);
    1.95 +  }
    1.96 +
    1.97 +int nr_socket_recvfrom(nr_socket *sock,void * restrict buf, size_t maxlen,
    1.98 +  size_t *len, int flags, nr_transport_addr *addr)
    1.99 +  {
   1.100 +    CHECK_DEFINED(srecvfrom);
   1.101 +    return sock->vtbl->srecvfrom(sock->obj, buf, maxlen, len, flags, addr);
   1.102 +  }
   1.103 +
   1.104 +int nr_socket_getfd(nr_socket *sock, NR_SOCKET *fd)
   1.105 +  {
   1.106 +    CHECK_DEFINED(getfd);
   1.107 +    return sock->vtbl->getfd(sock->obj, fd);
   1.108 +  }
   1.109 +
   1.110 +int nr_socket_getaddr(nr_socket *sock, nr_transport_addr *addrp)
   1.111 +  {
   1.112 +    CHECK_DEFINED(getaddr);
   1.113 +    return sock->vtbl->getaddr(sock->obj, addrp);
   1.114 +  }
   1.115 +
   1.116 +int nr_socket_close(nr_socket *sock)
   1.117 +  {
   1.118 +    CHECK_DEFINED(close);
   1.119 +    return sock->vtbl->close(sock->obj);
   1.120 +  }
   1.121 +
   1.122 +int nr_socket_connect(nr_socket *sock, nr_transport_addr *addr)
   1.123 +  {
   1.124 +    CHECK_DEFINED(connect);
   1.125 +    return sock->vtbl->connect(sock->obj, addr);
   1.126 +  }
   1.127 +
   1.128 +int nr_socket_write(nr_socket *sock,const void *msg, size_t len, size_t *written, int flags)
   1.129 +  {
   1.130 +    CHECK_DEFINED(swrite);
   1.131 +    return sock->vtbl->swrite(sock->obj, msg, len, written);
   1.132 +  }
   1.133 +
   1.134 +
   1.135 +int nr_socket_read(nr_socket *sock,void * restrict buf, size_t maxlen,
   1.136 +  size_t *len, int flags)
   1.137 +  {
   1.138 +    CHECK_DEFINED(sread);
   1.139 +    return sock->vtbl->sread(sock->obj, buf, maxlen, len);
   1.140 +  }

mercurial