Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
belle-sip
Commits
e25a3bdc
Commit
e25a3bdc
authored
Jan 18, 2013
by
Simon Morlat
Browse files
work in progress
parent
0571004c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
189 additions
and
63 deletions
+189
-63
src/Makefile.am
src/Makefile.am
+1
-0
src/belle_sip_internal.h
src/belle_sip_internal.h
+2
-55
src/belle_sip_resolver.c
src/belle_sip_resolver.c
+17
-4
src/belle_sip_resolver.h
src/belle_sip_resolver.h
+5
-4
src/port.c
src/port.c
+55
-0
src/port.h
src/port.h
+109
-0
No files found.
src/Makefile.am
View file @
e25a3bdc
...
...
@@ -29,6 +29,7 @@ lib_LTLIBRARIES=libbellesip.la
libbellesip_la_SOURCES
=
\
clock_gettime.c clock_gettime.h
\
port.c port.h
\
belle_sip_uri_impl.c
\
belle_sip_headers_impl.c
\
belle_sip_utils.c belle_sip_internal.h
\
...
...
src/belle_sip_internal.h
View file @
e25a3bdc
...
...
@@ -24,28 +24,11 @@
#include <sys/types.h>
#include <errno.h>
#ifndef WIN32
#include <stdint.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <pthread.h>
#else
#include <ws2tcpip.h>
#include <winsock2.h>
#include <pthread.h>
#endif
/* include all public headers*/
#include "belle-sip/belle-sip.h"
#include "port.h"
#ifdef PACKAGE
#undef PACKAGE
#endif
...
...
@@ -72,42 +55,6 @@
#include "config.h"
#endif
#if defined(WIN32) || defined(WIN32_WCE)
static
inline
void
close_socket
(
belle_sip_socket_t
s
){
closesocket
(
s
);
}
static
inline
int
get_socket_error
(
void
){
return
WSAGetLastError
();
}
const
char
*
getSocketErrorString
();
#define belle_sip_get_socket_error_string() getSocketErrorString()
#define belle_sip_get_socket_error_string_from_code(code) getSocketErrorString()
#define usleep(us) Sleep((us)/1000)
static
inline
int
inet_aton
(
const
char
*
ip
,
struct
in_addr
*
p
){
*
(
long
*
)
p
=
inet_addr
(
ip
);
return
0
;
}
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEINPROGRESS
#else
static
inline
void
close_socket
(
belle_sip_socket_t
s
){
close
(
s
);
}
static
inline
int
get_socket_error
(
void
){
return
errno
;
}
#define belle_sip_get_socket_error_string() strerror(errno)
#define belle_sip_get_socket_error_string_from_code(code) strerror(code)
#endif
/*etc*/
#define BELLE_SIP_INTERFACE_GET_METHODS(obj,interface) \
...
...
src/belle_sip_resolver.c
View file @
e25a3bdc
...
...
@@ -51,17 +51,21 @@ void belle_sip_resolver_context_destroy(belle_sip_resolver_context_t *ctx){
if
(
ctx
->
thread
!=
0
){
if
(
!
ctx
->
exited
){
ctx
->
cancelled
=
1
;
p
thread_cancel
(
ctx
->
thread
);
belle_sip_
thread_cancel
(
ctx
->
thread
);
}
p
thread_join
(
ctx
->
thread
,
NULL
);
belle_sip_
thread_join
(
ctx
->
thread
,
NULL
);
}
if
(
ctx
->
name
)
belle_sip_free
(
ctx
->
name
);
if
(
ctx
->
ai
){
freeaddrinfo
(
ctx
->
ai
);
}
#ifndef WIN32
close
(
ctx
->
ctlpipe
[
0
]);
close
(
ctx
->
ctlpipe
[
1
]);
#else
CloseEvent
(
ctx
->
ctlevent
);
#endif
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES
(
belle_sip_resolver_context_t
);
...
...
@@ -71,17 +75,23 @@ static int resolver_callback(belle_sip_resolver_context_t *ctx){
char
tmp
;
ctx
->
cb
(
ctx
->
cb_data
,
ctx
->
name
,
ctx
->
ai
);
ctx
->
ai
=
NULL
;
#ifndef WIN32
if
(
read
(
ctx
->
source
.
fd
,
&
tmp
,
1
)
!=
1
){
belle_sip_fatal
(
"Unexpected read from resolver_callback"
);
}
#else
#endif
return
BELLE_SIP_STOP
;
}
belle_sip_resolver_context_t
*
belle_sip_resolver_context_new
(){
belle_sip_resolver_context_t
*
ctx
=
belle_sip_object_new
(
belle_sip_resolver_context_t
);
#ifndef WIN32
if
(
pipe
(
ctx
->
ctlpipe
)
==-
1
){
belle_sip_fatal
(
"pipe() failed: %s"
,
strerror
(
errno
));
}
#else
#endif
belle_sip_fd_source_init
(
&
ctx
->
source
,(
belle_sip_source_func_t
)
resolver_callback
,
ctx
,
ctx
->
ctlpipe
[
0
],
BELLE_SIP_EVENT_READ
,
-
1
);
return
ctx
;
}
...
...
@@ -106,10 +116,13 @@ static void *belle_sip_resolver_thread(void *ptr){
belle_sip_message
(
"%s has address %s."
,
ctx
->
name
,
host
);
ctx
->
ai
=
res
;
}
#ifndef WIN32
if
(
write
(
ctx
->
ctlpipe
[
1
],
"q"
,
1
)
==-
1
){
belle_sip_error
(
"belle_sip_resolver_thread(): Fail to write on pipe."
);
}
#else
SetEvent
(
ctx
->
ctlevent
);
#endif
return
NULL
;
}
...
...
@@ -125,7 +138,7 @@ unsigned long belle_sip_resolve(const char *name, int port, unsigned int hints,
ctx
->
hints
=
hints
;
belle_sip_main_loop_add_source
(
ml
,(
belle_sip_source_t
*
)
ctx
);
belle_sip_object_unref
(
ctx
);
p
thread_create
(
&
ctx
->
thread
,
NULL
,
belle_sip_resolver_thread
,
ctx
);
belle_sip_
thread_create
(
&
ctx
->
thread
,
NULL
,
belle_sip_resolver_thread
,
ctx
);
return
ctx
->
source
.
id
;
}
else
{
cb
(
data
,
name
,
res
);
...
...
src/belle_sip_resolver.h
View file @
e25a3bdc
...
...
@@ -22,9 +22,6 @@
#include "belle_sip_internal.h"
#define BELLE_SIP_RESOLVER_HINT_IPV6 (1)
#define BELLE_SIP_RESOLVER_HINT_SRV (1<<1)
typedef
struct
belle_sip_resolver_context
belle_sip_resolver_context_t
;
...
...
@@ -43,8 +40,12 @@ struct belle_sip_resolver_context{
int
port
;
struct
addrinfo
*
ai
;
unsigned
int
hints
;
pthread_t
thread
;
belle_sip_thread_t
thread
;
#ifndef WIN32
int
ctlpipe
[
2
];
#else
HANDLE
ctlevent
;
#endif
uint8_t
cancelled
;
uint8_t
exited
;
};
...
...
src/port.c
0 → 100644
View file @
e25a3bdc
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belle_sip_internal.h"
#ifdef WIN32
typedef
struct
thread_param
{
void
*
(
*
func
)(
void
*
);
void
*
arg
;
}
thread_param_t
;
static
unsigned
WINAPI
thread_starter
(
void
*
data
){
thread_param_t
*
params
=
(
thread_param_t
*
)
data
;
void
*
ret
=
params
->
func
(
params
->
arg
);
belle_sip_free
(
data
);
return
(
DWORD
)
ret
;
}
int
belle_sip_thread_create
(
belle_sip_thread_t
*
th
,
void
*
attr
,
void
*
(
*
func
)(
void
*
),
void
*
data
)
{
thread_param_t
*
params
=
belle_sip_new
(
thread_param_t
);
params
->
func
=
func
;
params
->
arg
=
data
;
*
th
=
(
HANDLE
)
_beginthreadex
(
NULL
,
0
,
thread_starter
,
params
,
0
,
NULL
);
return
0
;
}
int
belle_sip_thread_join
(
belle_sip_thread_t
thread_h
,
void
**
unused
)
{
if
(
thread_h
!=
NULL
)
{
WaitForSingleObject
(
thread_h
,
INFINITE
);
CloseHandle
(
thread_h
);
}
return
0
;
}
#endif
src/port.h
0 → 100644
View file @
e25a3bdc
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef belle_sip_port_h
#define belle_sip_port_h
#ifndef WIN32
#include <stdint.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <pthread.h>
#else
#include <ws2tcpip.h>
#include <winsock2.h>
/*AI_NUMERICSERV is not defined for windows XP. Since it is not essential, we define it to 0 (does nothing)*/
#ifndef AI_NUMERICSERV
#define AI_NUMERICSERV 0
#endif
#endif
/*
* Socket abstraction layer
*/
#if defined(WIN32)
static
inline
void
close_socket
(
belle_sip_socket_t
s
){
closesocket
(
s
);
}
static
inline
int
get_socket_error
(
void
){
return
WSAGetLastError
();
}
const
char
*
getSocketErrorString
();
#define belle_sip_get_socket_error_string() getSocketErrorString()
#define belle_sip_get_socket_error_string_from_code(code) getSocketErrorString()
#define usleep(us) Sleep((us)/1000)
static
inline
int
inet_aton
(
const
char
*
ip
,
struct
in_addr
*
p
){
*
(
long
*
)
p
=
inet_addr
(
ip
);
return
0
;
}
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEINPROGRESS
#else
static
inline
void
close_socket
(
belle_sip_socket_t
s
){
close
(
s
);
}
static
inline
int
get_socket_error
(
void
){
return
errno
;
}
#define belle_sip_get_socket_error_string() strerror(errno)
#define belle_sip_get_socket_error_string_from_code(code) strerror(code)
#endif
/*
* Thread abstraction layer
*/
#ifdef WIN32
typedef
HANDLE
belle_sip_thread_t
;
int
belle_sip_thread_join
(
belle_sip_thread_t
thread
,
void
**
retptr
);
int
belle_sip_thread_create
(
belle_sip_thread_t
*
thread
,
void
*
attr
,
void
*
(
*
routine
)(
void
*
),
void
*
arg
);
#else
#include <pthread.h>
typedef
pthread_t
belle_sip_thread_t
;
#define belle_sip_thread_join(thread,retptr) pthread_join(thread,retptr)
#define belle_sip_thread_create(thread,attr,routine,arg) pthread_create(thread,attr,routine,arg)
#endif
#endif
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