]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | /*- |
2 | * BSD LICENSE | |
3 | * | |
4 | * Copyright (c) Intel Corporation. | |
5 | * All rights reserved. | |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | |
10 | * | |
11 | * * Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * * Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in | |
15 | * the documentation and/or other materials provided with the | |
16 | * distribution. | |
17 | * * Neither the name of Intel Corporation nor the names of its | |
18 | * contributors may be used to endorse or promote products derived | |
19 | * from this software without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
25 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
27 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | /** \file | |
35 | * TCP network implementation abstraction layer | |
36 | */ | |
37 | ||
38 | #ifndef SPDK_INTERNAL_SOCK_H | |
39 | #define SPDK_INTERNAL_SOCK_H | |
40 | ||
41 | #include "spdk/stdinc.h" | |
42 | #include "spdk/sock.h" | |
43 | #include "spdk/queue.h" | |
44 | ||
45 | #ifdef __cplusplus | |
46 | extern "C" { | |
47 | #endif | |
48 | ||
49 | #define MAX_EVENTS_PER_POLL 32 | |
50 | ||
51 | struct spdk_sock { | |
52 | struct spdk_net_impl *net_impl; | |
53 | spdk_sock_cb cb_fn; | |
54 | void *cb_arg; | |
55 | TAILQ_ENTRY(spdk_sock) link; | |
56 | }; | |
57 | ||
58 | struct spdk_sock_group { | |
59 | STAILQ_HEAD(, spdk_sock_group_impl) group_impls; | |
60 | }; | |
61 | ||
62 | struct spdk_sock_group_impl { | |
63 | struct spdk_net_impl *net_impl; | |
64 | TAILQ_HEAD(, spdk_sock) socks; | |
65 | STAILQ_ENTRY(spdk_sock_group_impl) link; | |
66 | }; | |
67 | ||
68 | struct spdk_net_impl { | |
69 | const char *name; | |
70 | ||
71 | int (*getaddr)(struct spdk_sock *sock, char *saddr, int slen, uint16_t *sport, char *caddr, | |
72 | int clen, uint16_t *cport); | |
73 | struct spdk_sock *(*connect)(const char *ip, int port); | |
74 | struct spdk_sock *(*listen)(const char *ip, int port); | |
75 | struct spdk_sock *(*accept)(struct spdk_sock *sock); | |
76 | int (*close)(struct spdk_sock *sock); | |
77 | ssize_t (*recv)(struct spdk_sock *sock, void *buf, size_t len); | |
9f95a23c | 78 | ssize_t (*readv)(struct spdk_sock *sock, struct iovec *iov, int iovcnt); |
11fdf7f2 TL |
79 | ssize_t (*writev)(struct spdk_sock *sock, struct iovec *iov, int iovcnt); |
80 | ||
81 | int (*set_recvlowat)(struct spdk_sock *sock, int nbytes); | |
82 | int (*set_recvbuf)(struct spdk_sock *sock, int sz); | |
83 | int (*set_sendbuf)(struct spdk_sock *sock, int sz); | |
84 | ||
85 | bool (*is_ipv6)(struct spdk_sock *sock); | |
86 | bool (*is_ipv4)(struct spdk_sock *sock); | |
87 | ||
88 | struct spdk_sock_group_impl *(*group_impl_create)(void); | |
89 | int (*group_impl_add_sock)(struct spdk_sock_group_impl *group, struct spdk_sock *sock); | |
90 | int (*group_impl_remove_sock)(struct spdk_sock_group_impl *group, struct spdk_sock *sock); | |
91 | int (*group_impl_poll)(struct spdk_sock_group_impl *group, int max_events, | |
92 | struct spdk_sock **socks); | |
93 | int (*group_impl_close)(struct spdk_sock_group_impl *group); | |
94 | ||
95 | STAILQ_ENTRY(spdk_net_impl) link; | |
96 | }; | |
97 | ||
98 | void spdk_net_impl_register(struct spdk_net_impl *impl); | |
99 | ||
100 | #define SPDK_NET_IMPL_REGISTER(name, impl) \ | |
101 | static void __attribute__((constructor)) net_impl_register_##name(void) \ | |
102 | { \ | |
103 | spdk_net_impl_register(impl); \ | |
104 | } | |
105 | ||
106 | #ifdef __cplusplus | |
107 | } | |
108 | #endif | |
109 | ||
110 | #endif /* SPDK_INTERNAL_SOCK_H */ |