aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2016-04-29 00:06:51 +0200
committerMarius Halden <marius.h@lden.org>2016-05-07 14:31:03 +0200
commitc7caa906d60c7bebf2af7ce43fb375709e36da3f (patch)
treebac8b8e2a4ef544433750d082e24bd767b3d98e1
parent55ae34366cc42a3c1822718b47b4b65eb67c014b (diff)
Reconnect to twitter stream silently
-rw-r--r--protocols/twitter/twitter.h2
-rw-r--r--protocols/twitter/twitter_lib.c17
2 files changed, 19 insertions, 0 deletions
diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h
index 070dba40..a8ad424b 100644
--- a/protocols/twitter/twitter.h
+++ b/protocols/twitter/twitter.h
@@ -68,7 +68,9 @@ struct twitter_data {
gint main_loop_id;
gint filter_update_id;
struct http_request *stream;
+ time_t stream_opentime;
struct http_request *filter_stream;
+ time_t filter_stream_opentime;
struct groupchat *timeline_gc;
gint http_fails;
twitter_flags_t flags;
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index ae4a7079..44f0182d 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -1109,8 +1109,23 @@ static void twitter_http_stream(struct http_request *req)
if ((req->flags & HTTPC_EOF) || !req->reply_body) {
if (req == td->stream) {
td->stream = NULL;
+
+ if (req->status_code == 200 &&
+ td->stream_opentime + 3 < time(NULL)) {
+ debug("Reconnecting to twitter stream.");
+ twitter_open_stream(ic);
+ twitter_get_timeline(ic, -1);
+ return;
+ }
} else if (req == td->filter_stream) {
td->filter_stream = NULL;
+
+ if (req->status_code == 200 &&
+ td->filter_stream_opentime + 3 < time(NULL)) {
+ debug("Reconnecting to twitter filter stream.");
+ twitter_open_filter_stream(ic);
+ return;
+ }
}
imcb_error(ic, "Stream closed (%s)", req->status_string);
@@ -1285,6 +1300,7 @@ gboolean twitter_open_stream(struct im_connection *ic)
/* This flag must be enabled or we'll get no data until EOF
(which err, kind of, defeats the purpose of a streaming API). */
td->stream->flags |= HTTPC_STREAMING;
+ td->stream_opentime = time(NULL);
return TRUE;
}
@@ -1340,6 +1356,7 @@ static gboolean twitter_filter_stream(struct im_connection *ic)
/* This flag must be enabled or we'll get no data until EOF
(which err, kind of, defeats the purpose of a streaming API). */
td->filter_stream->flags |= HTTPC_STREAMING;
+ td->filter_stream_opentime = time(NULL);
ret = TRUE;
}