MCPcopy Create free account
hub / github.com/3rdparty/libprocess / main

Function main

src/tests/test_linkee.cpp:96–203  ·  view source on GitHub ↗

* This process provides a target for testing remote link semantics * in libprocess. * * When this process starts up, it sends a message to the provided UPID. * This message is a notification that the test-linkee is ready to be * linked against and also allows the parent to discover the linkee's UPID. * * In order to test "stale" links, this process will exit upon receiving * a message. Thi

Source from the content-addressed store, hash-verified

94 * a message. This gives a clear signal that a message was received.
95 */
96int main(int argc, char** argv)
97{
98 if (argc <= 1) {
99 EXIT(EXIT_FAILURE) << "Usage: test-linkee <UPID>";
100 }
101
102 // NOTE: On Windows, this initialization must take place before creating a
103 // `Socket`, otherwise the IOCP handle will be uninitialized. See MESOS-9097.
104 process::initialize();
105
106 // Create a server socket.
107 Try<Socket> create = Socket::create();
108 if (create.isError()) {
109 EXIT(EXIT_FAILURE)
110 << "Failed to create server socket: " << create.error();
111 }
112 __s__ = new Socket(create.get());
113
114 // Allow address reuse.
115 // NOTE: We cast to `char*` here because the function prototypes on Windows
116 // use `char*` instead of `void*`.
117 int on = 1;
118 if (::setsockopt(
119 __s__->get(),
120 SOL_SOCKET,
121 SO_REUSEADDR,
122 reinterpret_cast<char*>(&on),
123 sizeof(on)) < 0) {
124 EXIT(EXIT_FAILURE)
125 << "Failed to setsockopt(SO_REUSEADDR): " << ErrnoError().message;
126 }
127
128 // Bind to some random port.
129 Try<Address> bind = __s__->bind(inet4::Address::ANY_ANY());
130 if (bind.isError()) {
131 EXIT(EXIT_FAILURE) << "Failed to bind: " << bind.error();
132 }
133
134 Address address = bind.get();
135
136 // Resolve the hostname if the IP is 0.0.0.0 in case we actually have
137 // a valid external IP address. Note that we need only one IP address,
138 // so that other processes can send and receive and don't get confused
139 // as to whom they are sending to.
140 //
141 // This code is copied from process::initialize(), so it matches
142 // how libprocess proper sets up its listening socket.
143 if (address.ip.isAny()) {
144 char hostname[512];
145
146 if (gethostname(hostname, sizeof(hostname)) < 0) {
147 PLOG(FATAL) << "Failed to get the local hostname";
148 }
149
150 // Lookup an IP address of local hostname, taking the first result.
151 Try<net::IP> ip = net::getIP(hostname, address.ip.family());
152
153 if (ip.isError()) {

Callers

nothing calls this directly

Calls 13

bindFunction · 0.85
UPIDClass · 0.85
familyMethod · 0.80
isReadyMethod · 0.80
isFailedMethod · 0.80
initializeFunction · 0.50
encodeFunction · 0.50
getMethod · 0.45
bindMethod · 0.45
listenMethod · 0.45
acceptMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected