mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-21 09:10:36 +00:00
I *think* this is the last list in chan_iax2
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@43802 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -360,7 +360,7 @@ struct iax2_peer {
|
|||||||
|
|
||||||
#define IAX2_TRUNK_PREFACE (sizeof(struct iax_frame) + sizeof(struct ast_iax2_meta_hdr) + sizeof(struct ast_iax2_meta_trunk_hdr))
|
#define IAX2_TRUNK_PREFACE (sizeof(struct iax_frame) + sizeof(struct ast_iax2_meta_hdr) + sizeof(struct ast_iax2_meta_trunk_hdr))
|
||||||
|
|
||||||
static struct iax2_trunk_peer {
|
struct iax2_trunk_peer {
|
||||||
ast_mutex_t lock;
|
ast_mutex_t lock;
|
||||||
int sockfd;
|
int sockfd;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
@@ -373,12 +373,12 @@ static struct iax2_trunk_peer {
|
|||||||
unsigned char *trunkdata;
|
unsigned char *trunkdata;
|
||||||
unsigned int trunkdatalen;
|
unsigned int trunkdatalen;
|
||||||
unsigned int trunkdataalloc;
|
unsigned int trunkdataalloc;
|
||||||
struct iax2_trunk_peer *next;
|
|
||||||
int trunkerror;
|
int trunkerror;
|
||||||
int calls;
|
int calls;
|
||||||
} *tpeers = NULL;
|
AST_LIST_ENTRY(iax2_trunk_peer) list;
|
||||||
|
};
|
||||||
|
|
||||||
AST_MUTEX_DEFINE_STATIC(tpeerlock);
|
static AST_LIST_HEAD_STATIC(tpeers, iax2_trunk_peer);
|
||||||
|
|
||||||
struct iax_firmware {
|
struct iax_firmware {
|
||||||
AST_LIST_ENTRY(iax_firmware) list;
|
AST_LIST_ENTRY(iax_firmware) list;
|
||||||
@@ -3484,17 +3484,18 @@ static unsigned int calc_rxstamp(struct chan_iax2_pvt *p, unsigned int offset)
|
|||||||
|
|
||||||
static struct iax2_trunk_peer *find_tpeer(struct sockaddr_in *sin, int fd)
|
static struct iax2_trunk_peer *find_tpeer(struct sockaddr_in *sin, int fd)
|
||||||
{
|
{
|
||||||
struct iax2_trunk_peer *tpeer;
|
struct iax2_trunk_peer *tpeer = NULL;
|
||||||
|
|
||||||
/* Finds and locks trunk peer */
|
/* Finds and locks trunk peer */
|
||||||
ast_mutex_lock(&tpeerlock);
|
AST_LIST_LOCK(&tpeers);
|
||||||
for (tpeer = tpeers; tpeer; tpeer = tpeer->next) {
|
|
||||||
/* We don't lock here because tpeer->addr *never* changes */
|
AST_LIST_TRAVERSE(&tpeers, tpeer, list) {
|
||||||
if (!inaddrcmp(&tpeer->addr, sin)) {
|
if (!inaddrcmp(&tpeer->addr, sin)) {
|
||||||
ast_mutex_lock(&tpeer->lock);
|
ast_mutex_lock(&tpeer->lock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tpeer) {
|
if (!tpeer) {
|
||||||
if ((tpeer = ast_calloc(1, sizeof(*tpeer)))) {
|
if ((tpeer = ast_calloc(1, sizeof(*tpeer)))) {
|
||||||
ast_mutex_init(&tpeer->lock);
|
ast_mutex_init(&tpeer->lock);
|
||||||
@@ -3502,16 +3503,17 @@ static struct iax2_trunk_peer *find_tpeer(struct sockaddr_in *sin, int fd)
|
|||||||
memcpy(&tpeer->addr, sin, sizeof(tpeer->addr));
|
memcpy(&tpeer->addr, sin, sizeof(tpeer->addr));
|
||||||
tpeer->trunkact = ast_tvnow();
|
tpeer->trunkact = ast_tvnow();
|
||||||
ast_mutex_lock(&tpeer->lock);
|
ast_mutex_lock(&tpeer->lock);
|
||||||
tpeer->next = tpeers;
|
|
||||||
tpeer->sockfd = fd;
|
tpeer->sockfd = fd;
|
||||||
tpeers = tpeer;
|
|
||||||
#ifdef SO_NO_CHECK
|
#ifdef SO_NO_CHECK
|
||||||
setsockopt(tpeer->sockfd, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
|
setsockopt(tpeer->sockfd, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));
|
||||||
#endif
|
#endif
|
||||||
ast_log(LOG_DEBUG, "Created trunk peer for '%s:%d'\n", ast_inet_ntoa(tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port));
|
ast_log(LOG_DEBUG, "Created trunk peer for '%s:%d'\n", ast_inet_ntoa(tpeer->addr.sin_addr), ntohs(tpeer->addr.sin_port));
|
||||||
|
AST_LIST_INSERT_TAIL(&tpeers, tpeer, list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&tpeerlock);
|
|
||||||
|
AST_LIST_UNLOCK(&tpeers);
|
||||||
|
|
||||||
return tpeer;
|
return tpeer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5887,10 +5889,8 @@ static inline int iax2_trunk_expired(struct iax2_trunk_peer *tpeer, struct timev
|
|||||||
static int timing_read(int *id, int fd, short events, void *cbdata)
|
static int timing_read(int *id, int fd, short events, void *cbdata)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int res;
|
int res, processed = 0, totalcalls = 0;
|
||||||
struct iax2_trunk_peer *tpeer, *prev = NULL, *drop=NULL;
|
struct iax2_trunk_peer *tpeer = NULL, *drop = NULL;
|
||||||
int processed = 0;
|
|
||||||
int totalcalls = 0;
|
|
||||||
#ifdef ZT_TIMERACK
|
#ifdef ZT_TIMERACK
|
||||||
int x = 1;
|
int x = 1;
|
||||||
#endif
|
#endif
|
||||||
@@ -5914,9 +5914,8 @@ static int timing_read(int *id, int fd, short events, void *cbdata)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* For each peer that supports trunking... */
|
/* For each peer that supports trunking... */
|
||||||
ast_mutex_lock(&tpeerlock);
|
AST_LIST_LOCK(&tpeers);
|
||||||
tpeer = tpeers;
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&tpeers, tpeer, list) {
|
||||||
while(tpeer) {
|
|
||||||
processed++;
|
processed++;
|
||||||
res = 0;
|
res = 0;
|
||||||
ast_mutex_lock(&tpeer->lock);
|
ast_mutex_lock(&tpeer->lock);
|
||||||
@@ -5925,10 +5924,7 @@ static int timing_read(int *id, int fd, short events, void *cbdata)
|
|||||||
if (!drop && iax2_trunk_expired(tpeer, &now)) {
|
if (!drop && iax2_trunk_expired(tpeer, &now)) {
|
||||||
/* Take it out of the list, but don't free it yet, because it
|
/* Take it out of the list, but don't free it yet, because it
|
||||||
could be in use */
|
could be in use */
|
||||||
if (prev)
|
AST_LIST_REMOVE_CURRENT(&tpeers, list);
|
||||||
prev->next = tpeer->next;
|
|
||||||
else
|
|
||||||
tpeers = tpeer->next;
|
|
||||||
drop = tpeer;
|
drop = tpeer;
|
||||||
} else {
|
} else {
|
||||||
res = send_trunk(tpeer, &now);
|
res = send_trunk(tpeer, &now);
|
||||||
@@ -5938,10 +5934,10 @@ static int timing_read(int *id, int fd, short events, void *cbdata)
|
|||||||
totalcalls += res;
|
totalcalls += res;
|
||||||
res = 0;
|
res = 0;
|
||||||
ast_mutex_unlock(&tpeer->lock);
|
ast_mutex_unlock(&tpeer->lock);
|
||||||
prev = tpeer;
|
|
||||||
tpeer = tpeer->next;
|
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&tpeerlock);
|
AST_LIST_TRAVERSE_SAFE_END
|
||||||
|
AST_LIST_UNLOCK(&tpeers);
|
||||||
|
|
||||||
if (drop) {
|
if (drop) {
|
||||||
ast_mutex_lock(&drop->lock);
|
ast_mutex_lock(&drop->lock);
|
||||||
/* Once we have this lock, we're sure nobody else is using it or could use it once we release it,
|
/* Once we have this lock, we're sure nobody else is using it or could use it once we release it,
|
||||||
@@ -5953,9 +5949,11 @@ static int timing_read(int *id, int fd, short events, void *cbdata)
|
|||||||
free(drop);
|
free(drop);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iaxtrunkdebug)
|
if (iaxtrunkdebug)
|
||||||
ast_verbose("Ending trunk processing with %d peers and %d call chunks processed\n", processed, totalcalls);
|
ast_verbose("Ending trunk processing with %d peers and %d call chunks processed\n", processed, totalcalls);
|
||||||
iaxtrunkdebug =0;
|
iaxtrunkdebug = 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user