MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / FindAvailablePort

Method FindAvailablePort

oneflow/core/control/ctrl_util.cpp:46–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44} // namespace
45
46int CtrlUtil::FindAvailablePort() const {
47 int sock = socket(AF_INET, SOCK_STREAM, 0);
48
49 for (uint16_t port = 10000; port < GetMaxVal<uint16_t>(); ++port) {
50 sockaddr_in sa = GetSockAddr("0.0.0.0", port);
51 int bind_result = bind(sock, reinterpret_cast<sockaddr*>(&sa), sizeof(sa));
52 if (bind_result == 0) {
53 shutdown(sock, SHUT_RDWR);
54 close(sock);
55 return port;
56 }
57 }
58 return -1;
59}
60
61#else
62

Callers 1

TESTFunction · 0.80

Calls 2

bindFunction · 0.85
GetSockAddrFunction · 0.70

Tested by 1

TESTFunction · 0.64