diff --git a/checkin_notes b/checkin_notes index fc9a6f4e36..da8950b02b 100755 --- a/checkin_notes +++ b/checkin_notes @@ -26942,3 +26942,10 @@ David 8 April 2005 error_numbers.h gui_rpc_client.C,h network.C,h + +David 8 April 2005 + - debugged asynchronous connect for GUI RPC + + lib/ + boinc_cmd.C + gui_rpc_client.C,h diff --git a/lib/boinc_cmd.C b/lib/boinc_cmd.C index 86cd80dded..2ba2800a38 100644 --- a/lib/boinc_cmd.C +++ b/lib/boinc_cmd.C @@ -54,14 +54,14 @@ #ifdef _WIN32 #include "boinc_win.h" #include "win_net.h" +#else +#include +#include #endif + #include using std::vector; -#ifndef _WIN32 -#include -#endif - #include "gui_rpc_client.h" #include "error_numbers.h" @@ -130,11 +130,28 @@ int main(int argc, char** argv) { passwd = argv[i+1]; i += 2; } - retval = rpc.init(hostname); +#if 1 + retval = rpc.init(hostname, false); if (retval) { fprintf(stderr, "can't connect\n"); exit(1); } +#else + retval = rpc.init(hostname, true); + while (1) { + retval = rpc.init_poll(); + if (!retval) break; + if (retval == ERR_RETRY) { + printf("sleeping\n"); + sleep(1); + continue; + } + fprintf(stderr, "can't connect: %d\n", retval); + exit(1); + } + printf("connected\n"); +#endif + if (passwd) { retval = rpc.authorize(passwd); if (retval) { diff --git a/lib/gui_rpc_client.C b/lib/gui_rpc_client.C index 8a9c6a9aea..191defade6 100644 --- a/lib/gui_rpc_client.C +++ b/lib/gui_rpc_client.C @@ -29,10 +29,6 @@ #include #include #include -#include -#include -#include -#include #endif #include "diagnostics.h" @@ -950,7 +946,6 @@ void RPC_CLIENT::close() { int RPC_CLIENT::init(const char* host, bool asynch) { int retval; - sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(GUI_RPC_PORT_ALT); @@ -973,8 +968,15 @@ int RPC_CLIENT::init(const char* host, bool asynch) { if (retval) return retval; if (asynch) { - boinc_socket_asynch(sock, true); + tried_alt_port = false; + retval = boinc_socket_asynch(sock, true); + if (retval) { + printf("asynch error: %d\n", retval); + } retval = connect(sock, (const sockaddr*)(&addr), sizeof(addr)); + printf("connect: %d %s\n", retval, host); + perror("connect"); + return 0; } else { retval = connect(sock, (const sockaddr*)(&addr), sizeof(addr)); if (retval) { @@ -999,6 +1001,7 @@ int RPC_CLIENT::init(const char* host, bool asynch) { int RPC_CLIENT::init_poll() { fd_set read_fds, write_fds, error_fds; struct timeval tv; + int retval; FD_ZERO(&read_fds); FD_ZERO(&write_fds); @@ -1009,10 +1012,30 @@ int RPC_CLIENT::init_poll() { FD_SET(sock, &error_fds); tv.tv_sec = tv.tv_usec = 0; - select(FD_SETSIZE, &read_fds, &write_fds, &error_fds, &tv); + int n = select(FD_SETSIZE, &read_fds, &write_fds, &error_fds, &tv); + printf("select: %d\n",n); if (FD_ISSET(sock, &error_fds)) return ERR_CONNECT; - if (FD_ISSET(sock, &read_fds)) { - boinc_socket_asynch(sock, false); + if (FD_ISSET(sock, &write_fds)) { + printf("read set\n"); + retval = get_socket_error(sock); + printf("socket error %d\n", retval); + if (retval) { + if (tried_alt_port) { + return retval; + } else { + boinc_close_socket(sock); + retval = boinc_socket(sock); + retval = boinc_socket_asynch(sock, true); + addr.sin_port = htons(GUI_RPC_PORT); + retval = connect(sock, (const sockaddr*)(&addr), sizeof(addr)); + return ERR_RETRY; + tried_alt_port = true; + } + } + retval = boinc_socket_asynch(sock, false); + if (retval) { + printf("asynch error: %d\n", retval); + } return 0; } return ERR_RETRY; @@ -1058,7 +1081,11 @@ int RPC_CLIENT::send_request(const char* p) { p ); int n = send(sock, buf, strlen(buf), 0); - if (n < 0) return ERR_WRITE; + if (n < 0) { + printf("send: %d\n", n); + perror("send"); + return ERR_WRITE; + } return 0; } diff --git a/lib/gui_rpc_client.h b/lib/gui_rpc_client.h index 056245129b..5733e2a762 100644 --- a/lib/gui_rpc_client.h +++ b/lib/gui_rpc_client.h @@ -23,6 +23,11 @@ #include #include #include +#include +#include +#include +#include +#include #endif #include "miofile.h" @@ -389,6 +394,9 @@ class RPC_CLIENT { public: int sock; int client_version; + bool tried_alt_port; + sockaddr_in addr; + int send_request(const char*); int get_reply(char*&); RPC_CLIENT();