提交 4bd305e5 authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-3612 --resolve cool, thanks

上级 14b81f21
...@@ -1431,12 +1431,14 @@ static void j_setup_filter(ldl_handle_t *handle) ...@@ -1431,12 +1431,14 @@ static void j_setup_filter(ldl_handle_t *handle)
} }
} }
static void ldl_flush_queue(ldl_handle_t *handle, int done) static ldl_queue_t ldl_flush_queue(ldl_handle_t *handle, int done)
{ {
iks *msg; iks *msg;
void *pop = NULL; void *pop = NULL;
unsigned int len = 0, x = 0; unsigned int len = 0, x = 0;
ldl_queue_t sent_data = LDL_QUEUE_NONE;
apr_thread_mutex_lock(handle->lock); apr_thread_mutex_lock(handle->lock);
while(apr_queue_trypop(handle->queue, &pop) == APR_SUCCESS) { while(apr_queue_trypop(handle->queue, &pop) == APR_SUCCESS) {
...@@ -1445,6 +1447,7 @@ static void ldl_flush_queue(ldl_handle_t *handle, int done) ...@@ -1445,6 +1447,7 @@ static void ldl_flush_queue(ldl_handle_t *handle, int done)
if (!done) iks_send(handle->parser, msg); if (!done) iks_send(handle->parser, msg);
iks_delete(msg); iks_delete(msg);
pop = NULL; pop = NULL;
sent_data = LDL_QUEUE_SENT;
} else { } else {
break; break;
} }
...@@ -1473,6 +1476,7 @@ static void ldl_flush_queue(ldl_handle_t *handle, int done) ...@@ -1473,6 +1476,7 @@ static void ldl_flush_queue(ldl_handle_t *handle, int done)
} }
iks_send(handle->parser, packet_node->xml); iks_send(handle->parser, packet_node->xml);
packet_node->next = now + 5000000; packet_node->next = now + 5000000;
sent_data = LDL_QUEUE_SENT;
} }
} }
if (packet_node->retries == 0 || done) { if (packet_node->retries == 0 || done) {
...@@ -1490,17 +1494,22 @@ static void ldl_flush_queue(ldl_handle_t *handle, int done) ...@@ -1490,17 +1494,22 @@ static void ldl_flush_queue(ldl_handle_t *handle, int done)
} }
} }
apr_thread_mutex_unlock(handle->lock); apr_thread_mutex_unlock(handle->lock);
return sent_data;
} }
static void *APR_THREAD_FUNC queue_thread(apr_thread_t *thread, void *obj) static void *APR_THREAD_FUNC queue_thread(apr_thread_t *thread, void *obj)
{ {
ldl_handle_t *handle = (ldl_handle_t *) obj; ldl_handle_t *handle = (ldl_handle_t *) obj;
int timeout_ka = LDL_KEEPALIVE_TIMEOUT;
int count_ka = timeout_ka;
ldl_set_flag_locked(handle, LDL_FLAG_QUEUE_RUNNING); ldl_set_flag_locked(handle, LDL_FLAG_QUEUE_RUNNING);
while (ldl_test_flag(handle, LDL_FLAG_RUNNING) && !ldl_test_flag(handle, LDL_FLAG_QUEUE_STOP)) { while (ldl_test_flag(handle, LDL_FLAG_RUNNING) && !ldl_test_flag(handle, LDL_FLAG_QUEUE_STOP)) {
ldl_flush_queue(handle, 0); if (ldl_flush_queue(handle, 0) == LDL_QUEUE_SENT) {
count_ka = timeout_ka;
};
if (handle->loop_callback(handle) != LDL_STATUS_SUCCESS || !ldl_test_flag((&globals), LDL_FLAG_READY)) { if (handle->loop_callback(handle) != LDL_STATUS_SUCCESS || !ldl_test_flag((&globals), LDL_FLAG_READY)) {
int fd; int fd;
...@@ -1511,6 +1520,13 @@ static void *APR_THREAD_FUNC queue_thread(apr_thread_t *thread, void *obj) ...@@ -1511,6 +1520,13 @@ static void *APR_THREAD_FUNC queue_thread(apr_thread_t *thread, void *obj)
ldl_set_flag_locked(handle, LDL_FLAG_BREAK); ldl_set_flag_locked(handle, LDL_FLAG_BREAK);
break; break;
} }
if (count_ka-- <= 0) {
if( iks_send_raw(handle->parser, " ") == IKS_OK) {
count_ka = timeout_ka;
globals.logger(DL_LOG_DEBUG, "Sent keep alive signal\n");
}
}
microsleep(100); microsleep(100);
} }
...@@ -1618,6 +1634,7 @@ static void xmpp_connect(ldl_handle_t *handle, char *jabber_id, char *pass) ...@@ -1618,6 +1634,7 @@ static void xmpp_connect(ldl_handle_t *handle, char *jabber_id, char *pass)
ldl_flush_queue(handle, 0); ldl_flush_queue(handle, 0);
} }
handle->counter--;
if (!ldl_test_flag(handle, LDL_FLAG_CONNECTED)) { if (!ldl_test_flag(handle, LDL_FLAG_CONNECTED)) {
if (IKS_NET_TLSFAIL == e) { if (IKS_NET_TLSFAIL == e) {
globals.logger(DL_LOG_DEBUG, "tls handshake failed\n"); globals.logger(DL_LOG_DEBUG, "tls handshake failed\n");
......
...@@ -64,6 +64,8 @@ extern "C" { ...@@ -64,6 +64,8 @@ extern "C" {
#define LDL_MAX_PAYLOADS 50 #define LDL_MAX_PAYLOADS 50
#define LDL_RETRY 3 #define LDL_RETRY 3
#define IKS_NS_COMPONENT "jabber:component:accept" #define IKS_NS_COMPONENT "jabber:component:accept"
/* period between keep alive signals in 0.1sec units*/
#define LDL_KEEPALIVE_TIMEOUT 6000
/*! \brief A structure to store a jingle candidate */ /*! \brief A structure to store a jingle candidate */
struct ldl_candidate { struct ldl_candidate {
...@@ -173,6 +175,11 @@ typedef enum { ...@@ -173,6 +175,11 @@ typedef enum {
LDL_DESCRIPTION_ACCEPT LDL_DESCRIPTION_ACCEPT
} ldl_description_t; } ldl_description_t;
typedef enum {
LDL_QUEUE_NONE,
LDL_QUEUE_SENT
} ldl_queue_t;
#define DL_PRE __FILE__, __LDL_FUNC__, __LINE__ #define DL_PRE __FILE__, __LDL_FUNC__, __LINE__
#define DL_LOG_DEBUG DL_PRE, 7 #define DL_LOG_DEBUG DL_PRE, 7
#define DL_LOG_INFO DL_PRE, 6 #define DL_LOG_INFO DL_PRE, 6
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论