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
7f8ff6c2
Commit
7f8ff6c2
authored
Oct 07, 2008
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Much better NiceSocket API now, no more need for a socket factory
parent
8b6568da
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
173 deletions
+51
-173
socket/socket.c
socket/socket.c
+0
-48
socket/socket.h
socket/socket.h
+3
-33
socket/udp-bsd.c
socket/udp-bsd.c
+22
-38
socket/udp-bsd.h
socket/udp-bsd.h
+2
-2
socket/udp-turn.c
socket/udp-turn.c
+15
-39
socket/udp-turn.h
socket/udp-turn.h
+9
-13
No files found.
socket/socket.c
View file @
7f8ff6c2
...
@@ -43,56 +43,8 @@
...
@@ -43,56 +43,8 @@
#include <glib.h>
#include <glib.h>
#include "socket.h"
#include "socket.h"
#include "udp-bsd.h"
#include "udp-turn.h"
NICEAPI_EXPORT
NiceSocketFactory
*
nice_socket_factory_new
(
NiceSocketFactoryType
type
)
{
NiceSocketFactory
*
man
=
g_new0
(
NiceSocketFactory
,
1
);
if
(
man
)
{
switch
(
type
)
{
case
NICE_SOCKET_FACTORY_UDP_BSD
:
nice_udp_bsd_socket_factory_init
(
man
);
break
;
case
NICE_SOCKET_FACTORY_UDP_RELAY
:
nice_udp_turn_socket_factory_init
(
man
);
break
;
default:
g_free
(
man
);
man
=
NULL
;
}
}
return
man
;
}
NICEAPI_EXPORT
void
nice_socket_factory_free
(
NiceSocketFactory
*
man
)
{
if
(
man
)
{
man
->
close
(
man
);
g_free
(
man
);
}
}
NICEAPI_EXPORT
NiceSocket
*
nice_socket_new
(
NiceSocketFactory
*
man
,
NiceAddress
*
addr
)
{
NiceSocket
*
sock
=
g_slice_new0
(
NiceSocket
);
if
(
!
man
||
!
sock
||
!
man
->
init
(
man
,
sock
,
addr
))
{
g_free
(
sock
);
sock
=
NULL
;
}
return
sock
;
}
NICEAPI_EXPORT
gint
NICEAPI_EXPORT
gint
nice_socket_recv
(
nice_socket_recv
(
NiceSocket
*
sock
,
NiceSocket
*
sock
,
...
...
socket/socket.h
View file @
7f8ff6c2
...
@@ -56,39 +56,6 @@ struct _NiceSocket
...
@@ -56,39 +56,6 @@ struct _NiceSocket
void
*
priv
;
void
*
priv
;
};
};
typedef
struct
_NiceSocketFactory
NiceSocketFactory
;
struct
_NiceSocketFactory
{
gboolean
(
*
init
)
(
NiceSocketFactory
*
man
,
NiceSocket
*
sock
,
NiceAddress
*
sin
);
void
(
*
close
)
(
NiceSocketFactory
*
man
);
void
*
priv
;
};
typedef
enum
{
NICE_SOCKET_FACTORY_UDP_BSD
,
NICE_SOCKET_FACTORY_UDP_RELAY
,
}
NiceSocketFactoryType
;
G_GNUC_WARN_UNUSED_RESULT
NiceSocketFactory
*
nice_socket_factory_new
(
NiceSocketFactoryType
type
);
void
nice_socket_factory_free
(
NiceSocketFactory
*
man
);
/**
* If sin is not NULL, the new socket will be bound to that IP address/port.
* If sin->sin_port is 0, a port will be assigned at random. In all cases, the
* address bound to will be set in sock->addr.
*/
G_GNUC_WARN_UNUSED_RESULT
NiceSocket
*
nice_socket_new
(
NiceSocketFactory
*
man
,
NiceAddress
*
adddr
);
G_GNUC_WARN_UNUSED_RESULT
G_GNUC_WARN_UNUSED_RESULT
gint
gint
nice_socket_recv
(
nice_socket_recv
(
...
@@ -107,6 +74,9 @@ nice_socket_send (
...
@@ -107,6 +74,9 @@ nice_socket_send (
void
void
nice_socket_free
(
NiceSocket
*
sock
);
nice_socket_free
(
NiceSocket
*
sock
);
#include "udp-bsd.h"
#include "udp-turn.h"
G_END_DECLS
G_END_DECLS
#endif
/* _SOCKET_H */
#endif
/* _SOCKET_H */
...
...
socket/udp-bsd.c
View file @
7f8ff6c2
...
@@ -123,18 +123,17 @@ socket_close (NiceSocket *sock)
...
@@ -123,18 +123,17 @@ socket_close (NiceSocket *sock)
/*** NiceSocketFactory ***/
/*** NiceSocketFactory ***/
static
gboolean
NiceSocket
*
socket_factory_init_socket
(
nice_udp_bsd_socket_new
(
NiceAddress
*
addr
)
G_GNUC_UNUSED
NiceSocketFactory
*
man
,
NiceSocket
*
sock
,
NiceAddress
*
addr
)
{
{
int
sockfd
=
-
1
;
int
sockfd
=
-
1
;
struct
sockaddr_storage
name
;
struct
sockaddr_storage
name
;
guint
name_len
=
sizeof
(
name
);
guint
name_len
=
sizeof
(
name
);
NiceSocket
*
sock
=
g_slice_new0
(
NiceSocket
);
(
void
)
man
;
if
(
!
sock
)
{
return
NULL
;
}
if
(
addr
!=
NULL
)
if
(
addr
!=
NULL
)
{
{
...
@@ -187,8 +186,11 @@ socket_factory_init_socket (
...
@@ -187,8 +186,11 @@ socket_factory_init_socket (
#endif
#endif
}
}
if
(
sockfd
==
-
1
)
if
(
sockfd
==
-
1
)
{
return
FALSE
;
g_slice_free
(
NiceSocket
,
sock
);
return
NULL
;
}
#ifdef IP_RECVERR
#ifdef IP_RECVERR
else
else
{
{
...
@@ -204,16 +206,16 @@ socket_factory_init_socket (
...
@@ -204,16 +206,16 @@ socket_factory_init_socket (
fcntl
(
sockfd
,
F_SETFL
,
fcntl
(
sockfd
,
F_GETFL
)
|
O_NONBLOCK
);
fcntl
(
sockfd
,
F_SETFL
,
fcntl
(
sockfd
,
F_GETFL
)
|
O_NONBLOCK
);
#endif
#endif
if
(
bind
(
sockfd
,
(
struct
sockaddr
*
)
&
name
,
sizeof
(
name
))
!=
0
)
if
(
bind
(
sockfd
,
(
struct
sockaddr
*
)
&
name
,
sizeof
(
name
))
!=
0
)
{
{
g_slice_free
(
NiceSocket
,
sock
);
close
(
sockfd
);
close
(
sockfd
);
return
FALSE
;
return
NULL
;
}
}
if
(
getsockname
(
sockfd
,
(
struct
sockaddr
*
)
&
name
,
&
name_len
)
!=
0
)
if
(
getsockname
(
sockfd
,
(
struct
sockaddr
*
)
&
name
,
&
name_len
)
!=
0
)
{
{
g_slice_free
(
NiceSocket
,
sock
);
close
(
sockfd
);
close
(
sockfd
);
return
FALSE
;
return
NULL
;
}
}
nice_address_set_from_sockaddr
(
&
sock
->
addr
,
(
struct
sockaddr
*
)
&
name
);
nice_address_set_from_sockaddr
(
&
sock
->
addr
,
(
struct
sockaddr
*
)
&
name
);
...
@@ -222,23 +224,5 @@ socket_factory_init_socket (
...
@@ -222,23 +224,5 @@ socket_factory_init_socket (
sock
->
send
=
socket_send
;
sock
->
send
=
socket_send
;
sock
->
recv
=
socket_recv
;
sock
->
recv
=
socket_recv
;
sock
->
close
=
socket_close
;
sock
->
close
=
socket_close
;
return
TRUE
;
return
sock
;
}
}
static
void
socket_factory_close
(
G_GNUC_UNUSED
NiceSocketFactory
*
man
)
{
(
void
)
man
;
}
NICEAPI_EXPORT
void
nice_udp_bsd_socket_factory_init
(
G_GNUC_UNUSED
NiceSocketFactory
*
man
)
{
man
->
init
=
socket_factory_init_socket
;
man
->
close
=
socket_factory_close
;
}
socket/udp-bsd.h
View file @
7f8ff6c2
...
@@ -42,8 +42,8 @@
...
@@ -42,8 +42,8 @@
G_BEGIN_DECLS
G_BEGIN_DECLS
void
NiceSocket
*
nice_udp_bsd_socket_
factory_init
(
NiceSocketFactory
*
man
);
nice_udp_bsd_socket_
new
(
NiceAddress
*
addr
);
G_END_DECLS
G_END_DECLS
...
...
socket/udp-turn.c
View file @
7f8ff6c2
...
@@ -488,27 +488,22 @@ socket_close (NiceSocket *sock)
...
@@ -488,27 +488,22 @@ socket_close (NiceSocket *sock)
/*** NiceSocketFactory ***/
/*** NiceSocketFactory ***/
static
gboolean
NICEAPI_EXPORT
NiceSocket
*
socket_factory_init_socket
(
nice_udp_turn_socket_new
(
NiceSocketFactory
*
man
,
NiceSocket
*
sock
,
NiceAddress
*
addr
)
{
return
FALSE
;
}
NICEAPI_EXPORT
gboolean
nice_udp_turn_create_socket_full
(
NiceSocketFactory
*
man
,
NiceSocket
*
sock
,
NiceAddress
*
addr
,
NiceAddress
*
addr
,
NiceSocket
*
base_socket
,
NiceSocket
*
base_socket
,
NiceAddress
*
server_addr
,
NiceAddress
*
server_addr
,
gchar
*
username
,
gchar
*
username
,
gchar
*
password
,
gchar
*
password
,
NiceUdpTurnSocketCompatibility
compatibility
)
NiceUdpTurnSocketCompatibility
compatibility
,
GStaticRecMutex
*
mutex
)
{
{
turn_priv
*
priv
=
g_new0
(
turn_priv
,
1
);
turn_priv
*
priv
=
g_new0
(
turn_priv
,
1
);
NiceSocket
*
sock
=
g_slice_new0
(
NiceSocket
);
if
(
!
sock
)
{
return
NULL
;
}
if
(
compatibility
==
NICE_UDP_TURN_SOCKET_COMPATIBILITY_DRAFT9
)
{
if
(
compatibility
==
NICE_UDP_TURN_SOCKET_COMPATIBILITY_DRAFT9
)
{
stun_agent_init
(
&
priv
->
agent
,
STUN_ALL_KNOWN_ATTRIBUTES
,
stun_agent_init
(
&
priv
->
agent
,
STUN_ALL_KNOWN_ATTRIBUTES
,
...
@@ -552,24 +547,5 @@ nice_udp_turn_create_socket_full (
...
@@ -552,24 +547,5 @@ nice_udp_turn_create_socket_full (
sock
->
recv
=
socket_recv
;
sock
->
recv
=
socket_recv
;
sock
->
close
=
socket_close
;
sock
->
close
=
socket_close
;
sock
->
priv
=
(
void
*
)
priv
;
sock
->
priv
=
(
void
*
)
priv
;
return
TRUE
;
return
sock
;
}
}
static
void
socket_factory_close
(
G_GNUC_UNUSED
NiceSocketFactory
*
man
)
{
}
NICEAPI_EXPORT
void
nice_udp_turn_socket_factory_init
(
G_GNUC_UNUSED
NiceSocketFactory
*
man
)
{
man
->
init
=
socket_factory_init_socket
;
man
->
close
=
socket_factory_close
;
}
socket/udp-turn.h
View file @
7f8ff6c2
...
@@ -61,20 +61,16 @@ nice_udp_turn_socket_parse_recv (
...
@@ -61,20 +61,16 @@ nice_udp_turn_socket_parse_recv (
gboolean
gboolean
nice_udp_turn_socket_set_peer
(
NiceSocket
*
sock
,
NiceAddress
*
peer
);
nice_udp_turn_socket_set_peer
(
NiceSocket
*
sock
,
NiceAddress
*
peer
);
gboolean
NiceSocket
*
nice_udp_turn_create_socket_full
(
nice_udp_turn_socket_new
(
NiceSocketFactory
*
man
,
NiceSocket
*
sock
,
NiceAddress
*
addr
,
NiceAddress
*
addr
,
NiceSocket
*
udp_socket
,
NiceSocket
*
udp_socket
,
NiceAddress
*
server_addr
,
NiceAddress
*
server_addr
,
gchar
*
username
,
gchar
*
username
,
gchar
*
password
,
gchar
*
password
,
NiceUdpTurnSocketCompatibility
compatibility
);
NiceUdpTurnSocketCompatibility
compatibility
,
GStaticRecMutex
*
mutex
);
void
nice_udp_turn_socket_factory_init
(
NiceSocketFactory
*
man
);
G_END_DECLS
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