Minor fixes with list.

This commit is contained in:
Nicolás Ortega Froysa 2017-08-05 16:29:45 -05:00
parent afe5f6ae4e
commit e82514a56a
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF

View File

@ -130,6 +130,7 @@ void *NeoComm_connect_manager() {
NeoComm_error("Error on accept");
continue;
}
++num_nodes;
// TODO: Add the new connection and have it listen on a new thread.
}
pthread_exit(NULL);
@ -187,11 +188,13 @@ void NeoComm_shutdown_directory() {
pthread_join(node_list[i].thread, &res);
close(node_list[i].sockfd);
}
num_nodes = 0;
pthread_join(accept_thread, &res);
close(sockfd);
free(node_list);
node_list = NULL;
max_nodes = 0;
pthread_exit(NULL);
}
@ -221,6 +224,8 @@ int NeoComm_resize_directory(const unsigned int new_max_num_nodes) {
for(unsigned int i = max_nodes; i < new_max_num_nodes; ++i)
node_list[i].in_use = 0;
max_nodes = new_max_num_nodes;
return 1;
}
@ -233,7 +238,7 @@ unsigned int NeoComm_get_num_nodes() {
}
int NeoComm_add_node(const struct NeoComm_address addr) {
struct hostent *host;
struct hostent *host = NULL;
host = gethostbyname(addr.address);
if(!host)
{
@ -247,21 +252,29 @@ int NeoComm_add_node(const struct NeoComm_address addr) {
if(!node_list[i].in_use)
new_node = &node_list[i];
}
if(!new_node)
{
NeoComm_error("No more unused slots in directory");
return 0;
}
bzero((char*) &new_node->addr, sizeof(new_node->addr));
new_node->addr.sin_family = AF_INET;
bcopy((char*) host->h_addr,
bcopy((char*) host->h_addr_list[0],
(char*) &new_node->addr.sin_addr.s_addr,
host->h_length);
new_node->addr.sin_port = htons(addr.port);
if(connect(new_node->sockfd, (struct sockaddr*) &new_node->addr,
if(connect(new_node->sockfd,
(struct sockaddr*) &new_node->addr,
sizeof(new_node->addr)) < 0)
{
NeoComm_error("Failed to connect to new node");
return 0;
}
new_node->in_use = 1;
++num_nodes;
// TODO: listen to node on new thread
return 1;
}