-
Notifications
You must be signed in to change notification settings - Fork 0
/
xsrv.h
77 lines (66 loc) · 2.96 KB
/
xsrv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// This file is part of the casycom project
//
// Copyright (c) 2015 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.
#pragma once
#include "xcom.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*MFN_ExternServer_Open)(void* vo, int fd, const iid_t* exportedInterfaces, bool closeWhenEmpty);
typedef void (*MFN_ExternServer_Close)(void* vo);
typedef struct _DExternServer {
iid_t interface;
MFN_ExternServer_Open ExternServer_Open;
MFN_ExternServer_Close ExternServer_Close;
} DExternServer;
void PExternServer_Open (const Proxy* pp, int fd, const iid_t* exportedInterfaces, bool closeWhenEmpty) noexcept NONNULL(1);
void PExternServer_Close (const Proxy* pp) noexcept NONNULL();
int PExternServer_Bind (const Proxy* pp, const struct sockaddr* addr, socklen_t addrlen, const iid_t* exportedInterfaces) noexcept NONNULL();
int PExternServer_BindLocal (const Proxy* pp, const char* path, const iid_t* exportedInterfaces) noexcept NONNULL();
int PExternServer_BindUserLocal (const Proxy* pp, const char* sockname, const iid_t* exportedInterfaces) noexcept NONNULL();
int PExternServer_BindSystemLocal (const Proxy* pp, const char* sockname, const iid_t* exportedInterfaces) noexcept NONNULL();
extern const Interface i_ExternServer;
extern const Factory f_ExternServer;
//{{{ PExternServer_Bind variants --------------------------------------
#ifdef __cplusplus
namespace {
#endif
/// Create local IPv4 socket at given ip and port
static inline int PExternServer_BindIP4 (const Proxy* pp, in_addr_t ip, in_port_t port, const iid_t* exportedInterfaces)
{
struct sockaddr_in addr = {
.sin_family = PF_INET,
.sin_addr = { ip },
.sin_port = port
};
return PExternServer_Bind (pp, (const struct sockaddr*) &addr, sizeof(addr), exportedInterfaces);
}
/// Create local IPv4 socket at given port on the loopback interface
static inline int PExternServer_BindLocalIP4 (const Proxy* pp, in_port_t port, const iid_t* exportedInterfaces)
{ return PExternServer_BindIP4 (pp, INADDR_LOOPBACK, port, exportedInterfaces); }
/// Create local IPv6 socket at given ip and port
static inline int PExternServer_BindIP6 (const Proxy* pp, struct in6_addr ip, in_port_t port, const iid_t* exportedInterfaces)
{
struct sockaddr_in6 addr = {
.sin6_family = PF_INET6,
.sin6_addr = ip,
.sin6_port = port
};
return PExternServer_Bind (pp, (const struct sockaddr*) &addr, sizeof(addr), exportedInterfaces);
}
/// Create local IPv6 socket at given ip and port
static inline int PExternServer_BindLocalIP6 (const Proxy* pp, in_port_t port, const iid_t* exportedInterfaces)
{
struct sockaddr_in6 addr = {
.sin6_family = PF_INET6,
.sin6_addr = IN6ADDR_LOOPBACK_INIT,
.sin6_port = port
};
return PExternServer_Bind (pp, (const struct sockaddr*) &addr, sizeof(addr), exportedInterfaces);
}
#ifdef __cplusplus
} // namespace
} // extern "C"
#endif
//}}}-------------------------------------------------------------------