-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 This patch makes awesome-client give up after 10 tries when it lost the connection to awesome. Also it now waits for some time between reconnect attempts. I like the behaviour of this, but some of the code seems a little icky...
Signed-off-by: Uli Schlachter <[email protected]> - --- awesome-client.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 files changed, 35 insertions(+), 11 deletions(-) diff --git a/awesome-client.c b/awesome-client.c index c55f0d7..c7c84fa 100644 - --- a/awesome-client.c +++ b/awesome-client.c @@ -84,34 +84,54 @@ sockets_reconnect(void) sockets_init(); } - -/** Send a message to awesome. +/** Send a message to awesome without handling retries. * \param msg The message. * \param msg_len The message length. - - * \return The errno of sendto(). + * \return The errno of send(). */ static int - -send_msg(const char *msg, ssize_t msg_len) +send_msg_raw(const char *msg, ssize_t msg_len) { #ifndef __FreeBSD__ - - if(send(csfd, msg, msg_len, MSG_NOSIGNAL | MSG_EOR) == -1) + return send(csfd, msg, msg_len, MSG_NOSIGNAL | MSG_EOR); #else - - if(send(csfd, msg, msg_len, MSG_NOSIGNAL | MSG_EOF) == -1) + return send(csfd, msg, msg_len, MSG_NOSIGNAL | MSG_EOF); #endif +} + +/** Send a message to awesome. + * \param msg The message. + * \param msg_len The message length. + * \return The errno of send(). + */ +static int +send_msg(const char *msg, ssize_t msg_len) +{ + int try = 10; + + while (try && send_msg_raw(msg, msg_len) == -1) { switch (errno) { - - case ENOENT: - - warn("can't write to %s", addr->sun_path); - - break; case EPIPE: case ENOTCONN: case ECONNRESET: sockets_reconnect(); - - return send_msg(msg, msg_len); + try--; + break; + case ENOENT: + warn("can't write to %s", addr->sun_path); + return errno; default: warn("error sending packet: %s", strerror(errno)); + return errno; } - - return errno; + usleep(100000); + } + if(!try) + { + warn("giving up."); + return EXIT_FAILURE; } return EXIT_SUCCESS; @@ -201,12 +221,16 @@ main(int argc, char **argv) while((msg = readline(prompt))) if((msg_len = a_strlen(msg))) { + int result; add_history (msg); p_realloc(&msg, msg_len + 2); msg[msg_len] = '\n'; msg[msg_len + 1] = '\0'; - - if(send_msg(msg, msg_len + 2) == EXIT_SUCCESS) + result = send_msg(msg, msg_len + 2); + if(result == EXIT_SUCCESS) recv_msg(); + else if(result == EXIT_FAILURE) + break; p_delete(&msg); } } - -- 1.6.2 - -- "Do you know that books smell like nutmeg or some spice from a foreign land?" -- Faber in Fahrenheit 451 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkm/z5QACgkQABixOSrV9982WQCcD1Ius5QtFWNx5Afo1DD7dS3/ IQwAoN0ME0yU8BbFlA5uDj59jG65grvu =ubkJ -----END PGP SIGNATURE----- -- To unsubscribe, send mail to [email protected].
