Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
libnice
Commits
03027077
Commit
03027077
authored
Feb 06, 2013
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: Make input non blocking to allow exit when remote hangs up
parent
73e28d8a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
8 deletions
+21
-8
examples/sdp-example.c
examples/sdp-example.c
+11
-4
examples/threaded-example.c
examples/threaded-example.c
+10
-4
No files found.
examples/sdp-example.c
View file @
03027077
...
...
@@ -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
"
);
...
...
examples/threaded-example.c
View file @
03027077
...
...
@@ -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
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment