line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "sockaddr.h" |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
namespace xs { namespace net { |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
using panda::net::SockAddr; |
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
|
|
|
static PERL_ITHREADS_LOCAL HV* s1 = gv_stashpvs("Net::SockAddr::Inet4", GV_ADD); |
8
|
5
|
|
|
|
|
|
static PERL_ITHREADS_LOCAL HV* s2 = gv_stashpvs("Net::SockAddr::Inet6", GV_ADD); |
9
|
5
|
|
|
|
|
|
static PERL_ITHREADS_LOCAL HV* s3 = gv_stashpvs("Net::SockAddr::Unix", GV_ADD); |
10
|
|
|
|
|
|
|
|
11
|
63
|
|
|
|
|
|
SockAddr* _in_sockaddr_ptr (SV* arg) { |
12
|
63
|
50
|
|
|
|
|
if (!SvOK(arg)) return nullptr; |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13
|
63
|
50
|
|
|
|
|
if (!Sv(arg).is_object_ref()) throw "invalid sockaddr"; |
14
|
63
|
|
|
|
|
|
return (panda::net::SockAddr*)SvPVX(SvRV(arg)); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
15
|
|
|
|
|
|
SockAddr _in_sockaddr (SV* arg) { |
18
|
15
|
100
|
|
|
|
|
if (!SvOK(arg)) return {}; |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
19
|
14
|
100
|
|
|
|
|
if (Sv(arg).is_object_ref()) return *_in_sockaddr_ptr(arg); |
20
|
3
|
50
|
|
|
|
|
if (!SvPOK(arg) || SvCUR(arg) < sizeof(panda::net::sa_family_t)) throw "invalid sockaddr"; |
|
|
50
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
|
size_t sz = (size_t)SvCUR(arg); |
23
|
3
|
|
|
|
|
|
auto sa = (const sockaddr*)SvPVX(arg); |
24
|
3
|
|
|
|
|
|
return SockAddr(sa, sz); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
46
|
|
|
|
|
|
Sv _create_sockaddr (const panda::net::SockAddr& var) { |
28
|
92
|
|
|
|
|
|
Stash stash; |
29
|
46
|
50
|
|
|
|
|
size_t sz = var.length(); |
30
|
46
|
|
|
|
|
|
switch (var.family()) { |
31
|
1
|
50
|
|
|
|
|
case AF_UNSPEC : return Sv::undef; |
32
|
24
|
50
|
|
|
|
|
case AF_INET : stash = s1; break; |
33
|
18
|
50
|
|
|
|
|
case AF_INET6 : stash = s2; break; |
34
|
|
|
|
|
|
|
#ifndef _WIN32 |
35
|
3
|
50
|
|
|
|
|
case AF_UNIX : stash = s3; break; |
36
|
|
|
|
|
|
|
#endif |
37
|
0
|
|
|
|
|
|
default: throw "invalid sockaddr family"; |
38
|
|
|
|
|
|
|
} |
39
|
90
|
50
|
|
|
|
|
auto base = Simple(panda::string_view(reinterpret_cast(&var), sz)); |
40
|
45
|
50
|
|
|
|
|
return stash.bless(base).ref(); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
20
|
50
|
|
|
|
|
}} |
|
|
50
|
|
|
|
|
|