MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_con_nodes

Function ng_con_nodes

lib/ff_ng_base.c:1483–1527  ·  view source on GitHub ↗

* Connect this node with another node. We assume that this node is * currently locked, as we are only called from an NGM_CONNECT message. */

Source from the content-addressed store, hash-verified

1481 * currently locked, as we are only called from an NGM_CONNECT message.
1482 */
1483static int
1484ng_con_nodes(item_p item, node_p node, const char *name,
1485 node_p node2, const char *name2)
1486{
1487 int error;
1488 hook_p hook;
1489 hook_p hook2;
1490
1491 if (ng_findhook(node2, name2) != NULL) {
1492 return(EEXIST);
1493 }
1494 if ((error = ng_add_hook(node, name, &hook))) /* gives us a ref */
1495 return (error);
1496 /* Allocate the other hook and link it up */
1497 NG_ALLOC_HOOK(hook2);
1498 if (hook2 == NULL) {
1499 TRAP_ERROR();
1500 ng_destroy_hook(hook); /* XXX check ref counts so far */
1501 NG_HOOK_UNREF(hook); /* including our ref */
1502 return (ENOMEM);
1503 }
1504 hook2->hk_refs = 1; /* start with a reference for us. */
1505 hook2->hk_flags = HK_INVALID;
1506 hook2->hk_peer = hook; /* Link the two together */
1507 hook->hk_peer = hook2;
1508 NG_HOOK_REF(hook); /* Add a ref for the peer to each*/
1509 NG_HOOK_REF(hook2);
1510 hook2->hk_node = &ng_deadnode;
1511 strlcpy(NG_HOOK_NAME(hook2), name2, NG_HOOKSIZ);
1512
1513 /*
1514 * Queue the function above.
1515 * Procesing continues in that function in the lock context of
1516 * the other node.
1517 */
1518 if ((error = ng_send_fn2(node2, hook2, item, &ng_con_part2, NULL, 0,
1519 NG_NOFLAGS))) {
1520 printf("failed in ng_con_nodes(): %d\n", error);
1521 ng_destroy_hook(hook); /* also zaps peer */
1522 }
1523
1524 NG_HOOK_UNREF(hook); /* Let each hook go if it wants to */
1525 NG_HOOK_UNREF(hook2);
1526 return (error);
1527}
1528
1529/*
1530 * Make a peer and connect.

Callers 1

ng_generic_msgFunction · 0.70

Calls 6

ng_findhookFunction · 0.70
ng_add_hookFunction · 0.70
ng_destroy_hookFunction · 0.70
ng_send_fn2Function · 0.70
printfFunction · 0.70
strlcpyFunction · 0.50

Tested by

no test coverage detected