[mpich2-commits] r7938 - mpich2/trunk/src/pm/hydra/utils/sock
balaji at mcs.anl.gov
balaji at mcs.anl.gov
Fri Feb 11 17:34:09 CST 2011
Author: balaji
Date: 2011-02-11 17:34:09 -0600 (Fri, 11 Feb 2011)
New Revision: 7938
Modified:
mpich2/trunk/src/pm/hydra/utils/sock/sock.c
Log:
Cleanup code and error messages for the case where the proxy is not
able to connect to the main server.
No reviewer.
Modified: mpich2/trunk/src/pm/hydra/utils/sock/sock.c
===================================================================
--- mpich2/trunk/src/pm/hydra/utils/sock/sock.c 2011-02-11 23:34:03 UTC (rev 7937)
+++ mpich2/trunk/src/pm/hydra/utils/sock/sock.c 2011-02-11 23:34:09 UTC (rev 7938)
@@ -18,6 +18,37 @@
struct fwd_hash *next;
};
+static char localhost[MAX_HOSTNAME_LEN] = { 0 };
+static char shortlocal[MAX_HOSTNAME_LEN] = { 0 };
+
+static HYD_status sock_localhost_init(void)
+{
+ static int init = 1;
+ int i;
+ HYD_status status = HYD_SUCCESS;
+
+ if (init) {
+ init = 0;
+
+ status = HYDU_gethostname(localhost);
+ HYDU_ERR_POP(status, "unable to get local hostname\n");
+
+ strcpy(shortlocal, localhost);
+ for (i = 0; shortlocal[i]; i++) {
+ if (shortlocal[i] == '.') {
+ shortlocal[i] = 0;
+ break;
+ }
+ }
+ }
+
+ fn_exit:
+ return status;
+
+ fn_fail:
+ goto fn_exit;
+}
+
HYD_status HYDU_sock_listen(int *listen_fd, char *port_range, uint16_t * port)
{
struct sockaddr_in sa;
@@ -148,9 +179,12 @@
* return an error, but only print a warning message. The upper
* layer can decide what to do with the return status. */
if (connect(*fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
- HYDU_error_printf("connect error (%s)\n", HYDU_strerror(errno));
- status = HYD_SOCK_ERROR;
- goto fn_fail;
+ status = sock_localhost_init();
+ HYDU_ERR_POP(status, "unable to initialize sock local information\n");
+
+ HYDU_ERR_SETANDJUMP(status, HYD_SOCK_ERROR,
+ "unable to connect from \"%s\" to \"%s\" (%s)\n",
+ localhost, host, HYDU_strerror(errno));
}
/* Disable nagle */
@@ -463,9 +497,6 @@
char *ip1 = NULL, *ip2 = NULL;
char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
struct sockaddr_in *sa_ptr, sa;
- static int init = 1;
- static char localhost[MAX_HOSTNAME_LEN] = { 0 };
- static char shortlocal[MAX_HOSTNAME_LEN] = { 0 };
char shorthost[MAX_HOSTNAME_LEN] = { 0 };
int i;
@@ -516,21 +547,9 @@
#endif
/* Direct comparison of host names */
- if (init) {
- init = 0;
+ status = sock_localhost_init();
+ HYDU_ERR_POP(status, "unable to initialize sock local information\n");
- status = HYDU_gethostname(localhost);
- HYDU_ERR_POP(status, "unable to get local hostname\n");
-
- strcpy(shortlocal, localhost);
- for (i = 0; shortlocal[i]; i++) {
- if (shortlocal[i] == '.') {
- shortlocal[i] = 0;
- break;
- }
- }
- }
-
if (!strcmp(host, localhost)) {
*is_local = 1;
goto fn_exit;
More information about the mpich2-commits
mailing list