|
1 /* |
|
2 Copyright (c) 2007, Adobe Systems, Incorporated |
|
3 All rights reserved. |
|
4 |
|
5 Redistribution and use in source and binary forms, with or without |
|
6 modification, are permitted provided that the following conditions are |
|
7 met: |
|
8 |
|
9 * Redistributions of source code must retain the above copyright |
|
10 notice, this list of conditions and the following disclaimer. |
|
11 |
|
12 * Redistributions in binary form must reproduce the above copyright |
|
13 notice, this list of conditions and the following disclaimer in the |
|
14 documentation and/or other materials provided with the distribution. |
|
15 |
|
16 * Neither the name of Adobe Systems, Network Resonance nor the names of its |
|
17 contributors may be used to endorse or promote products derived from |
|
18 this software without specific prior written permission. |
|
19 |
|
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
31 */ |
|
32 |
|
33 |
|
34 |
|
35 #ifndef _nr_socket_h |
|
36 #define _nr_socket_h |
|
37 |
|
38 #include <sys/types.h> |
|
39 #ifdef WIN32 |
|
40 #include <winsock2.h> |
|
41 #include <ws2tcpip.h> |
|
42 #else |
|
43 #include <sys/socket.h> |
|
44 #endif |
|
45 |
|
46 #include "transport_addr.h" |
|
47 |
|
48 #ifdef __cplusplus |
|
49 #define restrict |
|
50 #elif defined(WIN32) |
|
51 #define restrict __restrict |
|
52 #endif |
|
53 |
|
54 typedef struct nr_socket_vtbl_ { |
|
55 UINT4 version; /* Currently 1 */ |
|
56 int (*destroy)(void **obj); |
|
57 int (*ssendto)(void *obj,const void *msg, size_t len, int flags, |
|
58 nr_transport_addr *addr); |
|
59 int (*srecvfrom)(void *obj,void * restrict buf, size_t maxlen, size_t *len, int flags, |
|
60 nr_transport_addr *addr); |
|
61 int (*getfd)(void *obj, NR_SOCKET *fd); |
|
62 int (*getaddr)(void *obj, nr_transport_addr *addrp); |
|
63 int (*connect)(void *obj, nr_transport_addr *addr); |
|
64 int (*swrite)(void *obj,const void *msg, size_t len, size_t *written); |
|
65 int (*sread)(void *obj,void * restrict buf, size_t maxlen, size_t *len); |
|
66 int (*close)(void *obj); |
|
67 } nr_socket_vtbl; |
|
68 |
|
69 typedef struct nr_socket_ { |
|
70 void *obj; |
|
71 nr_socket_vtbl *vtbl; |
|
72 } nr_socket; |
|
73 |
|
74 |
|
75 /* To be called by constructors */ |
|
76 int nr_socket_create_int(void *obj, nr_socket_vtbl *vtbl, nr_socket **sockp); |
|
77 int nr_socket_destroy(nr_socket **sockp); |
|
78 int nr_socket_sendto(nr_socket *sock,const void *msg, size_t len, |
|
79 int flags,nr_transport_addr *addr); |
|
80 int nr_socket_recvfrom(nr_socket *sock,void * restrict buf, size_t maxlen, |
|
81 size_t *len, int flags, nr_transport_addr *addr); |
|
82 int nr_socket_getfd(nr_socket *sock, NR_SOCKET *fd); |
|
83 int nr_socket_getaddr(nr_socket *sock, nr_transport_addr *addrp); |
|
84 int nr_socket_close(nr_socket *sock); |
|
85 int nr_socket_connect(nr_socket *sock, nr_transport_addr *addr); |
|
86 int nr_socket_write(nr_socket *sock,const void *msg, size_t len, size_t *written, int flags); |
|
87 int nr_socket_read(nr_socket *sock, void * restrict buf, size_t maxlen, size_t *len, int flags); |
|
88 |
|
89 #endif |
|
90 |