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
a972e826
Commit
a972e826
authored
Oct 06, 2008
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new NiceSocket API
parent
4459912b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
40 deletions
+85
-40
socket/socket.c
socket/socket.c
+52
-15
socket/socket.h
socket/socket.h
+33
-25
No files found.
socket/socket.c
View file @
a972e826
...
...
@@ -42,26 +42,60 @@
#include <glib.h>
#include <udp.h>
#include "socket.h"
#include "udp-bsd.h"
#include "udp-turn.h"
NICEAPI_EXPORT
gboolean
nice_udp_socket_factory_make
(
NiceUDPSocketFactory
*
man
,
NiceUDPSocket
*
sock
,
NiceAddress
*
addr
)
NICEAPI_EXPORT
NiceSocketFactory
*
nice_socket_factory_new
(
NiceSocketFactoryType
type
)
{
return
man
->
init
(
man
,
sock
,
addr
);
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_udp_socket_factory_close
(
NiceUDPSocketFactory
*
man
)
nice_socket_factory_free
(
NiceSocketFactory
*
man
)
{
if
(
man
)
{
man
->
close
(
man
);
g_free
(
man
);
}
}
NICEAPI_EXPORT
NiceSocket
*
nice_socket_new
(
NiceSocketFactory
*
man
,
NiceAddress
*
addr
)
{
man
->
close
(
man
);
NiceSocket
*
sock
=
g_slice_new0
(
NiceSocket
);
if
(
!
man
||
!
sock
||
!
man
->
init
(
man
,
sock
,
addr
))
{
g_free
(
sock
);
sock
=
NULL
;
}
return
sock
;
}
NICEAPI_EXPORT
gint
nice_
udp_
socket_recv
(
Nice
UDP
Socket
*
sock
,
nice_socket_recv
(
NiceSocket
*
sock
,
NiceAddress
*
from
,
guint
len
,
gchar
*
buf
)
...
...
@@ -70,8 +104,8 @@ nice_udp_socket_recv (
}
NICEAPI_EXPORT
void
nice_
udp_
socket_send
(
Nice
UDP
Socket
*
sock
,
nice_socket_send
(
NiceSocket
*
sock
,
const
NiceAddress
*
to
,
guint
len
,
const
gchar
*
buf
)
...
...
@@ -80,8 +114,11 @@ nice_udp_socket_send (
}
NICEAPI_EXPORT
void
nice_
udp_socket_close
(
NiceUDP
Socket
*
sock
)
nice_
socket_free
(
Nice
Socket
*
sock
)
{
sock
->
close
(
sock
);
if
(
sock
)
{
sock
->
close
(
sock
);
g_slice_free
(
NiceSocket
,
sock
);
}
}
socket/socket.h
View file @
a972e826
...
...
@@ -35,71 +35,79 @@
* file under either the MPL or the LGPL.
*/
#ifndef _
UDP
_H
#define _
UDP
_H
#ifndef _
SOCKET
_H
#define _
SOCKET
_H
#include "address.h"
G_BEGIN_DECLS
typedef
struct
_Nice
UDPSocket
NiceUDP
Socket
;
typedef
struct
_Nice
Socket
Nice
Socket
;
struct
_Nice
UDP
Socket
struct
_NiceSocket
{
NiceAddress
addr
;
guint
fileno
;
gint
(
*
recv
)
(
Nice
UDP
Socket
*
sock
,
NiceAddress
*
from
,
guint
len
,
gint
(
*
recv
)
(
NiceSocket
*
sock
,
NiceAddress
*
from
,
guint
len
,
gchar
*
buf
);
gboolean
(
*
send
)
(
Nice
UDP
Socket
*
sock
,
const
NiceAddress
*
to
,
guint
len
,
gboolean
(
*
send
)
(
NiceSocket
*
sock
,
const
NiceAddress
*
to
,
guint
len
,
const
gchar
*
buf
);
void
(
*
close
)
(
Nice
UDP
Socket
*
sock
);
void
(
*
close
)
(
NiceSocket
*
sock
);
void
*
priv
;
};
typedef
struct
_Nice
UDPSocketManager
NiceUDP
SocketFactory
;
typedef
struct
_Nice
SocketFactory
Nice
SocketFactory
;
struct
_Nice
UDPSocketManager
struct
_Nice
SocketFactory
{
gboolean
(
*
init
)
(
Nice
UDPSocketFactory
*
man
,
NiceUDP
Socket
*
sock
,
gboolean
(
*
init
)
(
Nice
SocketFactory
*
man
,
Nice
Socket
*
sock
,
NiceAddress
*
sin
);
void
(
*
close
)
(
Nice
UDP
SocketFactory
*
man
);
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
gboolean
nice_udp_socket_factory_make
(
NiceUDPSocketFactory
*
man
,
NiceUDPSocket
*
sock
,
NiceAddress
*
addr
);
void
nice_udp_socket_factory_close
(
NiceUDPSocketFactory
*
man
);
NiceSocket
*
nice_socket_new
(
NiceSocketFactory
*
man
,
NiceAddress
*
adddr
);
G_GNUC_WARN_UNUSED_RESULT
gint
nice_
udp_
socket_recv
(
Nice
UDP
Socket
*
sock
,
nice_socket_recv
(
NiceSocket
*
sock
,
NiceAddress
*
from
,
guint
len
,
gchar
*
buf
);
void
nice_
udp_
socket_send
(
Nice
UDP
Socket
*
sock
,
nice_socket_send
(
NiceSocket
*
sock
,
const
NiceAddress
*
to
,
guint
len
,
const
gchar
*
buf
);
void
nice_
udp_socket_close
(
NiceUDP
Socket
*
sock
);
nice_
socket_free
(
Nice
Socket
*
sock
);
G_END_DECLS
#endif
/* _
UDP
_H */
#endif
/* _
SOCKET
_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