Skip to content

Commit

Permalink
sb: close on inactivity
Browse files Browse the repository at this point in the history
This fixes the long-standing problem of undelivered messages due to
switchboard timeouts.

In 1 to 1 conversations in normal conditions (when chatting with a
contact that uses WLM official client in Windows) the contact leaves
after 1 minute of inactivity; We would receive a BYE command, and
immediately afterward the connection should be closed. Other clients
will not leave the sb, in such cases the server will close it after 5
minutes.

However, in certain network conditions the BYE command is never
received, nor the notification of the closed connection. In such cases we
think the sb is alive so we send commands, but we never get
acknowledgement because the connection is already dead.

Further investigation would be required in order to determine why we are
not notified of the disconnection, but in order to workaround the issue
we now close sb after 1 minute of inactivity.

This is possibly not the best thing to do, but it emulates what the
official client does and for user's point of view it's perfect.

Fixes issue #181.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
  • Loading branch information
felipec committed Jul 12, 2009
1 parent 53fb0d5 commit 4d9982e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions switchboard.c
Expand Up @@ -128,6 +128,15 @@ close_cb (PnNode *conn,
msn_switchboard_close (swboard);
}

static gboolean
timeout (gpointer data)
{
MsnSwitchBoard *swboard = data;
msn_switchboard_close (swboard);

return FALSE;
}

/**************************************************************************
* Main
**************************************************************************/
Expand Down Expand Up @@ -189,6 +198,7 @@ msn_switchboard_new(MsnSession *session)
swboard->error_handler = g_signal_connect (conn, "error", G_CALLBACK (close_cb), swboard);
}

swboard->timer = pn_timer_new(timeout, swboard);
swboard->ref_count++;

return swboard;
Expand All @@ -206,6 +216,8 @@ msn_switchboard_free (MsnSwitchBoard *swboard)

g_return_if_fail(swboard);

pn_timer_free(swboard->timer);

g_signal_handler_disconnect (swboard->conn, swboard->open_handler);
g_signal_handler_disconnect (swboard->conn, swboard->close_handler);
g_signal_handler_disconnect (swboard->conn, swboard->error_handler);
Expand Down Expand Up @@ -699,6 +711,8 @@ release_msg(MsnSwitchBoard *swboard, MsnMessage *msg)
#endif
}

pn_timer_start(swboard->timer, 60);

trans->payload = payload;
trans->payload_len = payload_len;

Expand Down Expand Up @@ -857,6 +871,7 @@ static void
msg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len)
{
MsnMessage *msg;
MsnSwitchBoard *swboard = cmdproc->data;

msg = msn_message_new_from_cmd(cmd);

Expand All @@ -871,6 +886,8 @@ msg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len)
msg->remote_user = g_strdup(cmd->params[0]);
msn_cmdproc_process_msg(cmdproc, msg);

pn_timer_start(swboard->timer, 60);

msn_message_unref(msg);
}

Expand Down
2 changes: 2 additions & 0 deletions switchboard.h
Expand Up @@ -42,6 +42,7 @@ typedef enum

#include "io/pn_cmd_server.h"
#include "io/pn_node.h"
#include "pn_timer.h"

struct MsnSession;
struct MsnMessage;
Expand Down Expand Up @@ -97,6 +98,7 @@ struct MsnSwitchBoard
gulong error_handler;

guint ref_count;
struct pn_timer *timer;
};

/**
Expand Down

0 comments on commit 4d9982e

Please sign in to comment.