Commit 03027077 authored by Youness Alaoui's avatar Youness Alaoui

examples: Make input non blocking to allow exit when remote hangs up

parent 73e28d8a
......@@ -41,6 +41,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <agent.h>
......@@ -117,6 +118,7 @@ example_thread(void *data)
gchar *sdp, *sdp64;
io_stdin = g_io_channel_unix_new(fileno(stdin));
g_io_channel_set_flags (io_stdin, G_IO_FLAG_NONBLOCK, NULL);
// Create the nice agent
agent = nice_agent_new(g_main_loop_get_context (gloop),
......@@ -174,8 +176,8 @@ example_thread(void *data)
printf("> ");
fflush (stdout);
while (!exit_thread) {
if (g_io_channel_read_line (io_stdin, &line, NULL, NULL, NULL) ==
G_IO_STATUS_NORMAL) {
GIOStatus s = g_io_channel_read_line (io_stdin, &line, NULL, NULL, NULL);
if (s == G_IO_STATUS_NORMAL) {
gsize sdp_len;
sdp = (gchar *) g_base64_decode (line, &sdp_len);
......@@ -193,6 +195,8 @@ example_thread(void *data)
}
g_free (sdp);
g_free (line);
} else if (s == G_IO_STATUS_AGAIN) {
usleep (100000);
}
}
......@@ -209,12 +213,15 @@ example_thread(void *data)
printf("> ");
fflush (stdout);
while (!exit_thread) {
if (g_io_channel_read_line (io_stdin, &line, NULL, NULL, NULL) ==
G_IO_STATUS_NORMAL) {
GIOStatus s = g_io_channel_read_line (io_stdin, &line, NULL, NULL, NULL);
if (s == G_IO_STATUS_NORMAL) {
nice_agent_send(agent, stream_id, 1, strlen(line), line);
g_free (line);
printf("> ");
fflush (stdout);
} else if (s == G_IO_STATUS_AGAIN) {
usleep (100000);
} else {
// Ctrl-D was pressed.
nice_agent_send(agent, stream_id, 1, 1, "\0");
......
......@@ -41,6 +41,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <agent.h>
......@@ -127,6 +128,7 @@ example_thread(void *data)
int rval;
io_stdin = g_io_channel_unix_new(fileno(stdin));
g_io_channel_set_flags (io_stdin, G_IO_FLAG_NONBLOCK, NULL);
// Create the nice agent
agent = nice_agent_new(g_main_loop_get_context (gloop),
......@@ -183,8 +185,8 @@ example_thread(void *data)
printf("> ");
fflush (stdout);
while (!exit_thread) {
if (g_io_channel_read_line (io_stdin, &line, NULL, NULL, NULL) ==
G_IO_STATUS_NORMAL) {
GIOStatus s = g_io_channel_read_line (io_stdin, &line, NULL, NULL, NULL);
if (s == G_IO_STATUS_NORMAL) {
// Parse remote candidate list and set it on the agent
rval = parse_remote_data(agent, stream_id, 1, line);
if (rval == EXIT_SUCCESS) {
......@@ -197,6 +199,8 @@ example_thread(void *data)
fflush (stdout);
}
g_free (line);
} else if (s == G_IO_STATUS_AGAIN) {
usleep (100000);
}
}
......@@ -225,12 +229,14 @@ example_thread(void *data)
printf("> ");
fflush (stdout);
while (!exit_thread) {
if (g_io_channel_read_line (io_stdin, &line, NULL, NULL, NULL) ==
G_IO_STATUS_NORMAL) {
GIOStatus s = g_io_channel_read_line (io_stdin, &line, NULL, NULL, NULL);
if (s == G_IO_STATUS_NORMAL) {
nice_agent_send(agent, stream_id, 1, strlen(line), line);
g_free (line);
printf("> ");
fflush (stdout);
} else if (s == G_IO_STATUS_AGAIN) {
usleep (100000);
} else {
// Ctrl-D was pressed.
nice_agent_send(agent, stream_id, 1, 1, "\0");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment