| 72 | |
| 73 | |
| 74 | Try<uint16_t> getFreePort() |
| 75 | { |
| 76 | // Bind to port=0 to obtain a random unused port. |
| 77 | Try<inet::Socket> socket = inet::Socket::create(); |
| 78 | |
| 79 | if (socket.isError()) { |
| 80 | return Error(socket.error()); |
| 81 | } |
| 82 | |
| 83 | Try<inet::Address> address = socket->bind(inet4::Address::ANY_ANY()); |
| 84 | |
| 85 | if (address.isError()) { |
| 86 | return Error(address.error()); |
| 87 | } |
| 88 | |
| 89 | return address->port; |
| 90 | |
| 91 | // No explicit cleanup of `socket` as we rely on the implementation |
| 92 | // of `Socket` to close the socket on destruction. |
| 93 | } |
| 94 | |
| 95 | |
| 96 | string getModulePath(const string& name) |
no test coverage detected