Browse Source

TT#52651 move socket.[ch] into lib/

includes necessary re-shuffling of additional code pieces

Change-Id: I74b314ab5936ac8a0eeaff94e084617b59b28d79
changes/28/27228/5
Richard Fuchs 7 years ago
parent
commit
06d61cd3dd
13 changed files with 83 additions and 66 deletions
  1. +1
    -0
      daemon/.gitignore
  2. +2
    -2
      daemon/Makefile
  3. +0
    -33
      daemon/aux.c
  4. +7
    -0
      daemon/log.h
  5. +0
    -20
      include/aux.h
  6. +0
    -6
      include/call.h
  7. +1
    -0
      include/tcp_listener.h
  8. +36
    -0
      lib/auxlib.c
  9. +29
    -0
      lib/auxlib.h
  10. +1
    -2
      lib/socket.c
  11. +3
    -1
      lib/socket.h
  12. +2
    -2
      t/Makefile
  13. +1
    -0
      t/log.h

+ 1
- 0
daemon/.gitignore View File

@ -11,3 +11,4 @@ codeclib.c
resample.c
str.c
fix_frame_channel_layout.h
socket.c

+ 2
- 2
daemon/Makefile View File

@ -121,10 +121,10 @@ endif
SRCS= main.c kernel.c poller.c aux.c control_tcp.c streambuf.c call.c control_udp.c redis.c \
bencode.c cookie_cache.c udp_listener.c control_ng.strhash.c sdp.strhash.c stun.c rtcp.c \
crypto.c rtp.c call_interfaces.strhash.c dtls.c log.c cli.c graphite.c ice.c socket.c \
crypto.c rtp.c call_interfaces.strhash.c dtls.c log.c cli.c graphite.c ice.c \
media_socket.c homer.c recording.c statistics.c cdr.c ssrc.c iptables.c tcp_listener.c \
codec.c load.c dtmf.c
LIBSRCS= loglib.c auxlib.c rtplib.c str.c
LIBSRCS= loglib.c auxlib.c rtplib.c str.c socket.c
ifeq ($(with_transcoding),yes)
LIBSRCS+= codeclib.c resample.c
endif


+ 0
- 33
daemon/aux.c View File

@ -27,9 +27,6 @@ struct detach_thread {
const char *scheduler;
int priority;
};
struct thread_buf {
char buf[THREAD_BUF_SIZE];
};
struct scheduler {
const char *name;
int num;
@ -42,9 +39,6 @@ static GList *threads_to_join;
static GList *threads_running;
static cond_t threads_cond = COND_STATIC_INIT;
static struct thread_buf __thread t_bufs[NUM_THREAD_BUFS];
static int __thread t_buf_idx;
__thread struct timeval rtpe_now;
volatile int rtpe_shutdown;
@ -249,25 +243,6 @@ void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler
abort();
}
unsigned int in6_addr_hash(const void *p) {
const struct in6_addr *a = p;
return a->s6_addr32[0] ^ a->s6_addr32[3];
}
int in6_addr_eq(const void *a, const void *b) {
const struct in6_addr *A = a, *B = b;
return !memcmp(A, B, sizeof(*A));
}
char *get_thread_buf(void) {
char *ret;
ret = t_bufs[t_buf_idx].buf;
t_buf_idx++;
if (t_buf_idx >= G_N_ELEMENTS(t_bufs))
t_buf_idx = 0;
return ret;
}
int g_tree_find_first_cmp(void *k, void *v, void *d) {
void **p = d;
GEqualFunc f = p[1];
@ -285,14 +260,6 @@ int g_tree_find_all_cmp(void *k, void *v, void *d) {
g_queue_push_tail(q, v);
return FALSE;
}
unsigned int uint32_hash(const void *p) {
const u_int32_t *a = p;
return *a;
}
int uint32_eq(const void *a, const void *b) {
const u_int32_t *A = a, *B = b;
return (*A == *B) ? TRUE : FALSE;
}
void free_buf(char **p) {
if (*p)


+ 7
- 0
daemon/log.h View File

@ -48,5 +48,12 @@ void dtmflog(GString *s);
void log_format(enum log_format);
void __ilog(int prio, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
// call debug
#ifdef __DEBUG
#define __C_DBG(x...) ilog(LOG_DEBUG, x)
#else
#define __C_DBG(x...) ((void)0)
#endif
#endif

+ 0
- 20
include/aux.h View File

@ -49,21 +49,6 @@ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
/*** HELPER MACROS ***/
#define ZERO(x) memset(&(x), 0, sizeof(x))
#define UINT64F "%" G_GUINT64_FORMAT
#define THREAD_BUF_SIZE 64
#define NUM_THREAD_BUFS 8
#define AUTO_CLEANUP(decl, func) decl __attribute__ ((__cleanup__(func)))
#define AUTO_CLEANUP_INIT(decl, func, val) AUTO_CLEANUP(decl, func) = val
#define AUTO_CLEANUP_NULL(decl, func) AUTO_CLEANUP_INIT(decl, func, 0)
#define AUTO_CLEANUP_BUF(var) AUTO_CLEANUP_NULL(char *var, free_buf)
/*** GLOBALS ***/
extern __thread struct timeval rtpe_now;
@ -79,11 +64,6 @@ typedef int (*parse_func)(char **, void **, void *);
int pcre_multi_match(pcre *, pcre_extra *, const char *, unsigned int, parse_func, void *, GQueue *);
INLINE void strmove(char **, char **);
INLINE void strdupfree(char **, const char *);
char *get_thread_buf(void);
unsigned int in6_addr_hash(const void *p);
int in6_addr_eq(const void *a, const void *b);
unsigned int uint32_hash(const void *p);
int uint32_eq(const void *a, const void *b);


+ 0
- 6
include/call.h View File

@ -90,12 +90,6 @@ enum call_type {
#define RTP_LOOP_MAX_COUNT 30 /* number of consecutively detected dupes to trigger protection */
#endif
#ifdef __DEBUG
#define __C_DBG(x...) ilog(LOG_DEBUG, x)
#else
#define __C_DBG(x...) ((void)0)
#endif
#define IS_FOREIGN_CALL(c) (c->foreign_call)
#define IS_OWN_CALL(c) !IS_FOREIGN_CALL(c)


+ 1
- 0
include/tcp_listener.h View File

@ -3,6 +3,7 @@
#include "socket.h"
#include "obj.h"
#include "aux.h"
struct poller;


+ 36
- 0
lib/auxlib.c View File

@ -10,13 +10,21 @@
#ifdef HAVE_LIBSYSTEMD
#include <systemd/sd-daemon.h>
#endif
#include <sys/socket.h>
#include <netinet/in.h>
#include "log.h"
#include "loglib.h"
struct thread_buf {
char buf[THREAD_BUF_SIZE];
};
static int version;
struct rtpengine_common_config *rtpe_common_config_ptr;
static struct thread_buf __thread t_bufs[NUM_THREAD_BUFS];
static int __thread t_buf_idx;
void daemonize(void) {
if (rtpe_common_config_ptr->foreground)
@ -200,3 +208,31 @@ out:
err:
die("Bad command line: %s", er->message);
}
char *get_thread_buf(void) {
char *ret;
ret = t_bufs[t_buf_idx].buf;
t_buf_idx++;
if (t_buf_idx >= G_N_ELEMENTS(t_bufs))
t_buf_idx = 0;
return ret;
}
unsigned int in6_addr_hash(const void *p) {
const struct in6_addr *a = p;
return a->s6_addr32[0] ^ a->s6_addr32[3];
}
int in6_addr_eq(const void *a, const void *b) {
const struct in6_addr *A = a, *B = b;
return !memcmp(A, B, sizeof(*A));
}
unsigned int uint32_hash(const void *p) {
const u_int32_t *a = p;
return *a;
}
int uint32_eq(const void *a, const void *b) {
const u_int32_t *A = a, *B = b;
return (*A == *B) ? TRUE : FALSE;
}

+ 29
- 0
lib/auxlib.h View File

@ -6,6 +6,11 @@
#include "compat.h"
#include <openssl/rand.h>
#define THREAD_BUF_SIZE 64
#define NUM_THREAD_BUFS 8
struct rtpengine_common_config {
char *config_file;
char *config_section;
@ -18,6 +23,8 @@ struct rtpengine_common_config {
extern struct rtpengine_common_config *rtpe_common_config_ptr;
/*** PROTOTYPES ***/
void daemonize(void);
void wpidfile(void);
void service_notify(const char *message);
@ -25,6 +32,28 @@ void config_load(int *argc, char ***argv, GOptionEntry *entries, const char *des
char *default_config, char *default_section,
struct rtpengine_common_config *);
char *get_thread_buf(void);
unsigned int in6_addr_hash(const void *p);
int in6_addr_eq(const void *a, const void *b);
unsigned int uint32_hash(const void *p);
int uint32_eq(const void *a, const void *b);
/*** HELPER MACROS ***/
#define ZERO(x) memset(&(x), 0, sizeof(x))
#define UINT64F "%" G_GUINT64_FORMAT
#define AUTO_CLEANUP(decl, func) decl __attribute__ ((__cleanup__(func)))
#define AUTO_CLEANUP_INIT(decl, func, val) AUTO_CLEANUP(decl, func) = val
#define AUTO_CLEANUP_NULL(decl, func) AUTO_CLEANUP_INIT(decl, func, 0)
#define AUTO_CLEANUP_BUF(var) AUTO_CLEANUP_NULL(char *var, free_buf)
/*** STRING HELPERS ***/
INLINE void random_string(unsigned char *buf, int len) {
int ret = RAND_bytes(buf, len);
assert(ret == 1);


daemon/socket.c → lib/socket.c View File


include/socket.h → lib/socket.h View File


+ 2
- 2
t/Makefile View File

@ -62,8 +62,8 @@ SRCS+= transcode-test.c
ifeq ($(with_amr_tests),yes)
SRCS+= amr-decode-test.c amr-encode-test.c
endif
LIBSRCS+= codeclib.c resample.c
DAEMONSRCS+= codec.c call.c ice.c kernel.c media_socket.c stun.c bencode.c socket.c poller.c \
LIBSRCS+= codeclib.c resample.c socket.c
DAEMONSRCS+= codec.c call.c ice.c kernel.c media_socket.c stun.c bencode.c poller.c \
dtls.c recording.c statistics.c rtcp.c redis.c iptables.c graphite.c \
streambuf.c cookie_cache.c udp_listener.c homer.c load.c cdr.c dtmf.c
HASHSRCS+= call_interfaces.c control_ng.c sdp.c


+ 1
- 0
t/log.h View File

@ -3,6 +3,7 @@
#include "loglib.h"
#define __ilog(prio, fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
#define __C_DBG(x...) ilog(LOG_DEBUG, x)
INLINE void rtcplog(const char *x) {
}


Loading…
Cancel
Save