2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
20 # error AFDT is not currently supported for MSVC!
23 #include <sys/socket.h>
31 ///////////////////////////////////////////////////////////////////////////////
35 typedef void (*SrFunc
)(int afdt_fd
, std::vector
<iovec
>& iov
);
37 void sappend(int afdt_fd
,
38 std::vector
<iovec
>& iov
, const void* addr
, size_t size
);
39 void rappend(int afdt_fd
,
40 std::vector
<iovec
>& iov
, void* addr
, size_t size
);
43 typename
std::enable_if
<
44 std::is_fundamental
<T
>::value
|| std::is_pod
<T
>::value
,
46 >::type
sappend(int afdt_fd
, std::vector
<iovec
>& iov
, const T
& elm
) {
47 sappend(afdt_fd
, iov
, &elm
, sizeof elm
);
51 typename
std::enable_if
<
52 std::is_fundamental
<T
>::value
|| std::is_pod
<T
>::value
,
54 >::type
rappend(int afdt_fd
, std::vector
<iovec
>& iov
, T
* elm
) {
55 rappend(afdt_fd
, iov
, elm
, sizeof *elm
);
58 void send(int afdt_fd
, std::vector
<iovec
>& iov
);
60 template<class... Tail
>
61 void send(int afdt_fd
, std::vector
<iovec
>& iov
,
62 const std::vector
<std::string
>& h
, Tail
&&... args
);
64 template<class... Tail
>
65 void send(int afdt_fd
, std::vector
<iovec
>& iov
,
66 const std::string
& h
, Tail
&&... args
);
68 template<class... Tail
>
69 void send(int afdt_fd
, std::vector
<iovec
>& iov
,
70 const char* h
, Tail
&&... args
);
72 template<class T
, class... Tail
>
73 typename
std::enable_if
<std::is_fundamental
<T
>::value
, void>::type
74 send(int afdt_fd
, std::vector
<iovec
>& iov
,
75 const std::vector
<T
>& h
, Tail
&&... args
);
77 template<class... Tail
>
78 void send(int afdt_fd
, std::vector
<iovec
>& iov
,
79 const std::vector
<std::string
>& h
, Tail
&&... args
);
82 template<class Head
, class... Tail
>
83 void send(int afdt_fd
, std::vector
<iovec
>& iov
,
84 const Head
& h
, Tail
&&... args
) {
85 sappend(afdt_fd
, iov
, h
);
86 send(afdt_fd
, iov
, std::forward
<Tail
>(args
)...);
89 template<class... Tail
>
90 void send(int afdt_fd
, std::vector
<iovec
>& iov
,
91 const std::string
& h
, Tail
&&... args
) {
93 sappend(afdt_fd
, iov
, s
);
94 sappend(afdt_fd
, iov
, &h
[0], s
);
95 send(afdt_fd
, iov
, std::forward
<Tail
>(args
)...);
98 template<class... Tail
>
99 void send(int afdt_fd
, std::vector
<iovec
>& iov
,
100 const char* h
, Tail
&&... args
) {
101 size_t s
= std::strlen(h
);
102 sappend(afdt_fd
, iov
, s
);
103 sappend(afdt_fd
, iov
, &h
[0], s
);
104 send(afdt_fd
, iov
, std::forward
<Tail
>(args
)...);
107 template<class T
, class... Tail
>
108 typename
std::enable_if
<std::is_fundamental
<T
>::value
, void>::type
109 send(int afdt_fd
, std::vector
<iovec
>& iov
,
110 const std::vector
<T
>& h
, Tail
&&... args
) {
112 sappend(afdt_fd
, iov
, s
);
113 sappend(afdt_fd
, iov
, &h
[0], s
* sizeof(T
));
114 send(afdt_fd
, iov
, std::forward
<Tail
>(args
)...);
117 template<class... Tail
>
118 void send(int afdt_fd
, std::vector
<iovec
>& iov
,
119 const std::vector
<std::string
>& h
, Tail
&&... args
) {
121 sappend(afdt_fd
, iov
, s
);
122 std::vector
<size_t> sizes
;
125 auto strsz
= e
.size();
126 sizes
.push_back(strsz
);
127 sappend(afdt_fd
, iov
, sizes
.back());
128 sappend(afdt_fd
, iov
, &e
[0], strsz
);
130 send(afdt_fd
, iov
, std::forward
<Tail
>(args
)...);
133 void recv(int afdt_fd
, std::vector
<iovec
>& iov
);
135 template<class... Tail
>
136 void recv(int afdt_fd
, std::vector
<iovec
>& iov
,
137 std::string
& h
, Tail
&... args
);
139 template<class T
, class... Tail
>
140 typename
std::enable_if
<std::is_fundamental
<T
>::value
, void>::type
141 recv(int afdt_fd
, std::vector
<iovec
>& iov
,
142 std::vector
<T
>& h
, Tail
&... args
);
144 template<class... Tail
>
145 void recv(int afdt_fd
, std::vector
<iovec
>& iov
,
146 std::vector
<std::string
>& h
, Tail
&... args
);
149 template<class Head
, class... Tail
>
150 void recv(int afdt_fd
, std::vector
<iovec
>& iov
,
151 Head
& h
, Tail
&... args
) {
152 rappend(afdt_fd
, iov
, &h
);
153 recv(afdt_fd
, iov
, args
...);
156 template<class... Tail
>
157 void recv(int afdt_fd
, std::vector
<iovec
>& iov
,
158 std::string
& h
, Tail
&... args
) {
160 rappend(afdt_fd
, iov
, &sz
);
164 rappend(afdt_fd
, iov
, &h
[0], sz
);
165 recv(afdt_fd
, iov
, args
...);
168 template<class T
, class... Tail
>
169 typename
std::enable_if
<std::is_fundamental
<T
>::value
, void>::type
170 recv(int afdt_fd
, std::vector
<iovec
>& iov
,
171 std::vector
<T
>& h
, Tail
&... args
) {
173 rappend(afdt_fd
, iov
, &sz
);
177 rappend(afdt_fd
, iov
, &h
[0], sz
* sizeof(h
[0]));
178 recv(afdt_fd
, iov
, args
...);
181 template<class... Tail
>
182 void recv(int afdt_fd
, std::vector
<iovec
>& iov
,
183 std::vector
<std::string
>& h
, Tail
&... args
) {
185 rappend(afdt_fd
, iov
, &sz
);
191 rappend(afdt_fd
, iov
, &strsz
);
195 rappend(afdt_fd
, iov
, &e
[0], strsz
);
197 recv(afdt_fd
, iov
, args
...);
202 template<class Head
, class... Tail
>
203 void sendx(int afdt_fd
, const Head
& h
, Tail
&&... args
) {
204 std::vector
<iovec
> iov
;
205 detail::send(afdt_fd
, iov
, h
, std::forward
<Tail
>(args
)...);
208 template<class Head
, class... Tail
>
209 void recvx(int afdt_fd
, Head
& h
, Tail
&... args
) {
210 std::vector
<iovec
> iov
;
211 detail::recv(afdt_fd
, iov
, h
, args
...);
214 template<class Head
, class... Tail
>
215 int sendRaw(int afdt_fd
, const Head
& h
, Tail
&&... args
) {
216 std::vector
<iovec
> iov
;
218 detail::send(afdt_fd
, iov
, h
, std::forward
<Tail
>(args
)...);
220 } catch (const std::runtime_error
& e
) {
225 template<class Head
, class... Tail
>
226 int recvRaw(int afdt_fd
, Head
& h
, Tail
&... args
) {
227 std::vector
<iovec
> iov
;
229 detail::recv(afdt_fd
, iov
, h
, args
...);
231 } catch (const std::runtime_error
& e
) {
236 bool send_fd(int afdt_fd
, int fd
);
237 int recv_fd(int afdt_fd
);
239 ///////////////////////////////////////////////////////////////////////////////