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
d3a640c2
Commit
d3a640c2
authored
Feb 25, 2014
by
Olivier Crête
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: Use dynamically allocated port for test-new-dribble
parent
1771bc79
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
15 deletions
+29
-15
tests/test-new-dribble.c
tests/test-new-dribble.c
+29
-15
No files found.
tests/test-new-dribble.c
View file @
d3a640c2
...
@@ -52,7 +52,6 @@
...
@@ -52,7 +52,6 @@
#include "agent-priv.h"
#include "agent-priv.h"
#include "agent.h"
#include "agent.h"
#define IPPORT_STUN 3456
#define USE_UPNP 0
#define USE_UPNP 0
#define LEFT_AGENT GINT_TO_POINTER(1)
#define LEFT_AGENT GINT_TO_POINTER(1)
#define RIGHT_AGENT GINT_TO_POINTER(2)
#define RIGHT_AGENT GINT_TO_POINTER(2)
...
@@ -84,6 +83,7 @@ static gboolean data_received = FALSE;
...
@@ -84,6 +83,7 @@ static gboolean data_received = FALSE;
static
gboolean
drop_stun_packets
=
FALSE
;
static
gboolean
drop_stun_packets
=
FALSE
;
static
gboolean
got_stun_packet
=
FALSE
;
static
gboolean
got_stun_packet
=
FALSE
;
static
gboolean
send_stun
=
FALSE
;
static
gboolean
send_stun
=
FALSE
;
static
guint
stun_port
;
static
const
uint16_t
known_attributes
[]
=
{
static
const
uint16_t
known_attributes
[]
=
{
0
0
...
@@ -92,7 +92,7 @@ static const uint16_t known_attributes[] = {
...
@@ -92,7 +92,7 @@ static const uint16_t known_attributes[] = {
/*
/*
* Creates a listening socket
* Creates a listening socket
*/
*/
static
int
listen_socket
(
unsigned
int
port
)
static
int
listen_socket
(
unsigned
int
*
port
)
{
{
union
{
union
{
struct
sockaddr_in
in
;
struct
sockaddr_in
in
;
...
@@ -108,13 +108,24 @@ static int listen_socket (unsigned int port)
...
@@ -108,13 +108,24 @@ static int listen_socket (unsigned int port)
memset
(
&
addr
,
0
,
sizeof
(
addr
));
memset
(
&
addr
,
0
,
sizeof
(
addr
));
addr
.
in
.
sin_family
=
AF_INET
;
addr
.
in
.
sin_family
=
AF_INET
;
inet_pton
(
AF_INET
,
"127.0.0.1"
,
&
addr
.
in
.
sin_addr
);
inet_pton
(
AF_INET
,
"127.0.0.1"
,
&
addr
.
in
.
sin_addr
);
addr
.
in
.
sin_port
=
htons
(
port
)
;
addr
.
in
.
sin_port
=
0
;
if
(
bind
(
fd
,
&
addr
.
addr
,
sizeof
(
struct
sockaddr_in
)))
{
if
(
bind
(
fd
,
&
addr
.
addr
,
sizeof
(
struct
sockaddr_in
)))
{
perror
(
"Error opening IP port"
);
perror
(
"Error opening IP port"
);
goto
error
;
goto
error
;
}
}
if
(
port
)
{
socklen_t
socklen
=
sizeof
(
addr
);
if
(
getsockname
(
fd
,
&
addr
.
addr
,
&
socklen
)
<
0
)
g_error
(
"getsockname failed: %s"
,
strerror
(
errno
));
g_assert
(
socklen
==
sizeof
(
struct
sockaddr_in
));
*
port
=
ntohs
(
addr
.
in
.
sin_port
);
g_assert
(
*
port
!=
0
);
}
return
fd
;
return
fd
;
error:
error:
...
@@ -228,15 +239,9 @@ static gpointer stun_thread_func (const gpointer user_data)
...
@@ -228,15 +239,9 @@ static gpointer stun_thread_func (const gpointer user_data)
{
{
StunAgent
oldagent
;
StunAgent
oldagent
;
StunAgent
newagent
;
StunAgent
newagent
;
int
sock
;
int
sock
=
GPOINTER_TO_INT
(
user_data
)
;
int
exit_code
=
-
1
;
int
exit_code
=
-
1
;
sock
=
listen_socket
(
IPPORT_STUN
);
if
(
sock
==
-
1
)
{
g_assert_not_reached
();
}
g_mutex_lock
(
stun_thread_mutex_ptr
);
g_mutex_lock
(
stun_thread_mutex_ptr
);
g_cond_signal
(
stun_thread_signal_ptr
);
g_cond_signal
(
stun_thread_signal_ptr
);
g_mutex_unlock
(
stun_thread_mutex_ptr
);
g_mutex_unlock
(
stun_thread_mutex_ptr
);
...
@@ -681,7 +686,7 @@ static void new_candidate_test(NiceAgent *lagent, NiceAgent *ragent)
...
@@ -681,7 +686,7 @@ static void new_candidate_test(NiceAgent *lagent, NiceAgent *ragent)
static
void
send_dummy_data
(
void
)
static
void
send_dummy_data
(
void
)
{
{
int
sockfd
=
listen_socket
(
4567
);
int
sockfd
=
listen_socket
(
NULL
);
union
{
union
{
struct
sockaddr_in
in
;
struct
sockaddr_in
in
;
struct
sockaddr
addr
;
struct
sockaddr
addr
;
...
@@ -690,7 +695,7 @@ static void send_dummy_data(void)
...
@@ -690,7 +695,7 @@ static void send_dummy_data(void)
memset
(
&
addr
,
0
,
sizeof
(
addr
));
memset
(
&
addr
,
0
,
sizeof
(
addr
));
addr
.
in
.
sin_family
=
AF_INET
;
addr
.
in
.
sin_family
=
AF_INET
;
inet_pton
(
AF_INET
,
"127.0.0.1"
,
&
addr
.
in
.
sin_addr
);
inet_pton
(
AF_INET
,
"127.0.0.1"
,
&
addr
.
in
.
sin_addr
);
addr
.
in
.
sin_port
=
htons
(
IPPORT_STUN
);
addr
.
in
.
sin_port
=
htons
(
stun_port
);
g_debug
(
"Sending dummy data to close STUN thread"
);
g_debug
(
"Sending dummy data to close STUN thread"
);
sendto
(
sockfd
,
"close socket"
,
12
,
0
,
sendto
(
sockfd
,
"close socket"
,
12
,
0
,
...
@@ -703,6 +708,7 @@ int main(void)
...
@@ -703,6 +708,7 @@ int main(void)
GThread
*
stun_thread
=
NULL
;
GThread
*
stun_thread
=
NULL
;
NiceAddress
baseaddr
;
NiceAddress
baseaddr
;
GSource
*
src
;
GSource
*
src
;
int
sock
;
g_type_init
();
g_type_init
();
...
@@ -712,14 +718,22 @@ int main(void)
...
@@ -712,14 +718,22 @@ int main(void)
g_source_attach
(
src
,
NULL
);
g_source_attach
(
src
,
NULL
);
g_source_unref
(
src
);
g_source_unref
(
src
);
sock
=
listen_socket
(
&
stun_port
);
if
(
sock
==
-
1
)
{
g_assert_not_reached
();
}
#if !GLIB_CHECK_VERSION(2,31,8)
#if !GLIB_CHECK_VERSION(2,31,8)
g_thread_init
(
NULL
);
g_thread_init
(
NULL
);
stun_thread
=
g_thread_create
(
stun_thread_func
,
NULL
,
TRUE
,
NULL
);
stun_thread
=
g_thread_create
(
stun_thread_func
,
GINT_TO_POINTER
(
sock
),
TRUE
,
NULL
);
stun_mutex_ptr
=
g_mutex_new
();
stun_mutex_ptr
=
g_mutex_new
();
stun_signal_ptr
=
g_cond_new
();
stun_signal_ptr
=
g_cond_new
();
#else
#else
stun_thread
=
g_thread_new
(
"listen for STUN requests"
,
stun_thread
=
g_thread_new
(
"listen for STUN requests"
,
stun_thread_func
,
NULL
);
stun_thread_func
,
GINT_TO_POINTER
(
sock
)
);
#endif
#endif
// Once the the thread is forked, we want to listen for a signal
// Once the the thread is forked, we want to listen for a signal
...
@@ -737,7 +751,7 @@ int main(void)
...
@@ -737,7 +751,7 @@ int main(void)
g_object_set
(
G_OBJECT
(
ragent
),
"upnp"
,
USE_UPNP
,
NULL
);
g_object_set
(
G_OBJECT
(
ragent
),
"upnp"
,
USE_UPNP
,
NULL
);
g_object_set
(
G_OBJECT
(
lagent
),
"stun-server"
,
"127.0.0.1"
,
NULL
);
g_object_set
(
G_OBJECT
(
lagent
),
"stun-server"
,
"127.0.0.1"
,
NULL
);
g_object_set
(
G_OBJECT
(
lagent
),
"stun-server-port"
,
IPPORT_STUN
,
NULL
);
g_object_set
(
G_OBJECT
(
lagent
),
"stun-server-port"
,
stun_port
,
NULL
);
g_object_set_data
(
G_OBJECT
(
lagent
),
"other-agent"
,
ragent
);
g_object_set_data
(
G_OBJECT
(
lagent
),
"other-agent"
,
ragent
);
g_object_set_data
(
G_OBJECT
(
ragent
),
"other-agent"
,
lagent
);
g_object_set_data
(
G_OBJECT
(
ragent
),
"other-agent"
,
lagent
);
...
...
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