Commit 6ea0b78f authored by Philip Carns's avatar Philip Carns
Browse files

ability to query port if chosen dynamically

parent 6b7498a7
......@@ -87,6 +87,7 @@ enum
BMI_TCP_CHECK_UNEXPECTED = 15,
BMI_ZOID_POST_TIMEOUT = 16,
BMI_TRANSPORT_METHODS_STRING = 17,
BMI_TCP_GET_PORT = 18,
};
enum BMI_io_type
......
......@@ -1440,7 +1440,22 @@ int BMI_get_info(BMI_addr_t addr,
return ret;
}
break;
case BMI_TCP_GET_PORT:
gen_mutex_lock(&active_method_count_mutex);
/* look through active methods for one that will answer this */
for (i = 0; i < active_method_count; i++)
{
ret = active_method_table[i]->get_info(
option, inout_parameter);
if (ret == 0)
{
gen_mutex_unlock(&active_method_count_mutex);
return (ret);
}
}
gen_mutex_unlock(&active_method_count_mutex);
return ret;
break;
case BMI_TRANSPORT_METHODS_STRING:
{
/*
......
......@@ -1014,7 +1014,12 @@ int BMI_tcp_get_info(int option,
*((int *) inout_parameter) = TCP_MODE_EAGER_LIMIT;
ret = 0;
break;
case BMI_TCP_GET_PORT:
if(tcp_socket_collection_p)
*((int*)inout_parameter) = tcp_socket_collection_p->server_port;
else
*((int*)inout_parameter) = 0;
break;
default:
gossip_ldebug(GOSSIP_BMI_DEBUG_TCP,
"TCP hint %d not implemented.\n", option);
......@@ -1978,7 +1983,6 @@ static int tcp_server_init(void)
/* bind it to the appropriate port */
if(tcp_method_params.method_flags & BMI_TCP_BIND_SPECIFIC)
{
fprintf(stderr, "FOO: binding hostname %s, port %d\n", tcp_addr_data->hostname, tcp_addr_data->port);
ret = BMI_sockio_bind_sock_specific(tcp_addr_data->socket,
tcp_addr_data->hostname,
tcp_addr_data->port);
......
......@@ -56,6 +56,7 @@ socket_collection_p BMI_socket_collection_init(int new_server_socket)
}
memset(tmp_scp, 0, sizeof(struct socket_collection));
tmp_scp->server_port = -1;
tmp_scp->epfd = epoll_create(EPOLL_CREATE_SIZE);
if(tmp_scp->epfd < 0)
......@@ -69,6 +70,9 @@ socket_collection_p BMI_socket_collection_init(int new_server_socket)
if(new_server_socket > -1)
{
struct sockaddr_in addr;
socklen_t addr_len = sizeof(addr);
memset(&event, 0, sizeof(event));
event.events = (EPOLLIN|EPOLLERR|EPOLLHUP);
event.data.ptr = NULL;
......@@ -80,6 +84,20 @@ socket_collection_p BMI_socket_collection_init(int new_server_socket)
free(tmp_scp);
return(NULL);
}
/* determine what port the server socket is bound to, in case the
* port was auto-assigned
*/
ret = getsockname(new_server_socket, (struct sockaddr *)&addr, &addr_len);
if(ret < 0)
{
/* shrug */
tmp_scp->server_port = 0;
}
else
{
tmp_scp->server_port = ntohs(addr.sin_port);
}
}
return (tmp_scp);
......
......@@ -35,6 +35,7 @@ struct socket_collection
struct epoll_event event_array[BMI_EPOLL_MAX_PER_CYCLE];
int server_socket;
int server_port;
};
typedef struct socket_collection* socket_collection_p;
......
......@@ -54,6 +54,7 @@ socket_collection_p BMI_socket_collection_init(int new_server_socket)
}
memset(tmp_scp, 0, sizeof(struct socket_collection));
tmp_scp->server_port = -1;
gen_mutex_init(&tmp_scp->queue_mutex);
......@@ -93,6 +94,21 @@ socket_collection_p BMI_socket_collection_init(int new_server_socket)
tmp_scp->pollfd_array[tmp_scp->array_count].events = POLLIN;
tmp_scp->addr_array[tmp_scp->array_count] = NULL;
tmp_scp->array_count++;
/* determine what port the server socket is bound to, in case the
* port was auto-assigned
*/
ret = getsockname(new_server_socket, (struct sockaddr *)&addr, &addr_len);
if(ret < 0)
{
/* shrug */
tmp_scp->server_port = 0;
}
else
{
tmp_scp->server_port = ntohs(addr.sin_port);
}
}
/* Add the pipe_fd[0] fd to the poll in set always */
......
......@@ -36,6 +36,7 @@ struct socket_collection
struct qlist_head add_queue;
int server_socket;
int server_port;
int pipe_fd[2];
};
typedef struct socket_collection* socket_collection_p;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment