[Pvfs2-cvs] commit by aching in pvfs2-1/src/io/bmi/bmi_tcp:
bmi-tcp-addressing.h bmi-tcp.c module.mk.in
socket-collection-epoll.c socket-collection-epoll.h
socket-collection.c socket-collection.h sockio.c sockio.h
CVS commit program
cvs at parl.clemson.edu
Mon Jul 21 14:20:04 EDT 2008
Update of /projects/cvsroot/pvfs2-1/src/io/bmi/bmi_tcp
In directory parlweb1:/tmp/cvs-serv19729/io/bmi/bmi_tcp
Modified Files:
Tag: locking-branch
bmi-tcp-addressing.h bmi-tcp.c module.mk.in
socket-collection-epoll.c socket-collection-epoll.h
socket-collection.c socket-collection.h sockio.c sockio.h
Log Message:
Reverse merged and ported to HEAD.
Index: bmi-tcp-addressing.h
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/bmi/bmi_tcp/bmi-tcp-addressing.h,v
diff -p -u -r1.15 -r1.15.16.1
--- bmi-tcp-addressing.h 11 Sep 2006 20:22:04 -0000 1.15
+++ bmi-tcp-addressing.h 21 Jul 2008 18:20:03 -0000 1.15.16.1
@@ -46,7 +46,8 @@ struct tcp_allowed_connection_s {
* connections are made */
struct tcp_addr
{
- method_addr_p map; /* points back to generic address */
+ bmi_method_addr_p map; /* points back to generic address */ \
+ PVFS_BMI_addr_t bmi_addr;
/* stores error code for addresses that are broken for some reason */
int addr_error;
char *hostname;
@@ -77,10 +78,10 @@ struct tcp_addr
#define bmi_tcp_errno_to_pvfs bmi_errno_to_pvfs
-void tcp_forget_addr(method_addr_p map,
+void tcp_forget_addr(bmi_method_addr_p map,
int dealloc_flag,
int error_code);
-method_addr_p alloc_tcp_method_addr(void);
+bmi_method_addr_p alloc_tcp_method_addr(void);
#endif /* __BMI_TCP_ADDRESSING_H */
Index: bmi-tcp.c
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/bmi/bmi_tcp/bmi-tcp.c,v
diff -p -u -r1.108 -r1.108.4.1
--- bmi-tcp.c 11 Sep 2006 20:22:04 -0000 1.108
+++ bmi-tcp.c 21 Jul 2008 18:20:03 -0000 1.108.4.1
@@ -55,7 +55,7 @@
static gen_mutex_t interface_mutex = GEN_MUTEX_INITIALIZER;
/* function prototypes */
-int BMI_tcp_initialize(method_addr_p listen_addr,
+int BMI_tcp_initialize(bmi_method_addr_p listen_addr,
int method_id,
int init_flags);
int BMI_tcp_finalize(void);
@@ -70,7 +70,7 @@ int BMI_tcp_memfree(void *buffer,
enum bmi_op_type send_recv);
int BMI_tcp_unexpected_free(void *buffer);
int BMI_tcp_post_send(bmi_op_id_t * id,
- method_addr_p dest,
+ bmi_method_addr_p dest,
const void *buffer,
bmi_size_t size,
enum bmi_buffer_type buffer_type,
@@ -78,7 +78,7 @@ int BMI_tcp_post_send(bmi_op_id_t * id,
void *user_ptr,
bmi_context_id context_id);
int BMI_tcp_post_sendunexpected(bmi_op_id_t * id,
- method_addr_p dest,
+ bmi_method_addr_p dest,
const void *buffer,
bmi_size_t size,
enum bmi_buffer_type buffer_type,
@@ -86,7 +86,7 @@ int BMI_tcp_post_sendunexpected(bmi_op_i
void *user_ptr,
bmi_context_id context_id);
int BMI_tcp_post_recv(bmi_op_id_t * id,
- method_addr_p src,
+ bmi_method_addr_p src,
void *buffer,
bmi_size_t expected_size,
bmi_size_t * actual_size,
@@ -112,7 +112,7 @@ int BMI_tcp_testsome(int incount,
bmi_context_id context_id);
int BMI_tcp_testunexpected(int incount,
int *outcount,
- struct method_unexpected_info *info,
+ struct bmi_method_unexpected_info *info,
int max_idle_time_ms);
int BMI_tcp_testcontext(int incount,
bmi_op_id_t * out_id_array,
@@ -122,11 +122,11 @@ int BMI_tcp_testcontext(int incount,
void **user_ptr_array,
int max_idle_time_ms,
bmi_context_id context_id);
-method_addr_p BMI_tcp_method_addr_lookup(const char *id_string);
-const char* BMI_tcp_addr_rev_lookup_unexpected(method_addr_p map);
-int BMI_tcp_query_addr_range(method_addr_p, const char *, int);
+bmi_method_addr_p BMI_tcp_method_addr_lookup(const char *id_string);
+const char* BMI_tcp_addr_rev_lookup_unexpected(bmi_method_addr_p map);
+int BMI_tcp_query_addr_range(bmi_method_addr_p, const char *, int);
int BMI_tcp_post_send_list(bmi_op_id_t * id,
- method_addr_p dest,
+ bmi_method_addr_p dest,
const void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -136,7 +136,7 @@ int BMI_tcp_post_send_list(bmi_op_id_t *
void *user_ptr,
bmi_context_id context_id);
int BMI_tcp_post_recv_list(bmi_op_id_t * id,
- method_addr_p src,
+ bmi_method_addr_p src,
void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -147,7 +147,7 @@ int BMI_tcp_post_recv_list(bmi_op_id_t *
void *user_ptr,
bmi_context_id context_id);
int BMI_tcp_post_sendunexpected_list(bmi_op_id_t * id,
- method_addr_p dest,
+ bmi_method_addr_p dest,
const void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -221,11 +221,11 @@ static struct iovec stat_io_vector[BMI_T
/* internal utility functions */
static int tcp_server_init(void);
-static void dealloc_tcp_method_addr(method_addr_p map);
-static int tcp_sock_init(method_addr_p my_method_addr);
+static void dealloc_tcp_method_addr(bmi_method_addr_p map);
+static int tcp_sock_init(bmi_method_addr_p my_method_addr);
static int enqueue_operation(op_list_p target_list,
enum bmi_op_type send_recv,
- method_addr_p map,
+ bmi_method_addr_p map,
void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -238,12 +238,12 @@ static int enqueue_operation(op_list_p t
bmi_size_t actual_size,
bmi_size_t expected_size,
bmi_context_id context_id);
-static int tcp_cleanse_addr(method_addr_p map, int error_code);
-static int tcp_shutdown_addr(method_addr_p map);
+static int tcp_cleanse_addr(bmi_method_addr_p map, int error_code);
+static int tcp_shutdown_addr(bmi_method_addr_p map);
static int tcp_do_work(int max_idle_time);
-static int tcp_do_work_error(method_addr_p map);
-static int tcp_do_work_recv(method_addr_p map, int* stall_flag);
-static int tcp_do_work_send(method_addr_p map, int* stall_flag);
+static int tcp_do_work_error(bmi_method_addr_p map);
+static int tcp_do_work_recv(bmi_method_addr_p map, int* stall_flag);
+static int tcp_do_work_send(bmi_method_addr_p map, int* stall_flag);
static int work_on_recv_op(method_op_p my_method_op,
int *stall_flag);
static int work_on_send_op(method_op_p my_method_op,
@@ -251,9 +251,9 @@ static int work_on_send_op(method_op_p m
static int tcp_accept_init(int *socket, char** peer);
static method_op_p alloc_tcp_method_op(void);
static void dealloc_tcp_method_op(method_op_p old_op);
-static int handle_new_connection(method_addr_p map);
+static int handle_new_connection(bmi_method_addr_p map);
static int BMI_tcp_post_send_generic(bmi_op_id_t * id,
- method_addr_p dest,
+ bmi_method_addr_p dest,
const void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -262,7 +262,7 @@ static int BMI_tcp_post_send_generic(bmi
void *user_ptr,
bmi_context_id context_id);
static int tcp_post_recv_generic(bmi_op_id_t * id,
- method_addr_p src,
+ bmi_method_addr_p src,
void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -287,35 +287,40 @@ static int tcp_allow_trusted(struct sock
static void bmi_set_sock_buffers(int socket);
/* exported method interface */
-struct bmi_method_ops bmi_tcp_ops = {
+const struct bmi_method_ops bmi_tcp_ops = {
.method_name = BMI_tcp_method_name,
- .BMI_meth_initialize = BMI_tcp_initialize,
- .BMI_meth_finalize = BMI_tcp_finalize,
- .BMI_meth_set_info = BMI_tcp_set_info,
- .BMI_meth_get_info = BMI_tcp_get_info,
- .BMI_meth_memalloc = BMI_tcp_memalloc,
- .BMI_meth_memfree = BMI_tcp_memfree,
- .BMI_meth_unexpected_free = BMI_tcp_unexpected_free,
- .BMI_meth_post_send = BMI_tcp_post_send,
- .BMI_meth_post_sendunexpected = BMI_tcp_post_sendunexpected,
- .BMI_meth_post_recv = BMI_tcp_post_recv,
- .BMI_meth_test = BMI_tcp_test,
- .BMI_meth_testsome = BMI_tcp_testsome,
- .BMI_meth_testcontext = BMI_tcp_testcontext,
- .BMI_meth_testunexpected = BMI_tcp_testunexpected,
- .BMI_meth_method_addr_lookup = BMI_tcp_method_addr_lookup,
- .BMI_meth_post_send_list = BMI_tcp_post_send_list,
- .BMI_meth_post_recv_list = BMI_tcp_post_recv_list,
- .BMI_meth_post_sendunexpected_list = BMI_tcp_post_sendunexpected_list,
- .BMI_meth_open_context = BMI_tcp_open_context,
- .BMI_meth_close_context = BMI_tcp_close_context,
- .BMI_meth_cancel = BMI_tcp_cancel,
- .BMI_meth_rev_lookup_unexpected = BMI_tcp_addr_rev_lookup_unexpected,
- .BMI_meth_query_addr_range = BMI_tcp_query_addr_range,
+ .initialize = BMI_tcp_initialize,
+ .finalize = BMI_tcp_finalize,
+ .set_info = BMI_tcp_set_info,
+ .get_info = BMI_tcp_get_info,
+ .memalloc = BMI_tcp_memalloc,
+ .memfree = BMI_tcp_memfree,
+ .unexpected_free = BMI_tcp_unexpected_free,
+ .post_send = BMI_tcp_post_send,
+ .post_sendunexpected = BMI_tcp_post_sendunexpected,
+ .post_recv = BMI_tcp_post_recv,
+ .test = BMI_tcp_test,
+ .testsome = BMI_tcp_testsome,
+ .testcontext = BMI_tcp_testcontext,
+ .testunexpected = BMI_tcp_testunexpected,
+ .method_addr_lookup = BMI_tcp_method_addr_lookup,
+ .post_send_list = BMI_tcp_post_send_list,
+ .post_recv_list = BMI_tcp_post_recv_list,
+ .post_sendunexpected_list = BMI_tcp_post_sendunexpected_list,
+ .open_context = BMI_tcp_open_context,
+ .close_context = BMI_tcp_close_context,
+ .cancel = BMI_tcp_cancel,
+ .rev_lookup_unexpected = BMI_tcp_addr_rev_lookup_unexpected,
+ .query_addr_range = BMI_tcp_query_addr_range,
};
/* module parameters */
-static method_params_st tcp_method_params;
+static struct
+{
+ int method_flags;
+ int method_id;
+ bmi_method_addr_p listen_addr;
+} tcp_method_params;
#if defined(USE_TRUSTED) && defined(__PVFS2_SERVER__)
static struct tcp_allowed_connection_s *gtcp_allowed_connection = NULL;
@@ -395,7 +400,7 @@ static int tcp_buffer_size_send = 0;
*
* returns 0 on success, -errno on failure
*/
-int BMI_tcp_initialize(method_addr_p listen_addr,
+int BMI_tcp_initialize(bmi_method_addr_p listen_addr,
int method_id,
int init_flags)
{
@@ -417,7 +422,7 @@ int BMI_tcp_initialize(method_addr_p lis
gen_mutex_lock(&interface_mutex);
/* zero out our parameter structure and fill it in */
- memset(&tcp_method_params, 0, sizeof(struct method_params));
+ memset(&tcp_method_params, 0, sizeof(tcp_method_params));
tcp_method_params.method_id = method_id;
tcp_method_params.method_flags = init_flags;
@@ -540,15 +545,14 @@ int BMI_tcp_finalize(void)
*
* returns a pointer to method_addr on success, NULL on failure
*/
-method_addr_p BMI_tcp_method_addr_lookup(const char *id_string)
+bmi_method_addr_p BMI_tcp_method_addr_lookup(const char *id_string)
{
char *tcp_string = NULL;
char *delim = NULL;
char *hostname = NULL;
- method_addr_p new_addr = NULL;
+ bmi_method_addr_p new_addr = NULL;
struct tcp_addr *tcp_addr_data = NULL;
int ret = -1;
- char local_tag[] = "NULL";
tcp_string = string_key("tcp", id_string);
if (!tcp_string)
@@ -596,11 +600,6 @@ method_addr_p BMI_tcp_method_addr_lookup
tcp_addr_data->hostname = hostname;
- if (strcmp(hostname, local_tag) == 0)
- {
- new_addr->local_addr = 1;
- }
-
free(tcp_string);
return (new_addr);
}
@@ -619,7 +618,7 @@ void *BMI_tcp_memalloc(bmi_size_t size,
* preferences about how the memory should be configured.
*/
- return (malloc((size_t) size));
+ return (calloc(1,(size_t) size));
}
@@ -740,7 +739,7 @@ int BMI_tcp_set_info(int option,
void *inout_parameter)
{
int ret = -1;
- method_addr_p tmp_addr = NULL;
+ bmi_method_addr_p tmp_addr = NULL;
gen_mutex_lock(&interface_mutex);
@@ -781,7 +780,7 @@ int BMI_tcp_set_info(int option,
}
else
{
- tmp_addr = (method_addr_p) inout_parameter;
+ tmp_addr = (bmi_method_addr_p) inout_parameter;
/* take it out of the socket collection */
tcp_forget_addr(tmp_addr, 1, 0);
ret = 0;
@@ -793,7 +792,7 @@ int BMI_tcp_set_info(int option,
struct tcp_allowed_connection_s *tcp_allowed_connection = NULL;
if (inout_parameter == NULL)
{
- ret = -EINVAL;
+ ret = bmi_tcp_errno_to_pvfs(-EINVAL);
break;
}
else
@@ -807,7 +806,7 @@ int BMI_tcp_set_info(int option,
tcp_allowed_connection = alloc_trusted_connection_info(svc_config->allowed_networks_count);
if (tcp_allowed_connection == NULL)
{
- ret = -ENOMEM;
+ ret = bmi_tcp_errno_to_pvfs(-ENOMEM);
break;
}
#ifdef __PVFS2_SERVER__
@@ -916,7 +915,7 @@ int BMI_tcp_get_info(int option,
* an error and there is no way to reconnect
*/
if(tcp_addr_data->addr_error != 0 &&
- tcp_addr_data->dont_reconnect == 1)
+ tcp_addr_data->dont_reconnect == 1)
{
query->response = 1;
}
@@ -951,7 +950,7 @@ int BMI_tcp_get_info(int option,
* completion, -errno on failure
*/
int BMI_tcp_post_send(bmi_op_id_t * id,
- method_addr_p dest,
+ bmi_method_addr_p dest,
const void *buffer,
bmi_size_t size,
enum bmi_buffer_type buffer_type,
@@ -1006,7 +1005,7 @@ int BMI_tcp_post_send(bmi_op_id_t * id,
* completion, -errno on failure
*/
int BMI_tcp_post_sendunexpected(bmi_op_id_t * id,
- method_addr_p dest,
+ bmi_method_addr_p dest,
const void *buffer,
bmi_size_t size,
enum bmi_buffer_type buffer_type,
@@ -1054,7 +1053,7 @@ int BMI_tcp_post_sendunexpected(bmi_op_i
* completion, -errno on failure
*/
int BMI_tcp_post_recv(bmi_op_id_t * id,
- method_addr_p src,
+ bmi_method_addr_p src,
void *buffer,
bmi_size_t expected_size,
bmi_size_t * actual_size,
@@ -1112,7 +1111,7 @@ int BMI_tcp_test(bmi_op_id_t id,
bmi_context_id context_id)
{
int ret = -1;
- method_op_p query_op = (method_op_p)id_gen_safe_lookup(id);
+ method_op_p query_op = (method_op_p)id_gen_fast_lookup(id);
assert(query_op != NULL);
@@ -1186,7 +1185,7 @@ int BMI_tcp_testsome(int incount,
/* NOTE: this depends on the user passing in valid id's;
* otherwise we segfault.
*/
- query_op = (method_op_p)id_gen_safe_lookup(id_array[i]);
+ query_op = (method_op_p)id_gen_fast_lookup(id_array[i]);
if(((struct tcp_op*)(query_op->method_data))->tcp_op_state ==
BMI_TCP_COMPLETE)
{
@@ -1223,7 +1222,7 @@ int BMI_tcp_testsome(int incount,
*/
int BMI_tcp_testunexpected(int incount,
int *outcount,
- struct method_unexpected_info *info,
+ struct bmi_method_unexpected_info *info,
int max_idle_time)
{
int ret = -1;
@@ -1349,7 +1348,7 @@ int BMI_tcp_testcontext(int incount,
* -errno on failure
*/
int BMI_tcp_post_send_list(bmi_op_id_t * id,
- method_addr_p dest,
+ bmi_method_addr_p dest,
const void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -1407,7 +1406,7 @@ int BMI_tcp_post_send_list(bmi_op_id_t *
* -errno on failure
*/
int BMI_tcp_post_recv_list(bmi_op_id_t * id,
- method_addr_p src,
+ bmi_method_addr_p src,
void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -1451,7 +1450,7 @@ int BMI_tcp_post_recv_list(bmi_op_id_t *
* -errno on failure
*/
int BMI_tcp_post_sendunexpected_list(bmi_op_id_t * id,
- method_addr_p dest,
+ bmi_method_addr_p dest,
const void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -1547,7 +1546,7 @@ int BMI_tcp_cancel(bmi_op_id_t id, bmi_c
gen_mutex_lock(&interface_mutex);
- query_op = (method_op_p)id_gen_safe_lookup(id);
+ query_op = (method_op_p)id_gen_fast_lookup(id);
if(!query_op)
{
/* if we can't find the operattion, then assume that it has already
@@ -1702,15 +1701,21 @@ static int check_octets(struct in_addr a
* Check if a given address is within the network specified by the wildcard string!
* or if it is part of the subnet mask specified
*/
-int BMI_tcp_query_addr_range(method_addr_p map, const char *wildcard_string, int netmask)
+int BMI_tcp_query_addr_range(bmi_method_addr_p map, const char *wildcard_string, int netmask)
{
struct tcp_addr *tcp_addr_data = map->method_data;
struct sockaddr_in map_addr;
socklen_t map_addr_len = sizeof(map_addr);
- char *tcp_wildcard = (char *) wildcard_string + 6 /* strlen("tcp://") */;
+ const char *tcp_wildcard = wildcard_string + 6 /* strlen("tcp://") */;
+ int ret = -1;
memset(&map_addr, 0, sizeof(map_addr));
- getsockname(tcp_addr_data->socket, (struct sockaddr *) &map_addr, &map_addr_len);
+ if(getpeername(tcp_addr_data->socket, (struct sockaddr *) &map_addr, &map_addr_len) < 0)
+ {
+ ret = bmi_tcp_errno_to_pvfs(-EINVAL);
+ gossip_err("Error: failed to retrieve peer name for client.\n");
+ return(ret);
+ }
/* Wildcard specification */
if (netmask == -1)
{
@@ -1757,20 +1762,36 @@ int BMI_tcp_query_addr_range(method_addr
*
* returns string on success, "UNKNOWN" on failure
*/
-const char* BMI_tcp_addr_rev_lookup_unexpected(method_addr_p map)
+const char* BMI_tcp_addr_rev_lookup_unexpected(bmi_method_addr_p map)
{
struct tcp_addr *tcp_addr_data = map->method_data;
-
-#if !defined(__PVFS2_BMI_REV_LOOKUP_HOSTNAME__) || !defined(HAVE_GETHOSTBYADDR)
- return(tcp_addr_data->peer);
-
-#else
- socklen_t peerlen = sizeof(struct sockaddr_in);
+ int debug_on;
+ uint64_t mask;
+ socklen_t peerlen;
struct sockaddr_in peer;
int ret;
struct hostent *peerent;
char* tmp_peer;
+ /* return default response if we don't have support for the right socket
+ * calls
+ */
+#if !defined(HAVE_GETHOSTBYADDR)
+ return(tcp_addr_data->peer);
+#else
+
+ /* Only resolve hostnames if a gossip mask is set to request it.
+ * Otherwise we leave it at ip address
+ */
+ gossip_get_debug_mask(&debug_on, &mask);
+
+ if(!debug_on || (!(mask & GOSSIP_ACCESS_HOSTNAMES)))
+ {
+ return(tcp_addr_data->peer);
+ }
+
+ peerlen = sizeof(struct sockaddr_in);
+
if(tcp_addr_data->peer_type == BMI_TCP_PEER_HOSTNAME)
{
/* full hostname already cached; return now */
@@ -1821,13 +1842,14 @@ const char* BMI_tcp_addr_rev_lookup_unex
*
* no return value
*/
-void tcp_forget_addr(method_addr_p map,
+void tcp_forget_addr(bmi_method_addr_p map,
int dealloc_flag,
int error_code)
{
struct tcp_addr* tcp_addr_data = map->method_data;
+ PVFS_BMI_addr_t bmi_addr = tcp_addr_data->bmi_addr;
int tmp_outcount;
- method_addr_p tmp_addr;
+ bmi_method_addr_p tmp_addr;
int tmp_status;
if (tcp_socket_collection_p)
@@ -1839,6 +1861,7 @@ void tcp_forget_addr(method_addr_p map,
BMI_socket_collection_testglobal(tcp_socket_collection_p,
0, &tmp_outcount, &tmp_addr, &tmp_status, 0, &interface_mutex);
}
+
tcp_shutdown_addr(map);
tcp_cleanse_addr(map, error_code);
tcp_addr_data->addr_error = error_code;
@@ -1846,6 +1869,13 @@ void tcp_forget_addr(method_addr_p map,
{
dealloc_tcp_method_addr(map);
}
+ else
+ {
+ /* this will cause the bmi control layer to check to see if
+ * this address can be completely forgotten
+ */
+ bmi_method_addr_forget_callback(bmi_addr);
+ }
return;
};
@@ -1861,7 +1891,7 @@ void tcp_forget_addr(method_addr_p map,
*
* no return value
*/
-static void dealloc_tcp_method_addr(method_addr_p map)
+static void dealloc_tcp_method_addr(bmi_method_addr_p map)
{
struct tcp_addr *tcp_addr_data = NULL;
@@ -1883,7 +1913,7 @@ static void dealloc_tcp_method_addr(meth
if (tcp_addr_data->peer)
free(tcp_addr_data->peer);
- dealloc_method_addr(map);
+ bmi_dealloc_method_addr(map);
return;
}
@@ -1896,14 +1926,14 @@ static void dealloc_tcp_method_addr(meth
*
* returns pointer to struct on success, NULL on failure
*/
-method_addr_p alloc_tcp_method_addr(void)
+bmi_method_addr_p alloc_tcp_method_addr(void)
{
- struct method_addr *my_method_addr = NULL;
+ struct bmi_method_addr *my_method_addr = NULL;
struct tcp_addr *tcp_addr_data = NULL;
my_method_addr =
- alloc_method_addr(tcp_method_params.method_id, sizeof(struct tcp_addr));
+ bmi_alloc_method_addr(tcp_method_params.method_id, sizeof(struct tcp_addr));
if (!my_method_addr)
{
return (NULL);
@@ -1964,6 +1994,12 @@ static int tcp_server_init(void)
ret = BMI_sockio_bind_sock_specific(tcp_addr_data->socket,
tcp_addr_data->hostname,
tcp_addr_data->port);
+ /* NOTE: this particular function converts errno in advance */
+ if(ret < 0)
+ {
+ PVFS_perror_gossip("BMI_sockio_bind_sock_specific", ret);
+ return(ret);
+ }
}
else
{
@@ -1998,7 +2034,7 @@ static int tcp_server_init(void)
*
* returns pointer to operation on success, NULL if nothing found.
*/
-static method_op_p find_recv_inflight(method_addr_p map)
+static method_op_p find_recv_inflight(bmi_method_addr_p map)
{
struct op_list_search_key key;
method_op_p query_op = NULL;
@@ -2026,7 +2062,7 @@ static method_op_p find_recv_inflight(me
*
* returns 0 on success, -errno on failure
*/
-static int tcp_sock_init(method_addr_p my_method_addr)
+static int tcp_sock_init(bmi_method_addr_p my_method_addr)
{
int oldfl = 0; /* socket flags */
@@ -2052,9 +2088,6 @@ static int tcp_sock_init(method_addr_p m
if(tcp_addr_data->addr_error)
{
- /* TODO: make this a debug rather than error message once we have
- * tested this out enough
- */
gossip_debug(GOSSIP_BMI_DEBUG_TCP, "%s: attempting reconnect.\n",
__func__);
tcp_addr_data->addr_error = 0;
@@ -2144,14 +2177,14 @@ static int tcp_sock_init(method_addr_p m
if (ret < 0)
{
- if (errno == EINPROGRESS)
+ if (ret == -EINPROGRESS)
{
tcp_addr_data->not_connected = 1;
/* this will have to be connected later with a poll */
}
else
{
- /* BMI_sockio_connect_sock returns a PVFS error */
+ /* NOTE: BMI_sockio_connect_sock returns a PVFS error */
char buff[300];
snprintf(buff, 300, "Error: BMI_sockio_connect_sock: (%s):",
@@ -2178,7 +2211,7 @@ static int tcp_sock_init(method_addr_p m
*/
static int enqueue_operation(op_list_p target_list,
enum bmi_op_type send_recv,
- method_addr_p map,
+ bmi_method_addr_p map,
void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -2321,7 +2354,7 @@ static int enqueue_operation(op_list_p t
* completion, -errno on failure
*/
static int tcp_post_recv_generic(bmi_op_id_t * id,
- method_addr_p src,
+ bmi_method_addr_p src,
void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -2377,9 +2410,9 @@ static int tcp_post_recv_generic(bmi_op_
/* whoohoo- it is already done! */
/* copy buffer out to list segments; handle short case */
- for (i = 0; i < query_op->list_count; i++)
+ for (i = 0; i < list_count; i++)
{
- copy_size = query_op->size_list[i];
+ copy_size = size_list[i];
if (copy_size + total_copied > query_op->actual_size)
{
copy_size = query_op->actual_size - total_copied;
@@ -2421,9 +2454,9 @@ static int tcp_post_recv_generic(bmi_op_
/* copy what we have so far into the correct buffers */
total_copied = 0;
- for (i = 0; i < query_op->list_count; i++)
+ for (i = 0; i < list_count; i++)
{
- copy_size = query_op->size_list[i];
+ copy_size = size_list[i];
if (copy_size + total_copied > query_op->amt_complete)
{
copy_size = query_op->amt_complete - total_copied;
@@ -2498,6 +2531,7 @@ static int tcp_post_recv_generic(bmi_op_
if (ret < 0)
{
PVFS_perror_gossip("Error: payload_progress", ret);
+ /* payload_progress() returns BMI error codes */
tcp_forget_addr(query_op->addr, 0, ret);
return (ret);
}
@@ -2575,7 +2609,7 @@ static int tcp_post_recv_generic(bmi_op_
*
* returns 0 on success, -errno on failure
*/
-static int tcp_cleanse_addr(method_addr_p map, int error_code)
+static int tcp_cleanse_addr(bmi_method_addr_p map, int error_code)
{
int i = 0;
struct op_list_search_key key;
@@ -2620,7 +2654,7 @@ static int tcp_cleanse_addr(method_addr_
*
* returns 0 on success, -errno on failure
*/
-static int tcp_shutdown_addr(method_addr_p map)
+static int tcp_shutdown_addr(bmi_method_addr_p map)
{
struct tcp_addr *tcp_addr_data = map->method_data;
@@ -2646,7 +2680,7 @@ static int tcp_shutdown_addr(method_addr
static int tcp_do_work(int max_idle_time)
{
int ret = -1;
- method_addr_p addr_array[TCP_WORK_METRIC];
+ bmi_method_addr_p addr_array[TCP_WORK_METRIC];
int status_array[TCP_WORK_METRIC];
int socket_count = 0;
int i = 0;
@@ -2665,6 +2699,7 @@ static int tcp_do_work(int max_idle_time
gen_mutex_lock(&interface_mutex);
if (ret < 0)
{
+ /* BMI_socket_collection_testglobal() returns BMI error code */
return (ret);
}
@@ -2678,6 +2713,7 @@ static int tcp_do_work(int max_idle_time
/* skip working on addresses in failure mode */
if(tcp_addr_data->addr_error)
{
+ /* addr_error field is in BMI error code format */
tcp_forget_addr(addr_array[i], 0, tcp_addr_data->addr_error);
continue;
}
@@ -2742,7 +2778,7 @@ static int tcp_do_work(int max_idle_time
*
* returns 0 on success, -errno on failure
*/
-static int tcp_do_work_send(method_addr_p map, int* stall_flag)
+static int tcp_do_work_send(bmi_method_addr_p map, int* stall_flag)
{
method_op_p active_method_op = NULL;
struct op_list_search_key key;
@@ -2787,11 +2823,11 @@ static int tcp_do_work_send(method_addr_
*
* returns 0 on success, -errno on failure
*/
-static int handle_new_connection(method_addr_p map)
+static int handle_new_connection(bmi_method_addr_p map)
{
struct tcp_addr *tcp_addr_data = NULL;
int accepted_socket = -1;
- method_addr_p new_addr = NULL;
+ bmi_method_addr_p new_addr = NULL;
int ret = -1;
char* tmp_peer = NULL;
@@ -2828,7 +2864,7 @@ static int handle_new_connection(method_
*/
tcp_addr_data->dont_reconnect = 1;
/* register this address with the method control layer */
- ret = bmi_method_addr_reg_callback(new_addr);
+ tcp_addr_data->bmi_addr = bmi_method_addr_reg_callback(new_addr);
if (ret < 0)
{
tcp_shutdown_addr(new_addr);
@@ -2850,7 +2886,7 @@ static int handle_new_connection(method_
*
* returns 0 on success, -errno on failure
*/
-static int tcp_do_work_recv(method_addr_p map, int* stall_flag)
+static int tcp_do_work_recv(bmi_method_addr_p map, int* stall_flag)
{
method_op_p active_method_op = NULL;
@@ -2948,7 +2984,7 @@ static int tcp_do_work_recv(method_addr_
"...dropping connection.\n");
tcp_forget_addr(map, 0, bmi_tcp_errno_to_pvfs(-EPIPE));
}
- return(ret);
+ return(0);
}
else
{
@@ -2963,15 +2999,12 @@ static int tcp_do_work_recv(method_addr_
*stall_flag = 0;
gossip_ldebug(GOSSIP_BMI_DEBUG_TCP, "Reading header for new op.\n");
- /* NOTE: we only allow a blocking call here because we peeked to see
- * if this amount of data was ready above.
- */
- ret = BMI_sockio_brecv(tcp_addr_data->socket,
+ ret = BMI_sockio_nbrecv(tcp_addr_data->socket,
new_header.enc_hdr, TCP_ENC_HDR_SIZE);
if (ret < TCP_ENC_HDR_SIZE)
{
tmp_errno = errno;
- gossip_err("Error: BMI_sockio_brecv: %s\n", strerror(tmp_errno));
+ gossip_err("Error: BMI_sockio_nbrecv: %s\n", strerror(tmp_errno));
tcp_forget_addr(map, 0, bmi_tcp_errno_to_pvfs(-tmp_errno));
return (0);
}
@@ -3153,6 +3186,7 @@ static int work_on_send_op(method_op_p m
if (ret < 0)
{
PVFS_perror_gossip("Error: socket failed to init", ret);
+ /* tcp_sock_init() returns BMI error code */
tcp_forget_addr(my_method_op->addr, 0, ret);
return (0);
}
@@ -3177,6 +3211,7 @@ static int work_on_send_op(method_op_p m
if (ret < 0)
{
PVFS_perror_gossip("Error: payload_progress", ret);
+ /* payload_progress() returns BMI error codes */
tcp_forget_addr(my_method_op->addr, 0, ret);
return (0);
}
@@ -3244,6 +3279,7 @@ static int work_on_recv_op(method_op_p m
if (ret < 0)
{
PVFS_perror_gossip("Error: payload_progress", ret);
+ /* payload_progress() returns BMI error codes */
tcp_forget_addr(my_method_op->addr, 0, ret);
return (0);
}
@@ -3296,7 +3332,7 @@ static int work_on_recv_op(method_op_p m
*
* returns 0 on success, -errno on failure
*/
-static int tcp_do_work_error(method_addr_p map)
+static int tcp_do_work_error(bmi_method_addr_p map)
{
struct tcp_addr *tcp_addr_data = NULL;
int buf;
@@ -3474,6 +3510,7 @@ static int tcp_accept_init(int *socket,
int ret = -1;
int tmp_errno = 0;
struct tcp_addr *tcp_addr_data = tcp_method_params.listen_addr->method_data;
+ int oldfl = 0;
struct sockaddr_in peer_sockaddr;
int peer_sockaddr_size = sizeof(struct sockaddr_in);
char* tmp_peer;
@@ -3541,13 +3578,20 @@ static int tcp_accept_init(int *socket,
return (bmi_tcp_errno_to_pvfs(-tmp_errno));
}
+ /* set it to non-blocking operation */
+ oldfl = fcntl(*socket, F_GETFL, 0);
+ if (!(oldfl & O_NONBLOCK))
+ {
+ fcntl(*socket, F_SETFL, oldfl | O_NONBLOCK);
+ }
+
/* allocate ip address string */
tmp_peer = inet_ntoa(peer_sockaddr.sin_addr);
*peer = (char*)malloc(strlen(tmp_peer)+1);
if(!(*peer))
{
close(*socket);
- return(-BMI_ENOMEM);
+ return(bmi_tcp_errno_to_pvfs(-BMI_ENOMEM));
}
strcpy(*peer, tmp_peer);
@@ -3565,7 +3609,7 @@ static method_op_p alloc_tcp_method_op(v
{
method_op_p my_method_op = NULL;
- my_method_op = alloc_method_op(sizeof(struct tcp_op));
+ my_method_op = bmi_alloc_method_op(sizeof(struct tcp_op));
/* we trust alloc_method_op to zero it out */
@@ -3582,7 +3626,7 @@ static method_op_p alloc_tcp_method_op(v
*/
static void dealloc_tcp_method_op(method_op_p old_op)
{
- dealloc_method_op(old_op);
+ bmi_dealloc_method_op(old_op);
return;
}
@@ -3594,7 +3638,7 @@ static void dealloc_tcp_method_op(method
* completion, -errno on failure
*/
static int BMI_tcp_post_send_generic(bmi_op_id_t * id,
- method_addr_p dest,
+ bmi_method_addr_p dest,
const void *const *buffer_list,
const bmi_size_t *size_list,
int list_count,
@@ -3676,6 +3720,7 @@ static int BMI_tcp_post_send_generic(bmi
if (ret < 0)
{
gossip_debug(GOSSIP_BMI_DEBUG_TCP, "tcp_sock_init() failure.\n");
+ /* tcp_sock_init() returns BMI error code */
tcp_forget_addr(dest, 0, ret);
return (ret);
}
@@ -3718,6 +3763,7 @@ static int BMI_tcp_post_send_generic(bmi
if (ret < 0)
{
PVFS_perror_gossip("Error: payload_progress", ret);
+ /* payload_progress() returns BMI error codes */
tcp_forget_addr(dest, 0, ret);
return (ret);
}
Index: module.mk.in
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/bmi/bmi_tcp/module.mk.in,v
diff -p -u -r1.3 -r1.3.62.1
--- module.mk.in 19 Aug 2004 15:09:59 -0000 1.3
+++ module.mk.in 21 Jul 2008 18:20:04 -0000 1.3.62.1
@@ -1,3 +1,6 @@
+
+ifneq (,$(BUILD_BMI_TCP))
+
BUILD_EPOLL = @BUILD_EPOLL@
DIR := src/io/bmi/bmi_tcp
LIBSRC += \
@@ -11,8 +14,10 @@ SERVERSRC += \
ifdef BUILD_EPOLL
LIBSRC += $(DIR)/socket-collection-epoll.c
SERVERSRC += $(DIR)/socket-collection-epoll.c
+MODCFLAGS_$(DIR)/bmi-tcp.c := -D__PVFS2_USE_EPOLL__
else
LIBSRC += $(DIR)/socket-collection.c
SERVERSRC += $(DIR)/socket-collection.c
endif
+endif # BUILD_BMI_TCP
Index: socket-collection-epoll.c
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/bmi/bmi_tcp/socket-collection-epoll.c,v
diff -p -u -r1.3 -r1.3.18.1
--- socket-collection-epoll.c 24 May 2006 14:05:47 -0000 1.3
+++ socket-collection-epoll.c 21 Jul 2008 18:20:04 -0000 1.3.18.1
@@ -74,6 +74,7 @@ socket_collection_p BMI_socket_collectio
if(new_server_socket > -1)
{
+ memset(&event, 0, sizeof(event));
event.events = (EPOLLIN|EPOLLERR|EPOLLHUP);
event.data.ptr = NULL;
ret = epoll_ctl(tmp_scp->epfd, EPOLL_CTL_ADD, new_server_socket,
@@ -100,7 +101,7 @@ socket_collection_p BMI_socket_collectio
* returns 0 on success, -errno on failure.
*/
void BMI_socket_collection_queue(socket_collection_p scp,
- method_addr_p map, struct qlist_head* queue)
+ bmi_method_addr_p map, struct qlist_head* queue)
{
struct qlist_head* iterator = NULL;
struct qlist_head* scratch = NULL;
@@ -167,7 +168,7 @@ void BMI_socket_collection_finalize(sock
int BMI_socket_collection_testglobal(socket_collection_p scp,
int incount,
int *outcount,
- method_addr_p * maps,
+ bmi_method_addr_p * maps,
int * status,
int poll_timeout,
gen_mutex_t* external_mutex)
@@ -186,7 +187,7 @@ int BMI_socket_collection_testglobal(soc
/* init the outgoing arguments for safety */
*outcount = 0;
- memset(maps, 0, (sizeof(method_addr_p) * incount));
+ memset(maps, 0, (sizeof(bmi_method_addr_p) * incount));
memset(status, 0, (sizeof(int) * incount));
gen_mutex_lock(&scp->mutex);
@@ -200,11 +201,14 @@ int BMI_socket_collection_testglobal(soc
tcp_addr_data = qlist_entry(iterator, struct tcp_addr, sc_link);
qlist_del(&tcp_addr_data->sc_link);
+
/* take out of the epoll set */
if(tcp_addr_data->sc_index > -1)
{
+ memset(&event, 0, sizeof(event));
event.events = 0;
event.data.ptr = tcp_addr_data->map;
+
ret = epoll_ctl(scp->epfd, EPOLL_CTL_DEL, tcp_addr_data->socket,
&event);
@@ -226,15 +230,18 @@ int BMI_socket_collection_testglobal(soc
{
tcp_addr_data = qlist_entry(iterator, struct tcp_addr, sc_link);
qlist_del(&tcp_addr_data->sc_link);
+
if(tcp_addr_data->sc_index > -1)
{
+ memset(&event, 0, sizeof(event));
/* update existing entry */
event.data.ptr = tcp_addr_data->map;
event.events = (EPOLLIN|EPOLLERR|EPOLLHUP);
if(tcp_addr_data->write_ref_count > 0)
event.events |= EPOLLOUT;
+
ret = epoll_ctl(scp->epfd, EPOLL_CTL_MOD, tcp_addr_data->socket,
- &event);
+ &event);
if(ret < 0 && errno != ENOENT)
{
@@ -249,10 +256,12 @@ int BMI_socket_collection_testglobal(soc
/* new entry */
tcp_addr_data->sc_index = 1;
+ memset(&event, 0, sizeof(event));
event.data.ptr = tcp_addr_data->map;
event.events = (EPOLLIN|EPOLLERR|EPOLLHUP);
if(tcp_addr_data->write_ref_count > 0)
event.events |= EPOLLOUT;
+
ret = epoll_ctl(scp->epfd, EPOLL_CTL_ADD, tcp_addr_data->socket,
&event);
if(ret < 0 && errno != EEXIST)
Index: socket-collection-epoll.h
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/bmi/bmi_tcp/socket-collection-epoll.h,v
diff -p -u -r1.2 -r1.2.20.1
--- socket-collection-epoll.h 24 May 2006 13:24:50 -0000 1.2
+++ socket-collection-epoll.h 21 Jul 2008 18:20:04 -0000 1.2.20.1
@@ -53,7 +53,7 @@ enum
socket_collection_p BMI_socket_collection_init(int new_server_socket);
void BMI_socket_collection_queue(socket_collection_p scp,
- method_addr_p map, struct qlist_head* queue);
+ bmi_method_addr_p map, struct qlist_head* queue);
/* the bmi_tcp code may try to add a socket to the collection before
* it is fully connected, just ignore in this case
@@ -109,6 +109,7 @@ do { \
struct tcp_addr* tcp_data = (m)->method_data; \
if(tcp_data->socket > -1){ \
struct epoll_event event;\
+ memset(&event, 0, sizeof(event));\
event.events = EPOLLIN|EPOLLERR|EPOLLHUP;\
event.data.ptr = tcp_data->map;\
epoll_ctl(s->epfd, EPOLL_CTL_ADD, tcp_data->socket, &event);\
@@ -119,6 +120,8 @@ do { \
do { \
struct epoll_event event;\
struct tcp_addr* tcp_data = (m)->method_data; \
+ tcp_data->write_ref_count = 0; \
+ memset(&event, 0, sizeof(event));\
event.events = 0;\
event.data.ptr = tcp_data->map;\
epoll_ctl(s->epfd, EPOLL_CTL_DEL, tcp_data->socket, &event);\
@@ -131,6 +134,7 @@ do { \
struct epoll_event event;\
assert(tcp_data->socket > -1); \
tcp_data->write_ref_count++; \
+ memset(&event, 0, sizeof(event));\
event.events = EPOLLIN|EPOLLERR|EPOLLHUP|EPOLLOUT;\
event.data.ptr = tcp_data->map;\
epoll_ctl(s->epfd, EPOLL_CTL_MOD, tcp_data->socket, &event);\
@@ -143,6 +147,7 @@ do { \
tcp_data->write_ref_count--; \
assert(tcp_data->write_ref_count > -1); \
if (tcp_data->write_ref_count == 0) { \
+ memset(&event, 0, sizeof(event));\
event.events = EPOLLIN|EPOLLERR|EPOLLHUP;\
event.data.ptr = tcp_data->map;\
epoll_ctl(s->epfd, EPOLL_CTL_MOD, tcp_data->socket, &event);\
@@ -155,7 +160,7 @@ void BMI_socket_collection_finalize(sock
int BMI_socket_collection_testglobal(socket_collection_p scp,
int incount,
int *outcount,
- method_addr_p * maps,
+ bmi_method_addr_p * maps,
int * status,
int poll_timeout,
gen_mutex_t* external_mutex);
Index: socket-collection.c
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/bmi/bmi_tcp/socket-collection.c,v
diff -p -u -r1.15 -r1.15.28.1
--- socket-collection.c 24 May 2006 13:24:50 -0000 1.15
+++ socket-collection.c 21 Jul 2008 18:20:04 -0000 1.15.28.1
@@ -66,7 +66,7 @@ socket_collection_p BMI_socket_collectio
return(NULL);
}
tmp_scp->addr_array =
- (method_addr_p*)malloc(POLLFD_ARRAY_START*sizeof(method_addr_p));
+ (bmi_method_addr_p*)malloc(POLLFD_ARRAY_START*sizeof(bmi_method_addr_p));
if(!tmp_scp->addr_array)
{
free(tmp_scp->pollfd_array);
@@ -111,7 +111,7 @@ socket_collection_p BMI_socket_collectio
* returns 0 on success, -errno on failure.
*/
void BMI_socket_collection_queue(socket_collection_p scp,
- method_addr_p map, struct qlist_head* queue)
+ bmi_method_addr_p map, struct qlist_head* queue)
{
struct qlist_head* iterator = NULL;
struct qlist_head* scratch = NULL;
@@ -175,7 +175,7 @@ void BMI_socket_collection_finalize(sock
int BMI_socket_collection_testglobal(socket_collection_p scp,
int incount,
int *outcount,
- method_addr_p * maps,
+ bmi_method_addr_p * maps,
int * status,
int poll_timeout,
gen_mutex_t* external_mutex)
@@ -185,7 +185,7 @@ int BMI_socket_collection_testglobal(soc
struct tcp_addr* tcp_addr_data = NULL;
struct tcp_addr* shifted_tcp_addr_data = NULL;
struct pollfd* tmp_pollfd_array = NULL;
- method_addr_p* tmp_addr_array = NULL;
+ bmi_method_addr_p* tmp_addr_array = NULL;
int ret = -1;
int old_errno;
int tmp_count;
@@ -199,7 +199,7 @@ int BMI_socket_collection_testglobal(soc
do_again:
/* init the outgoing arguments for safety */
*outcount = 0;
- memset(maps, 0, (sizeof(method_addr_p) * incount));
+ memset(maps, 0, (sizeof(bmi_method_addr_p) * incount));
memset(status, 0, (sizeof(int) * incount));
gen_mutex_lock(&scp->mutex);
@@ -255,8 +255,8 @@ do_again:
(scp->array_max+POLLFD_ARRAY_INC)*sizeof(struct pollfd));
/* TODO: handle this */
assert(tmp_pollfd_array);
- tmp_addr_array = (method_addr_p*)malloc(
- (scp->array_max+POLLFD_ARRAY_INC)*sizeof(method_addr_p));
+ tmp_addr_array = (bmi_method_addr_p*)malloc(
+ (scp->array_max+POLLFD_ARRAY_INC)*sizeof(bmi_method_addr_p));
/* TODO: handle this */
assert(tmp_addr_array);
memcpy(tmp_pollfd_array, scp->pollfd_array,
@@ -264,7 +264,7 @@ do_again:
free(scp->pollfd_array);
scp->pollfd_array = tmp_pollfd_array;
memcpy(tmp_addr_array, scp->addr_array,
- scp->array_max*sizeof(method_addr_p));
+ scp->array_max*sizeof(bmi_method_addr_p));
free(scp->addr_array);
scp->addr_array = tmp_addr_array;
scp->array_max = scp->array_max+POLLFD_ARRAY_INC;
@@ -292,7 +292,7 @@ do_again:
if(ret < 0)
{
gen_mutex_unlock(&scp->mutex);
- return(-old_errno);
+ return(bmi_tcp_errno_to_pvfs(-old_errno));
}
/* nothing ready, just return */
Index: socket-collection.h
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/bmi/bmi_tcp/socket-collection.h,v
diff -p -u -r1.12 -r1.12.30.1
--- socket-collection.h 24 May 2006 13:24:50 -0000 1.12
+++ socket-collection.h 21 Jul 2008 18:20:04 -0000 1.12.30.1
@@ -29,7 +29,7 @@ struct socket_collection
gen_mutex_t mutex;
struct pollfd* pollfd_array;
- method_addr_p* addr_array;
+ bmi_method_addr_p* addr_array;
int array_max;
int array_count;
@@ -51,7 +51,7 @@ enum
socket_collection_p BMI_socket_collection_init(int new_server_socket);
void BMI_socket_collection_queue(socket_collection_p scp,
- method_addr_p map, struct qlist_head* queue);
+ bmi_method_addr_p map, struct qlist_head* queue);
#ifndef __PVFS2_JOB_THREADED__
/* the bmi_tcp code may try to add a socket to the collection before
@@ -151,7 +151,7 @@ void BMI_socket_collection_finalize(sock
int BMI_socket_collection_testglobal(socket_collection_p scp,
int incount,
int *outcount,
- method_addr_p * maps,
+ bmi_method_addr_p * maps,
int * status,
int poll_timeout,
gen_mutex_t* external_mutex);
Index: sockio.c
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/bmi/bmi_tcp/sockio.c,v
diff -p -u -r1.22 -r1.22.14.1
--- sockio.c 11 Sep 2006 15:42:39 -0000 1.22
+++ sockio.c 21 Jul 2008 18:20:04 -0000 1.22.14.1
@@ -24,8 +24,10 @@
#endif
#include <sys/poll.h>
#include <sys/uio.h>
+#include <assert.h>
#include "sockio.h"
+#include "gossip.h"
/* if the platform provides a MSG_NOSIGNAL option (which disables the
* generation of signals on broken pipe), then use it
@@ -60,6 +62,7 @@ int BMI_sockio_bind_sock(int sockd,
return (sockd);
}
+/* NOTE: this function returns BMI error codes */
int BMI_sockio_bind_sock_specific(int sockd,
const char *name,
int service)
@@ -75,12 +78,13 @@ int BMI_sockio_bind_sock_specific(int so
{
if (errno == EINTR)
goto bind_sock_restart;
- return (-1);
+ return(bmi_errno_to_pvfs(-errno));
}
return (sockd);
}
+/* NOTE: this function returns BMI error codes */
int BMI_sockio_connect_sock(int sockd,
const char *name,
int service)
@@ -89,13 +93,13 @@ int BMI_sockio_connect_sock(int sockd,
int ret;
if ((ret = BMI_sockio_init_sock(&saddr, name, service)) != 0)
- return (ret); /* converted to PVFS error code below */
+ return (ret);
connect_sock_restart:
if (connect(sockd, (struct sockaddr *) &saddr, sizeof(saddr)) < 0)
{
if (errno == EINTR)
goto connect_sock_restart;
- return (-PVFS_ERROR_CODE(errno));
+ return(bmi_errno_to_pvfs(-errno));
}
return (sockd);
}
@@ -139,7 +143,7 @@ int BMI_sockio_init_sock(struct sockaddr
}
((struct sockaddr_in *) saddrp)->sin_family = AF_INET;
((struct sockaddr_in *) saddrp)->sin_port = htons((u_short) service);
- bcopy(hep->h_addr, (char *) &(((struct sockaddr_in *) saddrp)->sin_addr),
+ memcpy((char *) &(((struct sockaddr_in *) saddrp)->sin_addr), hep->h_addr,
hep->h_length);
return (0);
}
@@ -166,7 +170,7 @@ int BMI_sockio_init_sock(struct sockaddr
((struct sockaddr_in *) saddrp)->sin_family = AF_INET;
((struct sockaddr_in *) saddrp)->sin_port = htons((u_short) service);
- bcopy(&addr, (char *) &(((struct sockaddr_in *) saddrp)->sin_addr),
+ memcpy((char *) &(((struct sockaddr_in *) saddrp)->sin_addr), &addr,
sizeof(addr));
return 0;
@@ -174,49 +178,6 @@ int BMI_sockio_init_sock(struct sockaddr
#endif
-/* blocking receive */
-/* Returns -1 if it cannot get all len bytes
- * and the # of bytes received otherwise
- */
-int BMI_sockio_brecv(int s,
- void *buf,
- int len)
-{
- int oldfl, ret, comp = len;
- int olderrno;
- oldfl = fcntl(s, F_GETFL, 0);
- if (oldfl & O_NONBLOCK)
- fcntl(s, F_SETFL, oldfl & (~O_NONBLOCK));
-
- while (comp)
- {
- brecv_restart:
- if ((ret = recv(s, (char *) buf, comp, DEFAULT_MSG_FLAGS)) < 0)
- {
- if (errno == EINTR)
- goto brecv_restart;
- olderrno = errno;
- fcntl(s, F_SETFL, oldfl|O_NONBLOCK);
- errno = olderrno;
- return (-1);
- }
- if (!ret)
- {
- /* Note: this indicates a closed socket. However, I don't
- * like this behavior, so we're going to return -1 w/an EPIPE
- * instead.
- */
- fcntl(s, F_SETFL, oldfl|O_NONBLOCK);
- errno = EPIPE;
- return (-1);
- }
- comp -= ret;
- buf = (char *)buf + ret;
- }
- fcntl(s, F_SETFL, oldfl|O_NONBLOCK);
- return (len - comp);
-}
-
/* nonblocking receive */
int BMI_sockio_nbrecv(int s,
void *buf,
@@ -224,20 +185,18 @@ int BMI_sockio_nbrecv(int s,
{
int ret, comp = len;
+ assert(fcntl(s, F_GETFL, 0) & O_NONBLOCK);
+
while (comp)
{
nbrecv_restart:
ret = recv(s, buf, comp, DEFAULT_MSG_FLAGS);
- if (!ret) /* socket closed */
- {
- errno = EPIPE;
- return (-1);
- }
- if (ret == -1 && errno == EWOULDBLOCK)
- {
- return (len - comp); /* return amount completed */
- }
- if (ret == -1 && errno == EINTR)
+ if (ret == 0) /* socket closed */
+ {
+ errno = EPIPE;
+ return (-1);
+ }
+ if (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK))
{
goto nbrecv_restart;
}
@@ -263,6 +222,8 @@ int BMI_sockio_nbpeek(int s, void* buf,
{
int ret, comp = len;
+ assert(fcntl(s, F_GETFL, 0) & O_NONBLOCK);
+
while (comp)
{
nbpeek_restart:
@@ -286,37 +247,6 @@ int BMI_sockio_nbpeek(int s, void* buf,
}
comp -= ret;
}
- return (len - comp);
-}
-
-
-/* blocking send */
-int BMI_sockio_bsend(int s,
- void *buf,
- int len)
-{
- int oldfl, ret, comp = len;
- int olderrno;
- oldfl = fcntl(s, F_GETFL, 0);
- if (oldfl & O_NONBLOCK)
- fcntl(s, F_SETFL, oldfl & (~O_NONBLOCK));
-
- while (comp)
- {
- bsend_restart:
- if ((ret = send(s, (char *) buf, comp, DEFAULT_MSG_FLAGS)) < 0)
- {
- if (errno == EINTR)
- goto bsend_restart;
- olderrno = errno;
- fcntl(s, F_SETFL, oldfl | O_NONBLOCK);
- errno = olderrno;
- return (-1);
- }
- comp -= ret;
- buf = (char *)buf + ret;
- }
- fcntl(s, F_SETFL, oldfl | O_NONBLOCK);
return (len - comp);
}
Index: sockio.h
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/io/bmi/bmi_tcp/sockio.h,v
diff -p -u -r1.15 -r1.15.16.1
--- sockio.h 11 Sep 2006 15:42:39 -0000 1.15
+++ sockio.h 21 Jul 2008 18:20:04 -0000 1.15.16.1
@@ -41,15 +41,9 @@ int BMI_sockio_connect_sock(int,
int BMI_sockio_init_sock(struct sockaddr *,
const char *,
int);
-int BMI_sockio_brecv(int s,
- void *buf,
- int len);
int BMI_sockio_nbrecv(int s,
void *buf,
int len);
-int BMI_sockio_bsend(int s,
- void *buf,
- int len);
int BMI_sockio_nbsend(int s,
void *buf,
int len);
More information about the Pvfs2-cvs
mailing list