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
78b29587
Commit
78b29587
authored
Mar 01, 2012
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tcp-bsd/udp-bsd coding style, add robustness and remove use of name_len
parent
c41021da
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
49 deletions
+35
-49
socket/tcp-bsd.c
socket/tcp-bsd.c
+21
-32
socket/udp-bsd.c
socket/udp-bsd.c
+14
-17
No files found.
socket/tcp-bsd.c
View file @
78b29587
...
...
@@ -87,12 +87,11 @@ NiceSocket *
nice_tcp_bsd_socket_new
(
GMainContext
*
ctx
,
NiceAddress
*
addr
)
{
struct
sockaddr_storage
name
;
socklen_t
name_len
=
sizeof
(
name
);
NiceSocket
*
sock
;
TcpPriv
*
priv
;
GSocket
*
gsock
=
NULL
;
GError
*
gerr
=
NULL
;
boolean
gret
;
gboolean
gret
=
FALSE
;
GSocketAddress
*
gaddr
;
if
(
addr
==
NULL
)
{
...
...
@@ -129,44 +128,34 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
}
/* GSocket: All socket file descriptors are set to be close-on-exec. */
g_socket_set_blocking
(
gsock
,
false
);
g_socket_set_blocking
(
gsock
,
false
);
gaddr
=
g_socket_address_new_from_native
(
&
name
,
sizeof
(
name
));
name_len
=
name
.
ss_family
==
AF_INET
?
sizeof
(
struct
sockaddr_in
)
:
sizeof
(
struct
sockaddr_in6
);
gaddr
=
g_socket_address_new_from_native
(
&
name
,
name_len
);
gret
=
g_socket_connect
(
gsock
,
gaddr
,
NULL
,
&
gerr
);
g_object_unref
(
gaddr
);
if
(
gaddr
!=
NULL
)
{
gret
=
g_socket_connect
(
gsock
,
gaddr
,
NULL
,
&
gerr
);
g_object_unref
(
gaddr
);
}
if
(
gret
==
FALSE
)
{
if
(
g_error_matches
(
gerr
,
G_IO_ERROR
,
G_IO_ERROR_PENDING
)
==
FALSE
)
{
g_socket_close
(
gsock
,
NULL
);
g_object_unref
(
gsock
);
if
(
gret
==
FALSE
)
{
if
(
g_error_matches
(
gerr
,
G_IO_ERROR
,
G_IO_ERROR_PENDING
)
==
FALSE
)
{
g_socket_close
(
gsock
,
NULL
);
g_object_unref
(
gsock
);
g_slice_free
(
NiceSocket
,
sock
);
return
NULL
;
}
g_error_free
(
gerr
);
}
gaddr
=
g_socket_get_local_address
(
gsock
,
NULL
);
if
(
gaddr
==
NULL
)
{
gaddr
=
g_socket_get_local_address
(
gsock
,
NULL
);
if
(
gaddr
==
NULL
||
!
g_socket_address_to_native
(
gaddr
,
&
name
,
sizeof
(
name
),
NULL
))
{
g_slice_free
(
NiceSocket
,
sock
);
g_socket_close
(
gsock
,
NULL
);
g_object_unref
(
gsock
);
return
NULL
;
}
name_len
=
name
.
ss_family
==
AF_INET
?
sizeof
(
struct
sockaddr_in
)
:
sizeof
(
struct
sockaddr_in6
);
g_socket_address_to_native
(
gaddr
,
&
name
,
name_len
,
NULL
);
g_object_unref
(
gaddr
);
g_object_unref
(
gaddr
);
nice_address_set_from_sockaddr
(
&
sock
->
addr
,
(
struct
sockaddr
*
)
&
name
);
...
...
socket/udp-bsd.c
View file @
78b29587
...
...
@@ -150,11 +150,9 @@ socket_close (NiceSocket *sock)
static
gint
socket_recv
(
NiceSocket
*
sock
,
NiceAddress
*
from
,
guint
len
,
gchar
*
buf
)
{
gint
recvd
;
struct
sockaddr_storage
sa
;
socklen_t
from_len
=
sizeof
(
sa
);
GSocketAddress
*
gaddr
=
NULL
;
GError
*
gerr
=
NULL
;
gint
recvd
;
recvd
=
g_socket_receive_from
(
sock
->
fileno
,
&
gaddr
,
buf
,
len
,
NULL
,
&
gerr
);
...
...
@@ -166,14 +164,16 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf)
g_error_free
(
gerr
);
}
if
(
recvd
>
0
)
{
if
(
gaddr
!=
NULL
)
{
g_socket_address_to_native
(
gaddr
,
&
sa
,
from_len
,
NULL
);
g_object_unref
(
gaddr
);
}
if
(
recvd
>
0
&&
from
!=
NULL
&&
gaddr
!=
NULL
)
{
struct
sockaddr_storage
sa
;
g_socket_address_to_native
(
gaddr
,
&
sa
,
sizeof
(
sa
),
NULL
);
nice_address_set_from_sockaddr
(
from
,
(
struct
sockaddr
*
)
&
sa
);
}
if
(
gaddr
!=
NULL
)
g_object_unref
(
gaddr
);
return
recvd
;
}
...
...
@@ -182,19 +182,16 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
guint
len
,
const
gchar
*
buf
)
{
struct
sockaddr_storage
sa
;
ssize_t
sent
;
socklen_t
name_len
=
sizeof
(
sa
);
GSocketAddress
*
gaddr
;
ssize_t
sent
=
-
1
;
nice_address_copy_to_sockaddr
(
to
,
(
struct
sockaddr
*
)
&
sa
);
gaddr
=
g_socket_address_new_from_native
(
&
sa
,
sizeof
(
sa
));
name_len
=
sa
.
ss_family
==
AF_INET
?
sizeof
(
struct
sockaddr_in
)
:
sizeof
(
struct
sockaddr_in6
);
gaddr
=
g_socket_address_new_from_native
(
&
sa
,
name_len
);
sent
=
g_socket_send_to
(
sock
->
fileno
,
gaddr
,
buf
,
len
,
NULL
,
NULL
);
g_object_unref
(
gaddr
);
if
(
gaddr
)
{
sent
=
g_socket_send_to
(
sock
->
fileno
,
gaddr
,
buf
,
len
,
NULL
,
NULL
);
g_object_unref
(
gaddr
);
}
return
sent
==
(
ssize_t
)
len
;
}
...
...
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