diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-05-25 17:41:59 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-05-25 17:41:59 +0200 |
commit | f86da7022c0490f5464e13e1a3781c3c881a4fa9 (patch) | |
tree | 23ece1d10699da07e07d25d55f12ae0ce4d974e3 /src/socket.c | |
parent | c8dca21ab48ea7033da5ce525aaffc68c54ee0b8 (diff) | |
download | cmumble-f86da7022c0490f5464e13e1a3781c3c881a4fa9.tar.gz cmumble-f86da7022c0490f5464e13e1a3781c3c881a4fa9.tar.bz2 cmumble-f86da7022c0490f5464e13e1a3781c3c881a4fa9.zip |
Ping every 5 seconds do not get disconnected
Diffstat (limited to 'src/socket.c')
-rw-r--r-- | src/socket.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/socket.c b/src/socket.c index d8603d9..5b42e53 100644 --- a/src/socket.c +++ b/src/socket.c @@ -147,13 +147,10 @@ handle_udp(struct context *ctx, uint8_t *data, uint32_t len) uint32_t read = 0; uint8_t frame_len, terminator; - printf("data[0]: 0x%x\n", data[0]); - printf("len: %u\n", len); session = decode_varint(&data[pos], &read, len-pos); pos += read; sequence = decode_varint(&data[pos], &read, len-pos); pos += read; - printf("session: %ld, sequence: %ld\n", session, sequence); do { frame_len = data[pos] & 0x7F; @@ -256,7 +253,6 @@ recv_msg(struct context *ctx, const callback_t *callbacks, uint32_t callback_siz abort(); } ret = g_input_stream_read(input, data, len, NULL, NULL); - printf("read ret: %d len: %d\n", ret, len); /* tunneled udp data - not a regular protobuf message */ if (type == 1) { @@ -280,7 +276,7 @@ recv_msg(struct context *ctx, const callback_t *callbacks, uint32_t callback_siz free(data); } -static void +static gboolean do_ping(struct context *ctx) { MumbleProto__Ping ping; @@ -293,6 +289,8 @@ do_ping(struct context *ctx) ping.resync = 1; send_msg(ctx, &ping.base); + + return TRUE; } static const callback_t callbacks[] = { @@ -511,6 +509,7 @@ int main(int argc, char **argv) #endif struct context ctx; GError *error = NULL; + GSource *source; memset(&ctx, 0, sizeof(ctx)); @@ -557,11 +556,16 @@ int main(int argc, char **argv) return 1; ctx.sock = g_socket_connection_get_socket(ctx.conn); - GSource *source = g_socket_create_source(ctx.sock, G_IO_IN | G_IO_ERR, NULL); + source = g_socket_create_source(ctx.sock, G_IO_IN | G_IO_ERR, NULL); g_source_set_callback(source, (GSourceFunc)read_cb, &ctx, NULL); g_source_attach(source, NULL); g_source_unref(source); + source = g_timeout_source_new_seconds(5); + g_source_set_callback(source, (GSourceFunc)do_ping, &ctx, NULL); + g_source_attach(source, NULL); + g_source_unref(source); + g_main_loop_run(ctx.loop); g_main_loop_unref(ctx.loop); |