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
7e665bf9
Commit
7e665bf9
authored
Feb 01, 2007
by
Dafydd Harries
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add "nice" prefix to UDP code
darcs-hash:20070201183830-c9803-6e562ea7405a931c59d56fbf67075fcaf90b1ee9.gz
parent
aa301c19
Changes
18
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
143 additions
and
143 deletions
+143
-143
agent/agent.c
agent/agent.c
+7
-7
agent/agent.h
agent/agent.h
+2
-2
agent/candidate.h
agent/candidate.h
+1
-1
agent/test-recv.c
agent/test-recv.c
+6
-6
agent/test-stun.c
agent/test-stun.c
+14
-14
agent/test.c
agent/test.c
+3
-3
nice/ice-test-client.c
nice/ice-test-client.c
+10
-10
nice/ice-test-server.c
nice/ice-test-server.c
+11
-11
nice/libnice.symbols
nice/libnice.symbols
+9
-9
udp/test.c
udp/test.c
+10
-10
udp/udp-bsd.c
udp/udp-bsd.c
+14
-14
udp/udp-bsd.h
udp/udp-bsd.h
+1
-1
udp/udp-client.c
udp/udp-client.c
+8
-8
udp/udp-echo-server.c
udp/udp-echo-server.c
+3
-3
udp/udp-fake.c
udp/udp-fake.c
+12
-12
udp/udp-fake.h
udp/udp-fake.h
+5
-5
udp/udp-generic.c
udp/udp-generic.c
+9
-9
udp/udp.h
udp/udp.h
+18
-18
No files found.
agent/agent.c
View file @
7e665bf9
...
...
@@ -174,17 +174,17 @@ nice_event_free (Event *ev)
/**
* nice_agent_new:
*
* @
mgr: a UDPSocketManager
used for allocating sockets
* @
factory: a NiceUDPSocketFactory
used for allocating sockets
*
* Create a new NiceAgent.
**/
NiceAgent
*
nice_agent_new
(
UDPSocketManager
*
mgr
)
nice_agent_new
(
NiceUDPSocketFactory
*
factory
)
{
NiceAgent
*
agent
;
agent
=
g_slice_new0
(
NiceAgent
);
agent
->
sock
mgr
=
mgr
;
agent
->
sock
et_factory
=
factory
;
agent
->
next_candidate_id
=
1
;
agent
->
next_stream_id
=
1
;
return
agent
;
...
...
@@ -247,7 +247,7 @@ nice_agent_add_local_host_candidate (
sin
.
sin_addr
.
s_addr
=
htonl
(
address
->
addr_ipv4
);
sin
.
sin_port
=
0
;
/* XXX: handle error */
udp_socket_manager_alloc_socket
(
agent
->
sockmgr
,
&
(
candidate
->
sock
),
&
sin
);
nice_udp_socket_factory_make
(
agent
->
socket_factory
,
&
(
candidate
->
sock
),
&
sin
);
candidate
->
port
=
ntohs
(
candidate
->
sock
.
addr
.
sin_port
);
}
...
...
@@ -496,7 +496,7 @@ RESPOND:
response
->
attributes
[
0
]
=
stun_attribute_mapped_address_new
(
ntohl
(
from
.
sin_addr
.
s_addr
),
ntohs
(
from
.
sin_port
));
len
=
stun_message_pack
(
response
,
&
packed
);
udp_socket_send
(
&
local
->
sock
,
&
from
,
len
,
packed
);
nice_
udp_socket_send
(
&
local
->
sock
,
&
from
,
len
,
packed
);
g_free
(
packed
);
stun_message_free
(
response
);
...
...
@@ -513,7 +513,7 @@ ERROR:
response
=
stun_message_new
(
STUN_MESSAGE_BINDING_ERROR_RESPONSE
,
msg
->
transaction_id
,
0
);
len
=
stun_message_pack
(
response
,
&
packed
);
udp_socket_send
(
&
local
->
sock
,
&
from
,
len
,
packed
);
nice_
udp_socket_send
(
&
local
->
sock
,
&
from
,
len
,
packed
);
g_free
(
packed
);
stun_message_free
(
response
);
...
...
@@ -542,7 +542,7 @@ _nice_agent_recv (
gchar
buf
[
1024
];
struct
sockaddr_in
from
;
len
=
udp_socket_recv
(
&
(
candidate
->
sock
),
&
from
,
len
=
nice_
udp_socket_recv
(
&
(
candidate
->
sock
),
&
from
,
sizeof
(
buf
)
/
sizeof
(
gchar
),
buf
);
g_assert
(
len
>
0
);
...
...
agent/agent.h
View file @
7e665bf9
...
...
@@ -57,7 +57,7 @@ struct _NiceAgent
{
guint
next_candidate_id
;
guint
next_stream_id
;
UDPSocketManager
*
sockmgr
;
NiceUDPSocketFactory
*
socket_factory
;
GSList
*
local_addresses
;
GSList
*
local_candidates
;
GSList
*
remote_candidates
;
...
...
@@ -72,7 +72,7 @@ typedef void (*NiceAgentRecvHandler) (
NiceAgent
*
nice_agent_new
(
UDPSocketManager
*
mgr
);
nice_agent_new
(
NiceUDPSocketFactory
*
factory
);
Event
*
nice_agent_pop_event
(
NiceAgent
*
agent
);
...
...
agent/candidate.h
View file @
7e665bf9
...
...
@@ -29,7 +29,7 @@ struct _NiceCandidate
guint
component_id
;
// guint generation;
// gchar *foundation;
UDPSocket
sock
;
Nice
UDPSocket
sock
;
gchar
username
[
128
];
gchar
password
[
128
];
};
...
...
agent/test-recv.c
View file @
7e665bf9
...
...
@@ -29,14 +29,14 @@ main (void)
NiceAgent
*
agent
;
NiceAddress
addr
;
NiceCandidate
*
candidate
;
UDPSocketManager
mgr
;
UDPSocket
*
sock
;
NiceUDPSocketFactory
factory
;
Nice
UDPSocket
*
sock
;
struct
sockaddr_in
from
=
{
0
,};
udp_fake_socket_manager_init
(
&
mgr
);
nice_udp_fake_socket_factory_init
(
&
factory
);
/* set up agent */
agent
=
nice_agent_new
(
&
mgr
);
agent
=
nice_agent_new
(
&
factory
);
nice_address_set_ipv4_from_string
(
&
addr
,
"192.168.0.1"
);
nice_agent_add_local_address
(
agent
,
&
addr
);
nice_agent_add_stream
(
agent
,
handle_recv
,
NULL
);
...
...
@@ -45,13 +45,13 @@ main (void)
/* recieve an RTP packet */
candidate
=
agent
->
local_candidates
->
data
;
sock
=
&
(
candidate
->
sock
);
udp_fake_socket_push_recv
(
sock
,
&
from
,
7
,
"
\x80
lalala"
);
nice_
udp_fake_socket_push_recv
(
sock
,
&
from
,
7
,
"
\x80
lalala"
);
nice_agent_recv
(
agent
,
candidate
->
id
);
g_assert
(
cb_called
==
TRUE
);
/* clean up */
nice_agent_free
(
agent
);
udp_socket_manager_close
(
&
mgr
);
nice_udp_socket_factory_close
(
&
factory
);
return
0
;
}
...
...
agent/test-stun.c
View file @
7e665bf9
...
...
@@ -23,7 +23,7 @@ test_stun_no_password (
struct
sockaddr_in
from
)
{
NiceCandidate
*
candidate
;
UDPSocket
*
sock
;
Nice
UDPSocket
*
sock
;
guint
len
;
struct
sockaddr_in
to
=
{
0
,};
gchar
buf
[
1024
];
...
...
@@ -42,7 +42,7 @@ test_stun_no_password (
breq
=
stun_message_new
(
STUN_MESSAGE_BINDING_REQUEST
,
"0123456789abcdef"
,
0
);
packed_len
=
stun_message_pack
(
breq
,
&
packed
);
udp_fake_socket_push_recv
(
sock
,
&
from
,
packed_len
,
packed
);
nice_
udp_fake_socket_push_recv
(
sock
,
&
from
,
packed_len
,
packed
);
g_free
(
packed
);
stun_message_free
(
breq
);
}
...
...
@@ -51,7 +51,7 @@ test_stun_no_password (
nice_agent_recv
(
agent
,
candidate
->
id
);
/* error response should have been sent */
len
=
udp_fake_socket_pop_send
(
sock
,
&
to
,
sizeof
(
buf
)
/
sizeof
(
gchar
),
len
=
nice_
udp_fake_socket_pop_send
(
sock
,
&
to
,
sizeof
(
buf
)
/
sizeof
(
gchar
),
buf
);
g_assert
(
len
!=
0
);
...
...
@@ -74,7 +74,7 @@ test_stun_invalid_password (
struct
sockaddr_in
from
)
{
NiceCandidate
*
candidate
;
UDPSocket
*
sock
;
Nice
UDPSocket
*
sock
;
guint
len
;
struct
sockaddr_in
to
=
{
0
,};
gchar
buf
[
1024
];
...
...
@@ -95,7 +95,7 @@ test_stun_invalid_password (
breq
->
attributes
[
0
]
=
stun_attribute_username_new
(
"lala"
);
packed_len
=
stun_message_pack
(
breq
,
&
packed
);
g_assert
(
packed_len
!=
0
);
udp_fake_socket_push_recv
(
sock
,
&
from
,
packed_len
,
packed
);
nice_
udp_fake_socket_push_recv
(
sock
,
&
from
,
packed_len
,
packed
);
g_free
(
packed
);
stun_message_free
(
breq
);
}
...
...
@@ -104,7 +104,7 @@ test_stun_invalid_password (
nice_agent_recv
(
agent
,
candidate
->
id
);
/* error should have been sent */
len
=
udp_fake_socket_pop_send
(
sock
,
&
to
,
sizeof
(
buf
)
/
sizeof
(
gchar
),
len
=
nice_
udp_fake_socket_pop_send
(
sock
,
&
to
,
sizeof
(
buf
)
/
sizeof
(
gchar
),
buf
);
g_assert
(
len
!=
0
);
...
...
@@ -127,7 +127,7 @@ test_stun_valid_password (
struct
sockaddr_in
from
)
{
NiceCandidate
*
candidate
;
UDPSocket
*
sock
;
Nice
UDPSocket
*
sock
;
guint
len
;
guint
packed_len
;
struct
sockaddr_in
to
=
{
0
,};
...
...
@@ -156,7 +156,7 @@ test_stun_valid_password (
g_free
(
username
);
packed_len
=
stun_message_pack
(
breq
,
&
packed
);
g_assert
(
packed_len
!=
0
);
udp_fake_socket_push_recv
(
sock
,
&
from
,
packed_len
,
packed
);
nice_
udp_fake_socket_push_recv
(
sock
,
&
from
,
packed_len
,
packed
);
g_free
(
packed
);
stun_message_free
(
breq
);
}
...
...
@@ -178,7 +178,7 @@ test_stun_valid_password (
nice_agent_recv
(
agent
,
candidate
->
id
);
/* compare sent packet to expected */
len
=
udp_fake_socket_pop_send
(
sock
,
&
to
,
sizeof
(
buf
)
/
sizeof
(
gchar
),
len
=
nice_
udp_fake_socket_pop_send
(
sock
,
&
to
,
sizeof
(
buf
)
/
sizeof
(
gchar
),
buf
);
g_assert
(
len
==
packed_len
);
g_assert
(
0
==
memcmp
(
buf
,
packed
,
len
));
...
...
@@ -194,11 +194,11 @@ main (void)
NiceAgent
*
agent
;
NiceAddress
local_addr
,
remote_addr
;
NiceCandidate
*
candidate
;
UDPSocketManager
mgr
;
UDPSocket
*
sock
;
NiceUDPSocketFactory
factory
;
Nice
UDPSocket
*
sock
;
struct
sockaddr_in
from
=
{
0
,};
udp_fake_socket_manager_init
(
&
mgr
);
nice_udp_fake_socket_factory_init
(
&
factory
);
nice_address_set_ipv4_from_string
(
&
local_addr
,
"192.168.0.1"
);
nice_address_set_ipv4_from_string
(
&
remote_addr
,
"192.168.0.5"
);
...
...
@@ -208,7 +208,7 @@ main (void)
from
.
sin_port
=
htons
(
5678
);
/* set up agent */
agent
=
nice_agent_new
(
&
mgr
);
agent
=
nice_agent_new
(
&
factory
);
nice_agent_add_local_address
(
agent
,
&
local_addr
);
nice_agent_add_stream
(
agent
,
handle_recv
,
NULL
);
nice_agent_add_remote_candidate
(
agent
,
1
,
1
,
NICE_CANDIDATE_TYPE_HOST
,
...
...
@@ -224,7 +224,7 @@ main (void)
/* clean up */
nice_agent_free
(
agent
);
udp_socket_manager_close
(
&
mgr
);
nice_udp_socket_factory_close
(
&
factory
);
return
0
;
}
...
...
agent/test.c
View file @
7e665bf9
...
...
@@ -22,14 +22,14 @@ main (void)
NiceAgent
*
agent
;
NiceAddress
addr_local
,
addr_remote
;
NiceCandidate
*
candidate
;
UDPSocketManager
mgr
;
NiceUDPSocketFactory
factory
;
udp_fake_socket_manager_init
(
&
mgr
);
nice_udp_fake_socket_factory_init
(
&
factory
);
nice_address_set_ipv4_from_string
(
&
addr_local
,
"192.168.0.1"
);
nice_address_set_ipv4_from_string
(
&
addr_remote
,
"192.168.0.2"
);
agent
=
nice_agent_new
(
&
mgr
);
agent
=
nice_agent_new
(
&
factory
);
g_assert
(
agent
->
local_addresses
==
NULL
);
g_assert
(
agent
->
local_candidates
==
NULL
);
...
...
nice/ice-test-client.c
View file @
7e665bf9
...
...
@@ -9,7 +9,7 @@
#include "stun.h"
static
void
send_stun
(
UDPSocket
*
udpsock
,
struct
sockaddr_in
sin
)
send_stun
(
Nice
UDPSocket
*
udpsock
,
struct
sockaddr_in
sin
)
{
gchar
*
packed
;
guint
packed_len
;
...
...
@@ -27,11 +27,11 @@ send_stun (UDPSocket *udpsock, struct sockaddr_in sin)
}
packed_len
=
stun_message_pack
(
msg
,
&
packed
);
udp_socket_send
(
udpsock
,
&
sin
,
packed_len
,
packed
);
nice_
udp_socket_send
(
udpsock
,
&
sin
,
packed_len
,
packed
);
g_free
(
packed
);
stun_message_free
(
msg
);
packed_len
=
udp_socket_recv
(
udpsock
,
&
sin
,
1024
,
buf
);
packed_len
=
nice_
udp_socket_recv
(
udpsock
,
&
sin
,
1024
,
buf
);
g_assert
(
packed_len
>
0
);
msg
=
stun_message_unpack
(
packed_len
,
buf
);
g_assert
(
msg
);
...
...
@@ -51,8 +51,8 @@ handle_connection (guint sock)
{
gchar
*
line
;
struct
sockaddr_in
sin
;
UDPSocketManager
man
;
UDPSocket
udpsock
;
NiceUDPSocketFactory
man
;
Nice
UDPSocket
udpsock
;
NiceCandidate
*
candidate
;
line
=
readline
(
sock
);
...
...
@@ -67,13 +67,13 @@ handle_connection (guint sock)
g_debug
(
"got candidate"
);
udp_bsd_socket_manager
_init
(
&
man
);
nice_udp_bsd_socket_factory
_init
(
&
man
);
sin
.
sin_family
=
AF_INET
;
sin
.
sin_addr
.
s_addr
=
INADDR_ANY
;
sin
.
sin_port
=
0
;
if
(
!
udp_socket_manager_alloc_socket
(
&
man
,
&
udpsock
,
&
sin
))
if
(
!
nice_udp_socket_factory_make
(
&
man
,
&
udpsock
,
&
sin
))
goto
OUT
;
// copy remote candidate address into sin
...
...
@@ -83,11 +83,11 @@ handle_connection (guint sock)
// agent doesn't proactively do STUN, so we have to do it ourselves for now
send_stun
(
&
udpsock
,
sin
);
udp_socket_send
(
&
udpsock
,
&
sin
,
6
,
"
\x80
hello"
);
udp_socket_close
(
&
udpsock
);
nice_
udp_socket_send
(
&
udpsock
,
&
sin
,
6
,
"
\x80
hello"
);
nice_
udp_socket_close
(
&
udpsock
);
OUT:
udp_socket_manager
_close
(
&
man
);
nice_udp_socket_factory
_close
(
&
man
);
nice_candidate_free
(
candidate
);
}
...
...
nice/ice-test-server.c
View file @
7e665bf9
...
...
@@ -25,15 +25,15 @@ handle_recv (
static
gboolean
make_agent
(
gchar
*
ip
,
UDPSocketManager
*
mgr
,
NiceUDPSocketFactory
*
factory
,
NiceAgent
**
ret_agent
,
UDPSocket
**
ret_sock
)
Nice
UDPSocket
**
ret_sock
)
{
NiceAgent
*
agent
;
NiceAddress
addr_local
;
NiceCandidate
*
candidate
;
agent
=
nice_agent_new
(
mgr
);
agent
=
nice_agent_new
(
factory
);
nice_address_set_ipv4_from_string
(
&
addr_local
,
ip
);
nice_agent_add_local_address
(
agent
,
&
addr_local
);
...
...
@@ -70,8 +70,8 @@ static void
handle_connection
(
guint
fileno
,
const
struct
sockaddr_in
*
sin
,
gpointer
data
)
{
NiceAgent
*
agent
;
UDPSocketManager
mgr
;
UDPSocket
*
sock
;
NiceUDPSocketFactory
factory
;
Nice
UDPSocket
*
sock
;
GSList
*
sockets
=
NULL
;
gchar
ip_str
[
INET_ADDRSTRLEN
];
fd_set
fds
;
...
...
@@ -81,9 +81,9 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
inet_ntop
(
AF_INET
,
&
(
sin
->
sin_addr
),
ip_str
,
INET_ADDRSTRLEN
);
g_debug
(
"got connection from %s:%d"
,
ip_str
,
ntohs
(
sin
->
sin_port
));
udp_bsd_socket_manager_init
(
&
mgr
);
nice_udp_bsd_socket_factory_init
(
&
factory
);
if
(
!
make_agent
((
gchar
*
)
data
,
&
mgr
,
&
agent
,
&
sock
))
if
(
!
make_agent
((
gchar
*
)
data
,
&
factory
,
&
agent
,
&
sock
))
return
;
sockets
=
g_slist_append
(
sockets
,
sock
);
...
...
@@ -141,17 +141,17 @@ END:
while
(
sockets
!=
NULL
)
{
GSList
*
tmp
;
UDPSocket
*
sock
=
sockets
->
data
;
Nice
UDPSocket
*
sock
=
sockets
->
data
;
tmp
=
sockets
;
sockets
=
sockets
->
next
;
g_slist_free_1
(
tmp
);
udp_socket_close
(
sock
);
g_slice_free
(
UDPSocket
,
sock
);
nice_
udp_socket_close
(
sock
);
g_slice_free
(
Nice
UDPSocket
,
sock
);
}
g_slist_free
(
sockets
);
udp_socket_manager_close
(
&
mgr
);
nice_udp_socket_factory_close
(
&
factory
);
}
static
gboolean
...
...
nice/libnice.symbols
View file @
7e665bf9
...
...
@@ -25,12 +25,12 @@ T nice_rng_generate_bytes
T nice_rng_generate_bytes_print
T nice_rng_generate_int
T nice_rng_new
T
udp_bsd_socket_manager
_init
T
udp_fake_socket_manager
_init
T udp_fake_socket_pop_send
T udp_fake_socket_push_recv
T udp_socket_close
T
udp_socket_manager_alloc_socket
T
udp_socket_manager_clos
e
T udp_socket_recv
T udp_socket_send
T
nice_udp_bsd_socket_factory
_init
T
nice_udp_fake_socket_factory
_init
T
nice_
udp_fake_socket_pop_send
T
nice_
udp_fake_socket_push_recv
T
nice_
udp_socket_close
T
nice_udp_socket_factory_close
T
nice_udp_socket_factory_mak
e
T
nice_
udp_socket_recv
T
nice_
udp_socket_send
udp/test.c
View file @
7e665bf9
...
...
@@ -7,13 +7,13 @@
int
main
(
void
)
{
UDPSocketManager
man
;
UDPSocket
sock
;
NiceUDPSocketFactory
man
;
Nice
UDPSocket
sock
;
struct
sockaddr_in
sin
=
{
0
,};
guint
len
;
gchar
buf
[
1024
];
udp_fake_socket_manager
_init
(
&
man
);
nice_udp_fake_socket_factory
_init
(
&
man
);
memset
(
buf
,
'\0'
,
1024
);
...
...
@@ -21,7 +21,7 @@ main (void)
sin
.
sin_addr
.
s_addr
=
INADDR_ANY
;
sin
.
sin_port
=
0
;
udp_socket_manager_alloc_socket
(
&
man
,
&
sock
,
&
sin
);
nice_udp_socket_factory_make
(
&
man
,
&
sock
,
&
sin
);
/* test recv */
...
...
@@ -29,12 +29,12 @@ main (void)
len
=
5
;
sin
.
sin_addr
.
s_addr
=
htonl
(
0x01020304
);
sin
.
sin_port
=
htons
(
2345
);
udp_fake_socket_push_recv
(
&
sock
,
&
sin
,
len
,
buf
);
nice_
udp_fake_socket_push_recv
(
&
sock
,
&
sin
,
len
,
buf
);
memset
(
buf
,
'\0'
,
5
);
memset
(
&
sin
,
'\0'
,
sizeof
(
sin
));
len
=
udp_socket_recv
(
&
sock
,
&
sin
,
sizeof
(
buf
),
buf
);
len
=
nice_
udp_socket_recv
(
&
sock
,
&
sin
,
sizeof
(
buf
),
buf
);
g_assert
(
len
==
5
);
g_assert
(
memcmp
(
buf
,
"he
\0
lo"
,
5
)
==
0
);
g_assert
(
ntohl
(
sin
.
sin_addr
.
s_addr
)
==
0x01020304
);
...
...
@@ -44,19 +44,19 @@ main (void)
memcpy
(
buf
,
"la
\0
la"
,
5
);
len
=
5
;
udp_socket_send
(
&
sock
,
&
sin
,
len
,
buf
);
nice_
udp_socket_send
(
&
sock
,
&
sin
,
len
,
buf
);
memset
(
buf
,
'\0'
,
len
);
memset
(
&
sin
,
'\0'
,
sizeof
(
sin
));
len
=
udp_fake_socket_pop_send
(
&
sock
,
&
sin
,
sizeof
(
buf
),
buf
);
len
=
nice_
udp_fake_socket_pop_send
(
&
sock
,
&
sin
,
sizeof
(
buf
),
buf
);
g_assert
(
len
==
5
);
g_assert
(
0
==
memcmp
(
buf
,
"la
\0
la"
,
5
));
g_assert
(
ntohl
(
sin
.
sin_addr
.
s_addr
)
==
0x01020304
);
g_assert
(
ntohs
(
sin
.
sin_port
)
==
2345
);
udp_socket_close
(
&
sock
);
udp_socket_manager
_close
(
&
man
);
nice_
udp_socket_close
(
&
sock
);
nice_udp_socket_factory
_close
(
&
man
);
return
0
;
}
udp/udp-bsd.c
View file @
7e665bf9
...
...
@@ -8,11 +8,11 @@
#include "udp-bsd.h"
/*** UDPSocket ***/
/***
Nice
UDPSocket ***/
static
gint
socket_recv
(
UDPSocket
*
sock
,
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
from
,
guint
len
,
gchar
*
buf
)
...
...
@@ -28,7 +28,7 @@ socket_recv (
static
gboolean
socket_send
(
UDPSocket
*
sock
,
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
to
,
guint
len
,
gchar
*
buf
)
...
...
@@ -39,17 +39,17 @@ socket_send (
}
static
void
socket_close
(
UDPSocket
*
sock
)
socket_close
(
Nice
UDPSocket
*
sock
)
{
close
(
sock
->
fileno
);
}
/***
UDPSocketManager
***/
/***
NiceUDPSocketFactory
***/
static
gboolean
socket_
manager
_init_socket
(
UDPSocketManager
*
man
,
UDPSocket
*
sock
,
socket_
factory
_init_socket
(
NiceUDPSocketFactory
*
man
,
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
sin
)
{
gint
sockfd
;
...
...
@@ -81,21 +81,21 @@ socket_manager_init_socket (
}
static
void
socket_
manager_select
(
UDPPacket
RecvFunc
cb
)
socket_
factory_select
(
NiceUDP
RecvFunc
cb
)
{
g_assert_not_reached
();
}
static
void
socket_
manager_close
(
UDPSocketManager
*
man
)
socket_
factory_close
(
NiceUDPSocketFactory
*
man
)
{
}
void
udp_bsd_socket_manager_init
(
UDPSocketManager
*
man
)
nice_udp_bsd_socket_factory_init
(
NiceUDPSocketFactory
*
man
)
{
man
->
init
=
socket_
manager
_init_socket
;
man
->
select
=
socket_
manager
_select
;
man
->
close
=
socket_
manager
_close
;
man
->
init
=
socket_
factory
_init_socket
;
man
->
select
=
socket_
factory
_select
;
man
->
close
=
socket_
factory
_close
;
}
udp/udp-bsd.h
View file @
7e665bf9
...
...
@@ -7,7 +7,7 @@
G_BEGIN_DECLS
void
udp_bsd_socket_manager_init
(
UDPSocketManager
*
man
);
nice_udp_bsd_socket_factory_init
(
NiceUDPSocketFactory
*
man
);
G_END_DECLS
...
...
udp/udp-client.c
View file @
7e665bf9
...
...
@@ -7,13 +7,13 @@
gint
main
(
void
)
{
UDPSocketManager
man
;
UDPSocket
sock
;
NiceUDPSocketFactory
man
;
Nice
UDPSocket
sock
;
struct
sockaddr_in
sin
;
udp_bsd_socket_manager
_init
(
&
man
);
nice_udp_bsd_socket_factory
_init
(
&
man
);
if
(
!
udp_socket_manager_alloc_socket
(
&
man
,
&
sock
,
NULL
))
if
(
!
nice_udp_socket_factory_make
(
&
man
,
&
sock
,
NULL
))
g_assert_not_reached
();
if
(
inet_pton
(
AF_INET
,
"127.0.0.1"
,
&
(
sin
.
sin_addr
))
<
0
)
...
...
@@ -30,13 +30,13 @@ main (void)
if
(
fgets
(
buf
,
sizeof
(
buf
),
stdin
)
==
NULL
)
break
;
udp_socket_send
(
&
sock
,
&
sin
,
strlen
(
buf
),
buf
);
length
=
udp_socket_recv
(
&
sock
,
NULL
,
sizeof
(
buf
),
buf
);
nice_
udp_socket_send
(
&
sock
,
&
sin
,
strlen
(
buf
),
buf
);
length
=
nice_
udp_socket_recv
(
&
sock
,
NULL
,
sizeof
(
buf
),
buf
);
g_print
(
buf
);
}
udp_socket_close
(
&
sock
);
udp_socket_manager
_close
(
&
man
);
nice_
udp_socket_close
(
&
sock
);
nice_udp_socket_factory
_close
(
&
man
);
return
0
;
}
udp/udp-echo-server.c
View file @
7e665bf9
...
...
@@ -4,11 +4,11 @@
gint
main
(
void
)
{
UDPSocketManager
man
;
UDPSocket
sock
;
NiceUDPSocketFactory
man
;
Nice
UDPSocket
sock
;
struct
sockaddr_in
sin
;
udp_bsd_socket_manager
_init
(
&
man
);
nice_udp_bsd_socket_factory
_init
(
&
man
);
sin
.
sin_family
=
AF_INET
;
sin
.
sin_addr
.
s_addr
=
INADDR_ANY
;
sin
.
sin_port
=
htons
(
9999
);
...
...
udp/udp-fake.c
View file @
7e665bf9
...
...
@@ -44,7 +44,7 @@ _g_slist_pop (GSList **list)
static
gboolean
fake_send
(
UDPSocket
*
sock
,
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
to
,
guint
len
,
gchar
*
buf
)
...
...
@@ -65,7 +65,7 @@ fake_send (
static
gint
fake_recv
(
UDPSocket
*
sock
,
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
from
,
guint
len
,
gchar
*
buf
)
...
...
@@ -82,7 +82,7 @@ fake_recv (
}
static
void
fake_close
(
UDPSocket
*
sock
)
fake_close
(
Nice
UDPSocket
*
sock
)
{
UDPFakeSocketPriv
*
priv
;
...
...
@@ -95,8 +95,8 @@ fake_close (UDPSocket *sock)
/* XXX: copied INADDR_ANY to sock->addr rather than using a valid address */
static
gboolean
fake_socket_init
(
UDPSocketManager
*
man
,
UDPSocket
*
sock
,
NiceUDPSocketFactory
*
man
,
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
sin
)
{
int
fds
[
2
];
...
...
@@ -127,8 +127,8 @@ fake_socket_init (
}
void
udp_fake_socket_push_recv
(
UDPSocket
*
sock
,
nice_
udp_fake_socket_push_recv
(
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
from
,
guint
len
,
gchar
*
buf
)
...
...
@@ -142,8 +142,8 @@ udp_fake_socket_push_recv (
}
guint
udp_fake_socket_pop_send
(
UDPSocket
*
sock
,
nice_
udp_fake_socket_pop_send
(
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
to
,
guint
len
,
gchar
*
buf
)
...
...
@@ -165,16 +165,16 @@ udp_fake_socket_pop_send (
}
static
void
fake_socket_
manager_close
(
UDPSocketManager
*
man
)
fake_socket_
factory_close
(
NiceUDPSocketFactory
*
man
)
{
}
void
udp_fake_socket_manager_init
(
UDPSocketManager
*
man
)
nice_udp_fake_socket_factory_init
(
NiceUDPSocketFactory
*
man
)
{
man
->
init
=
fake_socket_init
;
man
->
select
=
NULL
;
man
->
close
=
fake_socket_
manager
_close
;
man
->
close
=
fake_socket_
factory
_close
;
man
->
priv
=
NULL
;
}
udp/udp-fake.h
View file @
7e665bf9
...
...
@@ -7,18 +7,18 @@
G_BEGIN_DECLS
void
udp_fake_socket_manager_init
(
UDPSocketManager
*
man
);
nice_udp_fake_socket_factory_init
(
NiceUDPSocketFactory
*
man
);
void
udp_fake_socket_push_recv
(
UDPSocket
*
man
,
nice_
udp_fake_socket_push_recv
(
Nice
UDPSocket
*
man
,
struct
sockaddr_in
*
from
,
guint
len
,
gchar
*
buf
);
guint
udp_fake_socket_pop_send
(
UDPSocket
*
man
,
nice_
udp_fake_socket_pop_send
(
Nice
UDPSocket
*
man
,
struct
sockaddr_in
*
to
,
guint
len
,
gchar
*
buf
);
...
...
udp/udp-generic.c
View file @
7e665bf9
...
...
@@ -6,23 +6,23 @@
#include <udp.h>
gboolean
udp_socket_manager_alloc_socket
(
UDPSocketManager
*
man
,
UDPSocket
*
sock
,
nice_udp_socket_factory_make
(
NiceUDPSocketFactory
*
man
,
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
sin
)
{
return
man
->
init
(
man
,
sock
,
sin
);
}
void
udp_socket_manager_close
(
UDPSocketManager
*
man
)
nice_udp_socket_factory_close
(
NiceUDPSocketFactory
*
man
)
{
man
->
close
(
man
);
}
guint
udp_socket_recv
(
UDPSocket
*
sock
,
nice_
udp_socket_recv
(
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
sin
,
guint
len
,
gchar
*
buf
)
...
...
@@ -31,8 +31,8 @@ udp_socket_recv (
}
void
udp_socket_send
(
UDPSocket
*
sock
,
nice_
udp_socket_send
(
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
sin
,
guint
len
,
gchar
*
buf
)
...
...
@@ -41,7 +41,7 @@ udp_socket_send (
}
void
udp_socket_close
(
UDPSocket
*
sock
)
nice_udp_socket_close
(
Nice
UDPSocket
*
sock
)
{
sock
->
close
(
sock
);
}
...
...
udp/udp.h
View file @
7e665bf9
...
...
@@ -8,31 +8,31 @@
G_BEGIN_DECLS
typedef
struct
_UDPSocket
UDPSocket
;
typedef
struct
_UDPSocket
Nice
UDPSocket
;
struct
_UDPSocket
{
struct
sockaddr_in
addr
;
guint
fileno
;
gint
(
*
recv
)
(
UDPSocket
*
sock
,
struct
sockaddr_in
*
from
,
guint
len
,
gint
(
*
recv
)
(
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
from
,
guint
len
,
gchar
*
buf
);
gboolean
(
*
send
)
(
UDPSocket
*
sock
,
struct
sockaddr_in
*
to
,
guint
len
,
gboolean
(
*
send
)
(
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
to
,
guint
len
,
gchar
*
buf
);
void
(
*
close
)
(
UDPSocket
*
sock
);
void
(
*
close
)
(
Nice
UDPSocket
*
sock
);
void
*
priv
;
};
typedef
gboolean
(
*
UDPPacket
RecvFunc
)
(
struct
sockaddr_in
*
from
,
guint
len
,
typedef
gboolean
(
*
NiceUDP
RecvFunc
)
(
struct
sockaddr_in
*
from
,
guint
len
,
gchar
*
buf
);
typedef
struct
_UDPSocketManager
UDPSocketManager
;
typedef
struct
_UDPSocketManager
NiceUDPSocketFactory
;
struct
_UDPSocketManager
{
gboolean
(
*
init
)
(
UDPSocketManager
*
man
,
UDPSocket
*
sock
,
gboolean
(
*
init
)
(
NiceUDPSocketFactory
*
man
,
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
sin
);
void
(
*
select
)
(
UDPPacket
RecvFunc
cb
);
void
(
*
close
)
(
UDPSocketManager
*
man
);
void
(
*
select
)
(
NiceUDP
RecvFunc
cb
);
void
(
*
close
)
(
NiceUDPSocketFactory
*
man
);
void
*
priv
;
};
...
...
@@ -42,30 +42,30 @@ struct _UDPSocketManager
* address bound to will be set in sock->addr.
*/
gboolean
udp_socket_manager_alloc_socket
(
UDPSocketManager
*
man
,
UDPSocket
*
sock
,
nice_udp_socket_factory_make
(
NiceUDPSocketFactory
*
man
,
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
sin
);
void
udp_socket_manager_close
(
UDPSocketManager
*
man
);
nice_udp_socket_factory_close
(
NiceUDPSocketFactory
*
man
);
guint
udp_socket_recv
(
UDPSocket
*
sock
,
nice_
udp_socket_recv
(
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
sin
,
guint
len
,
gchar
*
buf
);
void
udp_socket_send
(
UDPSocket
*
sock
,
nice_
udp_socket_send
(
Nice
UDPSocket
*
sock
,
struct
sockaddr_in
*
sin
,
guint
len
,
gchar
*
buf
);
void
udp_socket_close
(
UDPSocket
*
sock
);
nice_udp_socket_close
(
Nice
UDPSocket
*
sock
);
G_END_DECLS
...
...
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