MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / process_hello_common

Function process_hello_common

net/net.c:4252–4294  ·  view source on GitHub ↗

Common code for processing hello and hello reply. * * Inputs: look_for_magic==1 if we want to check for the MAGICNODE. * * Returns: * 1 Hello was rejected (contained bad port numbers or error in * read_hostlist). * -1 IO error, reader thread cleans up. * 0 Success. */

Source from the content-addressed store, hash-verified

4250 * 0 Success.
4251 */
4252static int process_hello_common(netinfo_type *netinfo_ptr,
4253 host_node_type *host_node_ptr,
4254 int look_for_magic)
4255{
4256 char *hosts[REPMAX];
4257 int ports[REPMAX];
4258 host_node_type *newhost, *fndhost;
4259 int rc;
4260 int numhosts = REPMAX;
4261
4262 rc = read_hostlist(netinfo_ptr, host_node_ptr->sb, hosts, ports, &numhosts);
4263 if (rc < 0)
4264 return -1; /* reader thread cleans up */
4265 if (rc != 0) {
4266 logmsg(LOGMSG_ERROR,
4267 "process_hello_common:error from read_hostlist, rc=%d\n", rc);
4268 return 0;
4269 }
4270
4271 /* add each host, dont worry, dupes wont be added */
4272 for (int i = 0; i < numhosts; i++) {
4273 // only truly new hosts will return non-NULL
4274 newhost = add_to_netinfo(netinfo_ptr, intern(hosts[i]), ports[i]);
4275
4276 if (newhost != NULL) {
4277 /* get readlock to prevent host from disappearing */
4278 Pthread_rwlock_rdlock(&(netinfo_ptr->lock));
4279
4280 fndhost = get_host_node_by_name_ll(netinfo_ptr, intern(hosts[i]));
4281 if (fndhost)
4282 connect_to_host(netinfo_ptr, fndhost, host_node_ptr);
4283
4284 Pthread_rwlock_unlock(&(netinfo_ptr->lock));
4285 }
4286
4287 host_node_ptr->got_hello = 1;
4288 }
4289
4290 for (int i = 0; i < numhosts; i++)
4291 free(hosts[i]);
4292
4293 return 0;
4294}
4295
4296static void *reader_thread(void *arg)
4297{

Callers 2

process_helloFunction · 0.85
process_hello_replyFunction · 0.85

Calls 7

read_hostlistFunction · 0.85
add_to_netinfoFunction · 0.85
internFunction · 0.85
get_host_node_by_name_llFunction · 0.85
connect_to_hostFunction · 0.85
freeFunction · 0.85
logmsgFunction · 0.50

Tested by

no test coverage detected