Minor fixes with list.
This commit is contained in:
parent
afe5f6ae4e
commit
e82514a56a
@ -130,6 +130,7 @@ void *NeoComm_connect_manager() {
|
|||||||
NeoComm_error("Error on accept");
|
NeoComm_error("Error on accept");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
++num_nodes;
|
||||||
// TODO: Add the new connection and have it listen on a new thread.
|
// TODO: Add the new connection and have it listen on a new thread.
|
||||||
}
|
}
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
@ -187,11 +188,13 @@ void NeoComm_shutdown_directory() {
|
|||||||
pthread_join(node_list[i].thread, &res);
|
pthread_join(node_list[i].thread, &res);
|
||||||
close(node_list[i].sockfd);
|
close(node_list[i].sockfd);
|
||||||
}
|
}
|
||||||
|
num_nodes = 0;
|
||||||
pthread_join(accept_thread, &res);
|
pthread_join(accept_thread, &res);
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
|
|
||||||
free(node_list);
|
free(node_list);
|
||||||
node_list = NULL;
|
node_list = NULL;
|
||||||
|
max_nodes = 0;
|
||||||
|
|
||||||
pthread_exit(NULL);
|
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)
|
for(unsigned int i = max_nodes; i < new_max_num_nodes; ++i)
|
||||||
node_list[i].in_use = 0;
|
node_list[i].in_use = 0;
|
||||||
|
|
||||||
|
max_nodes = new_max_num_nodes;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +238,7 @@ unsigned int NeoComm_get_num_nodes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int NeoComm_add_node(const struct NeoComm_address addr) {
|
int NeoComm_add_node(const struct NeoComm_address addr) {
|
||||||
struct hostent *host;
|
struct hostent *host = NULL;
|
||||||
host = gethostbyname(addr.address);
|
host = gethostbyname(addr.address);
|
||||||
if(!host)
|
if(!host)
|
||||||
{
|
{
|
||||||
@ -247,21 +252,29 @@ int NeoComm_add_node(const struct NeoComm_address addr) {
|
|||||||
if(!node_list[i].in_use)
|
if(!node_list[i].in_use)
|
||||||
new_node = &node_list[i];
|
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));
|
bzero((char*) &new_node->addr, sizeof(new_node->addr));
|
||||||
new_node->addr.sin_family = AF_INET;
|
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,
|
(char*) &new_node->addr.sin_addr.s_addr,
|
||||||
host->h_length);
|
host->h_length);
|
||||||
new_node->addr.sin_port = htons(addr.port);
|
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)
|
sizeof(new_node->addr)) < 0)
|
||||||
{
|
{
|
||||||
NeoComm_error("Failed to connect to new node");
|
NeoComm_error("Failed to connect to new node");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
new_node->in_use = 1;
|
new_node->in_use = 1;
|
||||||
|
++num_nodes;
|
||||||
|
|
||||||
// TODO: listen to node on new thread
|
// TODO: listen to node on new thread
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user