Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
--- a/client.c Fri Oct 02 21:14:33 2009 +0200
+++ b/client.c Wed Oct 07 21:18:49 2009 +0200
@@ -191,23 +191,14 @@
int res;
m.type = GET_VERSION;
+ /* Double send, so an old ts will answer for sure at least once */
+ send_msg(server_socket, &m);
send_msg(server_socket, &m);
/* Set up a 2 second timeout to receive the
version msg. */
- install_sigalrm_donothing();
- alarm(2);
res = recv_msg(server_socket, &m);
- if(res == -1 || res == 0)
- {
- fprintf(stderr,
- "Error checking version with the server. Did you forget an "
- "old ts server running?\n");
- error("Error checking version");
- }
- alarm(0);
-
if (m.type != VERSION || m.u.version != PROTOCOL_VERSION)
{
printf("Wrong server version. Received %i, expecting %i\n",
@@ -216,6 +207,9 @@
error("Wrong server version. Received %i, expecting %i",
m.u.version, PROTOCOL_VERSION);
}
+
+ /* Receive also the 2nd send_msg if we got the right version */
+ res = recv_msg(server_socket, &m);
}
void c_show_info()
--- a/main.h Fri Oct 02 21:14:33 2009 +0200
+++ b/main.h Wed Oct 07 21:18:49 2009 +0200
@@ -260,7 +260,6 @@
void restore_sigmask();
void block_sigint();
void unblock_sigint_and_install_handler();
-void install_sigalrm_donothing();
/* msg.c */
void send_bytes(const int fd, const char *data, int bytes);
--- a/signals.c Fri Oct 02 21:14:33 2009 +0200
+++ b/signals.c Wed Oct 07 21:18:49 2009 +0200
@@ -71,18 +71,3 @@
* only that sets the normal_sigmask. */
sigprocmask(SIG_UNBLOCK, &set, 0);
}
-
-static void sigalrm_donothing(int s)
-{
-}
-
-void install_sigalrm_donothing()
-{
- struct sigaction act;
-
- /* Install the handler */
- act.sa_handler = sigalrm_donothing;
- sigemptyset(&act.sa_mask);
- act.sa_flags = 0;
- sigaction(SIGALRM, &act, 0);
-}