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
a9ce3510
Commit
a9ce3510
authored
Apr 10, 2014
by
Youness Alaoui
Committed by
Olivier Crête
May 15, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor tcp-bsd to ease integration of tcp-act/tcp-passive
parent
ee3c8082
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
26 deletions
+42
-26
socket/tcp-bsd.c
socket/tcp-bsd.c
+38
-26
socket/tcp-bsd.h
socket/tcp-bsd.h
+4
-0
No files found.
socket/tcp-bsd.c
View file @
a9ce3510
...
@@ -55,7 +55,7 @@
...
@@ -55,7 +55,7 @@
#endif
#endif
typedef
struct
{
typedef
struct
{
NiceAddress
server
_addr
;
NiceAddress
remote
_addr
;
GQueue
send_queue
;
GQueue
send_queue
;
GMainContext
*
context
;
GMainContext
*
context
;
GSource
*
io_source
;
GSource
*
io_source
;
...
@@ -77,6 +77,37 @@ static gboolean socket_is_reliable (NiceSocket *sock);
...
@@ -77,6 +77,37 @@ static gboolean socket_is_reliable (NiceSocket *sock);
static
gboolean
socket_send_more
(
GSocket
*
gsocket
,
GIOCondition
condition
,
static
gboolean
socket_send_more
(
GSocket
*
gsocket
,
GIOCondition
condition
,
gpointer
data
);
gpointer
data
);
NiceSocket
*
nice_tcp_bsd_socket_new_from_gsock
(
GMainContext
*
ctx
,
GSocket
*
gsock
,
NiceAddress
*
local_addr
,
NiceAddress
*
remote_addr
,
gboolean
reliable
)
{
NiceSocket
*
sock
;
TcpPriv
*
priv
;
g_return_val_if_fail
(
G_IS_SOCKET
(
gsock
),
NULL
);
sock
=
g_slice_new0
(
NiceSocket
);
sock
->
priv
=
priv
=
g_slice_new0
(
TcpPriv
);
if
(
ctx
==
NULL
)
ctx
=
g_main_context_default
();
priv
->
context
=
g_main_context_ref
(
ctx
);
priv
->
remote_addr
=
*
remote_addr
;
priv
->
error
=
FALSE
;
priv
->
reliable
=
reliable
;
sock
->
type
=
NICE_SOCKET_TYPE_TCP_BSD
;
sock
->
fileno
=
g_object_ref
(
gsock
);
sock
->
addr
=
*
local_addr
;
sock
->
send_messages
=
socket_send_messages
;
sock
->
send_messages_reliable
=
socket_send_messages_reliable
;
sock
->
recv_messages
=
socket_recv_messages
;
sock
->
is_reliable
=
socket_is_reliable
;
sock
->
close
=
socket_close
;
return
sock
;
}
NiceSocket
*
NiceSocket
*
nice_tcp_bsd_socket_new
(
GMainContext
*
ctx
,
NiceAddress
*
addr
,
gboolean
reliable
)
nice_tcp_bsd_socket_new
(
GMainContext
*
ctx
,
NiceAddress
*
addr
,
gboolean
reliable
)
{
{
...
@@ -85,19 +116,17 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr, gboolean reliable
...
@@ -85,19 +116,17 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr, gboolean reliable
struct
sockaddr
addr
;
struct
sockaddr
addr
;
}
name
;
}
name
;
NiceSocket
*
sock
;
NiceSocket
*
sock
;
TcpPriv
*
priv
;
GSocket
*
gsock
=
NULL
;
GSocket
*
gsock
=
NULL
;
GError
*
gerr
=
NULL
;
GError
*
gerr
=
NULL
;
gboolean
gret
=
FALSE
;
gboolean
gret
=
FALSE
;
GSocketAddress
*
gaddr
;
GSocketAddress
*
gaddr
;
NiceAddress
local_addr
;
if
(
addr
==
NULL
)
{
if
(
addr
==
NULL
)
{
/* We can't connect a tcp socket with no destination address */
/* We can't connect a tcp socket with no destination address */
return
NULL
;
return
NULL
;
}
}
sock
=
g_slice_new0
(
NiceSocket
);
nice_address_copy_to_sockaddr
(
addr
,
&
name
.
addr
);
nice_address_copy_to_sockaddr
(
addr
,
&
name
.
addr
);
if
(
name
.
storage
.
ss_family
==
AF_UNSPEC
||
name
.
storage
.
ss_family
==
AF_INET
)
{
if
(
name
.
storage
.
ss_family
==
AF_UNSPEC
||
name
.
storage
.
ss_family
==
AF_INET
)
{
...
@@ -118,14 +147,12 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr, gboolean reliable
...
@@ -118,14 +147,12 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr, gboolean reliable
}
}
if
(
gsock
==
NULL
)
{
if
(
gsock
==
NULL
)
{
g_slice_free
(
NiceSocket
,
sock
);
return
NULL
;
return
NULL
;
}
}
gaddr
=
g_socket_address_new_from_native
(
&
name
.
addr
,
sizeof
(
name
));
gaddr
=
g_socket_address_new_from_native
(
&
name
.
addr
,
sizeof
(
name
));
if
(
gaddr
==
NULL
)
{
if
(
gaddr
==
NULL
)
{
g_object_unref
(
gsock
);
g_object_unref
(
gsock
);
g_slice_free
(
NiceSocket
,
sock
);
return
NULL
;
return
NULL
;
}
}
...
@@ -140,7 +167,6 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr, gboolean reliable
...
@@ -140,7 +167,6 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr, gboolean reliable
g_error_free
(
gerr
);
g_error_free
(
gerr
);
g_socket_close
(
gsock
,
NULL
);
g_socket_close
(
gsock
,
NULL
);
g_object_unref
(
gsock
);
g_object_unref
(
gsock
);
g_slice_free
(
NiceSocket
,
sock
);
return
NULL
;
return
NULL
;
}
}
g_error_free
(
gerr
);
g_error_free
(
gerr
);
...
@@ -149,31 +175,17 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr, gboolean reliable
...
@@ -149,31 +175,17 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr, gboolean reliable
gaddr
=
g_socket_get_local_address
(
gsock
,
NULL
);
gaddr
=
g_socket_get_local_address
(
gsock
,
NULL
);
if
(
gaddr
==
NULL
||
if
(
gaddr
==
NULL
||
!
g_socket_address_to_native
(
gaddr
,
&
name
.
addr
,
sizeof
(
name
),
NULL
))
{
!
g_socket_address_to_native
(
gaddr
,
&
name
.
addr
,
sizeof
(
name
),
NULL
))
{
g_slice_free
(
NiceSocket
,
sock
);
g_socket_close
(
gsock
,
NULL
);
g_socket_close
(
gsock
,
NULL
);
g_object_unref
(
gsock
);
g_object_unref
(
gsock
);
return
NULL
;
return
NULL
;
}
}
g_object_unref
(
gaddr
);
g_object_unref
(
gaddr
);
nice_address_set_from_sockaddr
(
&
sock
->
addr
,
&
name
.
addr
);
nice_address_set_from_sockaddr
(
&
local_addr
,
&
name
.
addr
);
sock
->
priv
=
priv
=
g_slice_new0
(
TcpPriv
);
if
(
ctx
==
NULL
)
sock
=
nice_tcp_bsd_socket_new_from_gsock
(
ctx
,
gsock
,
&
local_addr
,
addr
,
ctx
=
g_main_context_default
();
reliable
);
priv
->
context
=
g_main_context_ref
(
ctx
);
g_object_unref
(
gsock
);
priv
->
server_addr
=
*
addr
;
priv
->
error
=
FALSE
;
priv
->
reliable
=
reliable
;
sock
->
type
=
NICE_SOCKET_TYPE_TCP_BSD
;
sock
->
fileno
=
gsock
;
sock
->
send_messages
=
socket_send_messages
;
sock
->
send_messages_reliable
=
socket_send_messages_reliable
;
sock
->
recv_messages
=
socket_recv_messages
;
sock
->
is_reliable
=
socket_is_reliable
;
sock
->
close
=
socket_close
;
return
sock
;
return
sock
;
}
}
...
@@ -240,7 +252,7 @@ socket_recv_messages (NiceSocket *sock,
...
@@ -240,7 +252,7 @@ socket_recv_messages (NiceSocket *sock,
}
}
if
(
recv_messages
[
i
].
from
)
if
(
recv_messages
[
i
].
from
)
*
recv_messages
[
i
].
from
=
priv
->
server
_addr
;
*
recv_messages
[
i
].
from
=
priv
->
remote
_addr
;
if
(
len
<=
0
)
if
(
len
<=
0
)
break
;
break
;
...
...
socket/tcp-bsd.h
View file @
a9ce3510
...
@@ -45,6 +45,10 @@ G_BEGIN_DECLS
...
@@ -45,6 +45,10 @@ G_BEGIN_DECLS
NiceSocket
*
NiceSocket
*
nice_tcp_bsd_socket_new
(
GMainContext
*
ctx
,
NiceAddress
*
addr
,
gboolean
reliable
);
nice_tcp_bsd_socket_new
(
GMainContext
*
ctx
,
NiceAddress
*
addr
,
gboolean
reliable
);
NiceSocket
*
nice_tcp_bsd_socket_new_from_gsock
(
GMainContext
*
ctx
,
GSocket
*
gsock
,
NiceAddress
*
local_addr
,
NiceAddress
*
remote_addr
,
gboolean
reliable
);
G_END_DECLS
G_END_DECLS
#endif
/* _TCP_BSD_H */
#endif
/* _TCP_BSD_H */
...
...
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