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

Method link

src/process.cpp:1584–1705  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1582
1583
1584void SocketManager::link(
1585 ProcessBase* process,
1586 const UPID& to,
1587 const ProcessBase::RemoteConnection remote,
1588 const SocketImpl::Kind& kind)
1589{
1590 // TODO(benh): The semantics we want to support for link are such
1591 // that if there is nobody to link to (local or remote) then an
1592 // ExitedEvent gets generated. This functionality has only been
1593 // implemented when the link is local, not remote. Of course, if
1594 // there is nobody listening on the remote side, then this should
1595 // work remotely ... but if there is someone listening remotely just
1596 // not at that id, then it will silently continue executing.
1597
1598 CHECK_NOTNULL(process);
1599
1600 Option<Socket> socket = None();
1601 bool connect = false;
1602
1603 synchronized (mutex) {
1604 // Check if the socket address is remote.
1605 if (to.address != __address__) {
1606 // Check if there isn't already a persistent link.
1607 if (persists.count(to.address) == 0) {
1608 // Okay, no link, let's create a socket.
1609 // The kind of socket we create is passed in as an argument.
1610 // This allows us to support downgrading the connection type
1611 // from SSL to POLL if enabled.
1612 Try<Socket> create = Socket::create(kind);
1613 if (create.isError()) {
1614 LOG(WARNING) << "Failed to link to '" << to.address
1615 << "', create socket: " << create.error();
1616
1617 // Failure to create a new socket should generate an `ExitedEvent`
1618 // for the linkee. At this point, we have not passed ownership of
1619 // this socket to the `SocketManager`, so there is only one possible
1620 // linkee to notify.
1621 process_manager->deliver(process, new ExitedEvent(to));
1622 return;
1623 }
1624 socket = create.get();
1625 int_fd s = socket->get();
1626
1627 CHECK(sockets.count(s) == 0);
1628 sockets.emplace(s, socket.get());
1629
1630 addresses.emplace(s, to.address);
1631
1632 persists.emplace(to.address, s);
1633
1634 // Initialize 'outgoing' to prevent a race with
1635 // SocketManager::send() while the socket is not yet connected.
1636 // Initializing the 'outgoing' queue prevents
1637 // SocketManager::send() from trying to write before it's
1638 // connected.
1639 outgoing[s];
1640
1641 connect = true;

Callers

nothing calls this directly

Calls 4

bindFunction · 0.85
deliverMethod · 0.80
connectSocketFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected