Browse Source

convert some macros to inline functions

git.mgm/mediaproxy-ng/2.0
Richard Fuchs 14 years ago
parent
commit
61967c1d32
4 changed files with 35 additions and 20 deletions
  1. +21
    -6
      daemon/aux.h
  2. +9
    -9
      daemon/call.c
  3. +3
    -3
      daemon/control.c
  4. +2
    -2
      daemon/control_udp.c

+ 21
- 6
daemon/aux.h View File

@ -35,13 +35,7 @@
#define D6F IP6F ":%u"
#define D6P(x) IP6P((x).sin6_addr.s6_addr), ntohs((x).sin6_port)
#define NONBLOCK(x) fcntl(x, F_SETFL, O_NONBLOCK)
#define REUSEADDR(x) do { int ONE = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &ONE, sizeof(ONE)); } while (0)
#define BIT_ARRAY_DECLARE(name, size) int name[((size) + sizeof(int) * 8 - 1) / (sizeof(int) * 8)]
#define BIT_ARRAY_SET(name, bit) name[(bit) / (sizeof(int) * 8)] |= 1 << ((bit) % (sizeof(int) * 8))
#define BIT_ARRAY_CLEAR(name, bit) name[(bit) / (sizeof(int) * 8)] &= ~(1 << ((bit) % (sizeof(int) * 8)))
#define BIT_ARRAY_ISSET(name, bit) (name[(bit) / (sizeof(int) * 8)] & (1 << ((bit) % (sizeof(int) * 8))))
@ -62,6 +56,27 @@ void g_queue_clear(GQueue *);
#endif
static inline void nonblock(int fd) {
fcntl(fd, F_SETFL, O_NONBLOCK);
}
static inline void reuseaddr(int fd) {
int one = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
}
static inline int bit_array_isset(int *name, unsigned int bit) {
return name[(bit) / (sizeof(int) * 8)] & (1 << ((bit) % (sizeof(int) * 8)));
}
static inline void bit_array_set(int *name, unsigned int bit) {
name[(bit) / (sizeof(int) * 8)] |= 1 << ((bit) % (sizeof(int) * 8));
}
static inline void bit_array_clear(int *name, unsigned int bit) {
name[(bit) / (sizeof(int) * 8)] &= ~(1 << ((bit) % (sizeof(int) * 8)));
}
static inline void uuid_str_generate(char *s) {
uuid_t uuid;
uuid_generate(uuid);


+ 9
- 9
daemon/call.c View File

@ -571,8 +571,8 @@ static int get_port4(struct streamrelay *r, u_int16_t p) {
if (fd < 0)
return -1;
NONBLOCK(fd);
REUSEADDR(fd);
nonblock(fd);
reuseaddr(fd);
setsockopt(fd, IPPROTO_IP, IP_TOS, &r->up->up->call->callmaster->tos, sizeof(r->up->up->call->callmaster->tos));
ZERO(sin);
@ -599,8 +599,8 @@ static int get_port6(struct streamrelay *r, u_int16_t p) {
if (fd < 0)
return -1;
NONBLOCK(fd);
REUSEADDR(fd);
nonblock(fd);
reuseaddr(fd);
setsockopt(fd, IPPROTO_IP, IP_TOS, &r->up->up->call->callmaster->tos, sizeof(r->up->up->call->callmaster->tos));
i = 1;
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &i, sizeof(i));
@ -623,7 +623,7 @@ fail:
static int get_port(struct streamrelay *r, u_int16_t p, int family) {
int ret;
if (BIT_ARRAY_ISSET(ports_used, p))
if (bit_array_isset(ports_used, p))
return -1;
switch (family) {
@ -710,8 +710,8 @@ next:
mylog(LOG_DEBUG, "[%s] Opened ports %u/%u for RTP", c->callid, a->localport, b->localport);
reserve:
BIT_ARRAY_SET(ports_used, a->localport);
BIT_ARRAY_SET(ports_used, b->localport);
bit_array_set(ports_used, a->localport);
bit_array_set(ports_used, b->localport);
return;
@ -791,7 +791,7 @@ static void steal_peer(struct peer *dest, struct peer *src) {
if (sr->fd != -1) {
mylog(LOG_DEBUG, "[%s] Closing port %u in favor of re-use", c->callid, sr->localport);
close(sr->fd);
BIT_ARRAY_CLEAR(ports_used, sr->localport);
bit_array_clear(ports_used, sr->localport);
poller_del_item(po, sr->fd);
}
@ -1094,7 +1094,7 @@ static void kill_callstream(struct callstream *s) {
if (r->fd != -1) {
close(r->fd);
BIT_ARRAY_CLEAR(ports_used, r->localport);
bit_array_clear(ports_used, r->localport);
}
poller_del_item(s->call->callmaster->poller, r->fd);
}


+ 3
- 3
daemon/control.c View File

@ -163,7 +163,7 @@ static void control_incoming(int fd, void *p) {
nfd = accept(fd, (struct sockaddr *) &sin, &sinl);
if (nfd == -1)
return;
NONBLOCK(nfd);
nonblock(nfd);
mylog(LOG_INFO, "New control connection from " DF, DP(sin));
@ -211,8 +211,8 @@ struct control *control_new(struct poller *p, u_int32_t ip, u_int16_t port, stru
if (fd == -1)
return NULL;
NONBLOCK(fd);
REUSEADDR(fd);
nonblock(fd);
reuseaddr(fd);
ZERO(sin);
sin.sin_family = AF_INET;


+ 2
- 2
daemon/control_udp.c View File

@ -173,8 +173,8 @@ struct control_udp *control_udp_new(struct poller *p, u_int32_t ip, u_int16_t po
if (fd == -1)
return NULL;
NONBLOCK(fd);
REUSEADDR(fd);
nonblock(fd);
reuseaddr(fd);
ZERO(sin);
sin.sin_family = AF_INET;


Loading…
Cancel
Save