本文整理汇总了C++中pj_grp_lock_acquire函数的典型用法代码示例。如果您正苦于以下问题:C++ pj_grp_lock_acquire函数的具体用法?C++ pj_grp_lock_acquire怎么用?C++ pj_grp_lock_acquire使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_grp_lock_acquire函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: on_sess_timer
/* Timer callback */
static void on_sess_timer(pj_timer_heap_t *th,
pj_timer_entry *te)
{
nat_detect_session *sess;
sess = (nat_detect_session*) te->user_data;
if (te->id == TIMER_DESTROY) {
pj_grp_lock_acquire(sess->grp_lock);
pj_ioqueue_unregister(sess->key);
sess->key = NULL;
sess->sock = PJ_INVALID_SOCKET;
te->id = 0;
pj_grp_lock_release(sess->grp_lock);
sess_destroy(sess);
} else if (te->id == TIMER_TEST) {
pj_bool_t next_timer;
pj_grp_lock_acquire(sess->grp_lock);
next_timer = PJ_FALSE;
if (sess->timer_executed == 0) {
send_test(sess, ST_TEST_1, NULL, 0);
next_timer = PJ_TRUE;
} else if (sess->timer_executed == 1) {
send_test(sess, ST_TEST_2, NULL, CHANGE_IP_PORT_FLAG);
next_timer = PJ_TRUE;
} else if (sess->timer_executed == 2) {
send_test(sess, ST_TEST_3, NULL, CHANGE_PORT_FLAG);
} else {
pj_assert(!"Shouldn't have timer at this state");
}
++sess->timer_executed;
if (next_timer) {
pj_time_val delay = {0, TEST_INTERVAL};
pj_timer_heap_schedule(th, te, &delay);
} else {
te->id = 0;
}
pj_grp_lock_release(sess->grp_lock);
} else {
pj_assert(!"Invalid timer ID");
}
}
开发者ID:zndxlx,项目名称:pjsip_r,代码行数:53,代码来源:nat_detect.c
示例2: stun_tsx_on_send_msg
static pj_status_t stun_tsx_on_send_msg(pj_stun_client_tsx *tsx,
const void *stun_pkt,
pj_size_t pkt_size)
{
pj_stun_tx_data *tdata;
pj_stun_session *sess;
pj_status_t status;
tdata = (pj_stun_tx_data*) pj_stun_client_tsx_get_data(tsx);
sess = tdata->sess;
/* Lock the session and prevent user from destroying us in the callback */
pj_grp_lock_acquire(sess->grp_lock);
if (sess->is_destroying) {
/* Stray timer */
pj_grp_lock_release(sess->grp_lock);
return PJ_EINVALIDOP;
}
status = sess->cb.on_send_msg(tdata->sess, tdata->token, stun_pkt,
pkt_size, tdata->dst_addr,
tdata->addr_len);
if (pj_grp_lock_release(sess->grp_lock))
return PJ_EGONE;
return status;
}
开发者ID:Archipov,项目名称:android-client,代码行数:28,代码来源:stun_session.c
示例3: PJ_DEF
PJ_DEF(pj_status_t) pj_ioqueue_lock_key(pj_ioqueue_key_t *key)
{
if (key->grp_lock)
return pj_grp_lock_acquire(key->grp_lock);
else
return pj_lock_acquire(key->lock);
}
开发者ID:iamroger,项目名称:voip,代码行数:7,代码来源:ioqueue_common_abs.c
示例4: PJ_DEF
/* Send application data */
PJ_DEF(pj_status_t) pj_stun_sock_sendto( pj_stun_sock *stun_sock,
pj_ioqueue_op_key_t *send_key,
const void *pkt,
unsigned pkt_len,
unsigned flag,
const pj_sockaddr_t *dst_addr,
unsigned addr_len)
{
pj_ssize_t size;
pj_status_t status;
PJ_ASSERT_RETURN(stun_sock && pkt && dst_addr && addr_len, PJ_EINVAL);
pj_grp_lock_acquire(stun_sock->grp_lock);
if (!stun_sock->active_sock) {
/* We have been shutdown, but this callback may still get called
* by retransmit timer.
*/
pj_grp_lock_release(stun_sock->grp_lock);
return PJ_EINVALIDOP;
}
if (send_key==NULL)
send_key = &stun_sock->send_key;
size = pkt_len;
status = pj_activesock_sendto(stun_sock->active_sock, send_key,
pkt, &size, flag, dst_addr, addr_len);
pj_grp_lock_release(stun_sock->grp_lock);
return status;
}
开发者ID:AmoebaLabs,项目名称:pjsip,代码行数:34,代码来源:stun_sock.c
示例5: dns_srv_resolver_cb
/* DNS resolver callback */
static void dns_srv_resolver_cb(void *user_data,
pj_status_t status,
const pj_dns_srv_record *rec)
{
pj_stun_sock *stun_sock = (pj_stun_sock*) user_data;
pj_grp_lock_acquire(stun_sock->grp_lock);
/* Clear query */
stun_sock->q = NULL;
/* Handle error */
if (status != PJ_SUCCESS) {
sess_fail(stun_sock, PJ_STUN_SOCK_DNS_OP, status);
pj_grp_lock_release(stun_sock->grp_lock);
return;
}
pj_assert(rec->count);
pj_assert(rec->entry[0].server.addr_count);
PJ_TODO(SUPPORT_IPV6_IN_RESOLVER);
pj_assert(stun_sock->af == pj_AF_INET());
/* Set the address */
pj_sockaddr_in_init(&stun_sock->srv_addr.ipv4, NULL,
rec->entry[0].port);
stun_sock->srv_addr.ipv4.sin_addr = rec->entry[0].server.addr[0];
/* Start sending Binding request */
get_mapped_addr(stun_sock);
pj_grp_lock_release(stun_sock->grp_lock);
}
开发者ID:AmoebaLabs,项目名称:pjsip,代码行数:35,代码来源:stun_sock.c
示例6: PJ_DEF
PJ_DEF(pj_status_t) pj_stun_client_tsx_schedule_destroy(
pj_stun_client_tsx *tsx,
const pj_time_val *delay)
{
pj_status_t status;
PJ_ASSERT_RETURN(tsx && delay, PJ_EINVAL);
PJ_ASSERT_RETURN(tsx->cb.on_destroy, PJ_EINVAL);
pj_grp_lock_acquire(tsx->grp_lock);
/* Cancel previously registered timer */
pj_timer_heap_cancel_if_active(tsx->timer_heap, &tsx->destroy_timer,
TIMER_INACTIVE);
/* Stop retransmission, just in case */
pj_timer_heap_cancel_if_active(tsx->timer_heap, &tsx->retransmit_timer,
TIMER_INACTIVE);
status = pj_timer_heap_schedule_w_grp_lock(tsx->timer_heap,
&tsx->destroy_timer, delay,
TIMER_ACTIVE, tsx->grp_lock);
if (status != PJ_SUCCESS) {
pj_grp_lock_release(tsx->grp_lock);
return status;
}
tsx->cb.on_complete = NULL;
pj_grp_lock_release(tsx->grp_lock);
TRACE_((tsx->obj_name, "STUN transaction %p schedule destroy", tsx));
return PJ_SUCCESS;
}
开发者ID:jhcloos,项目名称:pjproject,代码行数:35,代码来源:stun_transaction.c
示例7: PJ_DEF
PJ_DEF(pj_status_t) pj_stun_session_set_user_data( pj_stun_session *sess,
void *user_data)
{
PJ_ASSERT_RETURN(sess, PJ_EINVAL);
pj_grp_lock_acquire(sess->grp_lock);
sess->user_data = user_data;
pj_grp_lock_release(sess->grp_lock);
return PJ_SUCCESS;
}
开发者ID:Archipov,项目名称:android-client,代码行数:9,代码来源:stun_session.c
示例8: PJ_DEF
/* Send application data */
PJ_DEF(pj_status_t) pj_stun_sock_sendto( pj_stun_sock *stun_sock,
pj_ioqueue_op_key_t *send_key,
const void *pkt,
unsigned pkt_len,
unsigned flag,
const pj_sockaddr_t *dst_addr,
unsigned addr_len)
{
pj_ssize_t size;
pj_status_t status;
pj_bool_t is_stun = PJ_FALSE;
pj_bool_t is_tnl_data = PJ_FALSE;
PJ_ASSERT_RETURN(stun_sock && pkt && dst_addr && addr_len, PJ_EINVAL);
pj_grp_lock_acquire(stun_sock->grp_lock);
if (!stun_sock->active_sock) {
/* We have been shutdown, but this callback may still get called
* by retransmit timer.
*/
pj_grp_lock_release(stun_sock->grp_lock);
return PJ_EINVALIDOP;
}
if (send_key==NULL)
send_key = &stun_sock->send_key;
size = pkt_len;
if (!stun_sock || !stun_sock->active_sock)
return PJ_EINVALIDOP;
/* Check that this is STUN message */
status = pj_stun_msg_check((const pj_uint8_t*)pkt, size,
PJ_STUN_IS_DATAGRAM | PJ_STUN_CHECK_PACKET);
if (status == PJ_SUCCESS)
is_stun = PJ_TRUE;
else
is_tnl_data = (((pj_uint8_t*)pkt)[pkt_len] == 1);
if(is_stun || !is_tnl_data) {
pj_ioqueue_op_key_t *op_key = (pj_ioqueue_op_key_t*)pj_mem_alloc(sizeof(pj_ioqueue_op_key_t));
pj_ioqueue_op_key_init(op_key, sizeof(pj_ioqueue_op_key_t));
status = pj_activesock_sendto(stun_sock->active_sock, op_key,
pkt, &size, (flag | PJ_IOQUEUE_URGENT_DATA), dst_addr, addr_len);
} else {
status = pj_activesock_sendto(stun_sock->active_sock, &stun_sock->send_key,
pkt, &size, flag, dst_addr, addr_len);
}
pj_grp_lock_release(stun_sock->grp_lock);
return status;
}
开发者ID:Antares84,项目名称:asuswrt-merlin,代码行数:53,代码来源:stun_sock.c
示例9: on_read_complete
/*
* Callback upon receiving packet from network.
*/
static void on_read_complete(pj_ioqueue_key_t *key,
pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_read)
{
nat_detect_session *sess;
pj_status_t status;
sess = (nat_detect_session *) pj_ioqueue_get_user_data(key);
pj_assert(sess != NULL);
pj_grp_lock_acquire(sess->grp_lock);
/* Ignore packet when STUN session has been destroyed */
if (!sess->stun_sess)
goto on_return;
if (bytes_read < 0) {
if (-bytes_read != PJ_STATUS_FROM_OS(OSERR_EWOULDBLOCK) &&
-bytes_read != PJ_STATUS_FROM_OS(OSERR_EINPROGRESS) &&
-bytes_read != PJ_STATUS_FROM_OS(OSERR_ECONNRESET))
{
/* Permanent error */
end_session(sess, (pj_status_t)-bytes_read,
PJ_STUN_NAT_TYPE_ERR_UNKNOWN);
goto on_return;
}
} else if (bytes_read > 0) {
pj_stun_session_on_rx_pkt(sess->stun_sess, sess->rx_pkt, bytes_read,
PJ_STUN_IS_DATAGRAM|PJ_STUN_CHECK_PACKET,
NULL, NULL,
&sess->src_addr, sess->src_addr_len);
}
sess->rx_pkt_len = sizeof(sess->rx_pkt);
sess->src_addr_len = sizeof(sess->src_addr);
status = pj_ioqueue_recvfrom(key, op_key, sess->rx_pkt, &sess->rx_pkt_len,
PJ_IOQUEUE_ALWAYS_ASYNC,
&sess->src_addr, &sess->src_addr_len);
if (status != PJ_EPENDING) {
pj_assert(status != PJ_SUCCESS);
end_session(sess, status, PJ_STUN_NAT_TYPE_ERR_UNKNOWN);
}
on_return:
pj_grp_lock_release(sess->grp_lock);
}
开发者ID:zndxlx,项目名称:pjsip_r,代码行数:52,代码来源:nat_detect.c
示例10: PJ_DEF
/*
* Initialize.
*/
PJ_DEF(pj_status_t) pj_turn_sock_alloc(pj_turn_sock *turn_sock,
const pj_str_t *domain,
int default_port,
pj_dns_resolver *resolver,
const pj_stun_auth_cred *cred,
const pj_turn_alloc_param *param)
{
pj_status_t status;
PJ_ASSERT_RETURN(turn_sock && domain, PJ_EINVAL);
PJ_ASSERT_RETURN(turn_sock->sess, PJ_EINVALIDOP);
pj_grp_lock_acquire(turn_sock->grp_lock);
/* Copy alloc param. We will call session_alloc() only after the
* server address has been resolved.
*/
if (param) {
pj_turn_alloc_param_copy(turn_sock->pool, &turn_sock->alloc_param, param);
} else {
pj_turn_alloc_param_default(&turn_sock->alloc_param);
}
/* Set credental */
if (cred) {
status = pj_turn_session_set_credential(turn_sock->sess, cred);
if (status != PJ_SUCCESS) {
sess_fail(turn_sock, "Error setting credential", status);
pj_grp_lock_release(turn_sock->grp_lock);
return status;
}
}
/* Resolve server */
status = pj_turn_session_set_server(turn_sock->sess, domain, default_port,
resolver);
if (status != PJ_SUCCESS) {
sess_fail(turn_sock, "Error setting TURN server", status);
pj_grp_lock_release(turn_sock->grp_lock);
return status;
}
/* Done for now. The next work will be done when session state moved
* to RESOLVED state.
*/
pj_grp_lock_release(turn_sock->grp_lock);
return PJ_SUCCESS;
}
开发者ID:0x0B501E7E,项目名称:pjproject,代码行数:51,代码来源:turn_sock.c
示例11: on_connect_complete
/*
* Notification when outgoing TCP socket has been connected.
*/
static pj_bool_t on_connect_complete(pj_activesock_t *asock,
pj_status_t status)
{
pj_turn_sock *turn_sock;
turn_sock = (pj_turn_sock*) pj_activesock_get_user_data(asock);
if (!turn_sock)
return PJ_FALSE;
pj_grp_lock_acquire(turn_sock->grp_lock);
/* TURN session may have already been destroyed here.
* See ticket #1557 (http://trac.pjsip.org/repos/ticket/1557).
*/
if (!turn_sock->sess) {
sess_fail(turn_sock, "TURN session already destroyed", status);
pj_grp_lock_release(turn_sock->grp_lock);
return PJ_FALSE;
}
if (status != PJ_SUCCESS) {
sess_fail(turn_sock, "TCP connect() error", status);
pj_grp_lock_release(turn_sock->grp_lock);
return PJ_FALSE;
}
if (turn_sock->conn_type != PJ_TURN_TP_UDP) {
PJ_LOG(5,(turn_sock->obj_name, "TCP connected"));
}
/* Kick start pending read operation */
status = pj_activesock_start_read(asock, turn_sock->pool,
turn_sock->setting.max_pkt_size, 0);
/* Init send_key */
pj_ioqueue_op_key_init(&turn_sock->send_key, sizeof(turn_sock->send_key));
/* Send Allocate request */
status = pj_turn_session_alloc(turn_sock->sess, &turn_sock->alloc_param);
if (status != PJ_SUCCESS) {
sess_fail(turn_sock, "Error sending ALLOCATE", status);
pj_grp_lock_release(turn_sock->grp_lock);
return PJ_FALSE;
}
pj_grp_lock_release(turn_sock->grp_lock);
return PJ_TRUE;
}
开发者ID:0x0B501E7E,项目名称:pjproject,代码行数:51,代码来源:turn_sock.c
示例12: PJ_DEF
PJ_DEF(void) pj_grp_lock_t::pj_grp_lock_dump()
{
#if PJ_GRP_LOCK_DEBUG
grp_lock_ref *ref = grp_lock->ref_list.next;
char info_buf[1000];
pj_str_t info;
info.ptr = info_buf;
info.slen = 0;
pj_grp_lock_acquire(grp_lock);
pj_enter_critical_section();
while (ref != &grp_lock->ref_list && info.slen < sizeof(info_buf)) {
char *start = info.ptr + info.slen;
int max_len = sizeof(info_buf) - info.slen;
int len;
len = pj_ansi_snprintf(start, max_len, "%s:%d ", ref->file, ref->line);
if (len < 1 || len >= max_len) {
len = strlen(ref->file);
if (len > max_len - 1)
len = max_len - 1;
memcpy(start, ref->file, len);
start[len++] = ' ';
}
info.slen += len;
ref = ref->next;
}
if (ref != &grp_lock->ref_list) {
int i;
for (i=0; i<4; ++i)
info_buf[sizeof(info_buf)-i-1] = '.';
}
info.ptr[info.slen-1] = '\0';
pj_leave_critical_section();
pj_grp_lock_release(grp_lock);
PJ_LOG(4,(THIS_FILE, "Group lock %p, ref_cnt=%d. Reference holders: %s",
grp_lock, pj_grp_lock_get_ref(grp_lock), info.ptr));
#endif
}
开发者ID:yagiza,项目名称:qtice,代码行数:47,代码来源:lock.cpp
示例13: retransmit_timer_callback
/* Retransmit timer callback */
static void retransmit_timer_callback(pj_timer_heap_t *timer_heap,
pj_timer_entry *timer)
{
pj_stun_client_tsx *tsx = (pj_stun_client_tsx *) timer->user_data;
pj_status_t status;
PJ_UNUSED_ARG(timer_heap);
pj_grp_lock_acquire(tsx->grp_lock);
if (tsx->transmit_count >= PJ_STUN_MAX_TRANSMIT_COUNT) {
/* tsx may be destroyed when calling the callback below */
pj_grp_lock_t *grp_lock = tsx->grp_lock;
/* Retransmission count exceeded. Transaction has failed */
tsx->retransmit_timer.id = 0;
PJ_LOG(4,(tsx->obj_name, "STUN timeout waiting for response"));
pj_log_push_indent();
if (!tsx->complete) {
tsx->complete = PJ_TRUE;
if (tsx->cb.on_complete) {
tsx->cb.on_complete(tsx, PJNATH_ESTUNTIMEDOUT, NULL, NULL, 0);
}
}
pj_grp_lock_release(grp_lock);
/* We might have been destroyed, don't try to access the object */
pj_log_pop_indent();
return;
}
tsx->retransmit_timer.id = 0;
status = tsx_transmit_msg(tsx, PJ_TRUE);
if (status != PJ_SUCCESS) {
tsx->retransmit_timer.id = 0;
if (!tsx->complete) {
tsx->complete = PJ_TRUE;
if (tsx->cb.on_complete) {
tsx->cb.on_complete(tsx, status, NULL, NULL, 0);
}
}
}
pj_grp_lock_release(tsx->grp_lock);
/* We might have been destroyed, don't try to access the object */
}
开发者ID:jhcloos,项目名称:pjproject,代码行数:45,代码来源:stun_transaction.c
示例14: destroy
static void destroy(pj_turn_sock *turn_sock)
{
PJ_LOG(4,(turn_sock->obj_name, "TURN socket destroy request, ref_cnt=%d",
pj_grp_lock_get_ref(turn_sock->grp_lock)));
pj_grp_lock_acquire(turn_sock->grp_lock);
if (turn_sock->is_destroying) {
pj_grp_lock_release(turn_sock->grp_lock);
return;
}
turn_sock->is_destroying = PJ_TRUE;
if (turn_sock->sess)
pj_turn_session_shutdown(turn_sock->sess);
if (turn_sock->active_sock)
pj_activesock_close(turn_sock->active_sock);
pj_grp_lock_dec_ref(turn_sock->grp_lock);
pj_grp_lock_release(turn_sock->grp_lock);
}
开发者ID:0x0B501E7E,项目名称:pjproject,代码行数:19,代码来源:turn_sock.c
示例15: ka_timer_cb
/* Keep-alive timer callback */
static void ka_timer_cb(pj_timer_heap_t *th, pj_timer_entry *te)
{
pj_stun_sock *stun_sock;
stun_sock = (pj_stun_sock *) te->user_data;
PJ_UNUSED_ARG(th);
pj_grp_lock_acquire(stun_sock->grp_lock);
/* Time to send STUN Binding request */
if (get_mapped_addr(stun_sock) != PJ_SUCCESS) {
pj_grp_lock_release(stun_sock->grp_lock);
return;
}
/* Next keep-alive timer will be scheduled once the request
* is complete.
*/
pj_grp_lock_release(stun_sock->grp_lock);
}
开发者ID:AmoebaLabs,项目名称:pjsip,代码行数:21,代码来源:stun_sock.c
示例16: stun_tsx_on_complete
static void stun_tsx_on_complete(pj_stun_client_tsx *tsx,
pj_status_t status,
const pj_stun_msg *response,
const pj_sockaddr_t *src_addr,
unsigned src_addr_len)
{
pj_stun_session *sess;
pj_bool_t notify_user = PJ_TRUE;
pj_stun_tx_data *tdata;
tdata = (pj_stun_tx_data*) pj_stun_client_tsx_get_data(tsx);
sess = tdata->sess;
/* Lock the session and prevent user from destroying us in the callback */
pj_grp_lock_acquire(sess->grp_lock);
if (sess->is_destroying) {
pj_stun_msg_destroy_tdata(sess, tdata);
pj_grp_lock_release(sess->grp_lock);
return;
}
/* Handle authentication challenge */
handle_auth_challenge(sess, tdata, response, src_addr,
src_addr_len, ¬ify_user);
if (notify_user && sess->cb.on_request_complete) {
(*sess->cb.on_request_complete)(sess, status, tdata->token, tdata,
response, src_addr, src_addr_len);
}
/* Destroy the transmit data. This will remove the transaction
* from the pending list too.
*/
if (status == PJNATH_ESTUNTIMEDOUT)
destroy_tdata(tdata, PJ_TRUE);
else
destroy_tdata(tdata, PJ_FALSE);
tdata = NULL;
pj_grp_lock_release(sess->grp_lock);
}
开发者ID:Archipov,项目名称:android-client,代码行数:41,代码来源:stun_session.c
示例17: on_data_sent
/* Callback from active socket about send status */
static pj_bool_t on_data_sent(pj_activesock_t *asock,
pj_ioqueue_op_key_t *send_key,
pj_ssize_t sent)
{
pj_stun_sock *stun_sock;
stun_sock = (pj_stun_sock*) pj_activesock_get_user_data(asock);
if (!stun_sock)
return PJ_FALSE;
/* Don't report to callback if this is internal message */
if (send_key == &stun_sock->int_send_key) {
return PJ_TRUE;
}
/* Report to callback */
if (stun_sock->cb.on_data_sent) {
pj_bool_t ret;
pj_grp_lock_acquire(stun_sock->grp_lock);
/* If app gives NULL send_key in sendto() function, then give
* NULL in the callback too
*/
if (send_key == &stun_sock->send_key)
send_key = NULL;
/* Call callback */
ret = (*stun_sock->cb.on_data_sent)(stun_sock, send_key, sent);
pj_grp_lock_release(stun_sock->grp_lock);
return ret;
}
return PJ_TRUE;
}
开发者ID:AmoebaLabs,项目名称:pjsip,代码行数:37,代码来源:stun_sock.c
示例18: proxy_on_rx_request
//.........这里部分代码省略.........
return PJ_TRUE;
}
/* Feed the request to the UAS transaction to drive it's state
* out of NULL state.
*/
pjsip_tsx_recv_msg(uas_tsx, rdata);
/* Attach a data to the UAC transaction, to be used to find the
* UAS transaction when we receive response in the UAC side.
*/
uac_data = (struct uac_data*)
pj_pool_alloc(uac_tsx->pool, sizeof(struct uac_data));
uac_data->uas_tsx = uas_tsx;
uac_tsx->mod_data[mod_tu.id] = (void*)uac_data;
/* Attach data to the UAS transaction, to find the UAC transaction
* when cancelling INVITE request.
*/
uas_data = (struct uas_data*)
pj_pool_alloc(uas_tsx->pool, sizeof(struct uas_data));
uas_data->uac_tsx = uac_tsx;
uas_tsx->mod_data[mod_tu.id] = (void*)uas_data;
/* Everything is setup, forward the request */
status = pjsip_tsx_send_msg(uac_tsx, tdata);
if (status != PJ_SUCCESS) {
pjsip_tx_data *err_res;
/* Fail to send request, for some reason */
/* Destroy transmit data */
pjsip_tx_data_dec_ref(tdata);
/* I think UAC transaction should have been destroyed when
* it fails to send request, so no need to destroy it.
pjsip_tsx_terminate(uac_tsx, PJSIP_SC_INTERNAL_SERVER_ERROR);
*/
/* Send 500/Internal Server Error to UAS transaction */
pjsip_endpt_create_response(global.endpt, rdata,
500, NULL, &err_res);
pjsip_tsx_send_msg(uas_tsx, err_res);
return PJ_TRUE;
}
/* Send 100/Trying if this is an INVITE */
if (rdata->msg_info.msg->line.req.method.id == PJSIP_INVITE_METHOD) {
pjsip_tx_data *res100;
pjsip_endpt_create_response(global.endpt, rdata, 100, NULL,
&res100);
pjsip_tsx_send_msg(uas_tsx, res100);
}
} else {
/* This is CANCEL request */
pjsip_transaction *invite_uas;
struct uas_data *uas_data2;
pj_str_t key;
/* Find the UAS INVITE transaction */
pjsip_tsx_create_key(rdata->tp_info.pool, &key, PJSIP_UAS_ROLE,
pjsip_get_invite_method(), rdata);
invite_uas = pjsip_tsx_layer_find_tsx(&key, PJ_TRUE);
if (!invite_uas) {
/* Invite transaction not found, respond CANCEL with 481 */
pjsip_endpt_respond_stateless(global.endpt, rdata, 481, NULL,
NULL, NULL);
return PJ_TRUE;
}
/* Respond 200 OK to CANCEL */
pjsip_endpt_respond(global.endpt, NULL, rdata, 200, NULL, NULL,
NULL, NULL);
/* Send CANCEL to cancel the UAC transaction.
* The UAS INVITE transaction will get final response when
* we receive final response from the UAC INVITE transaction.
*/
uas_data2 = (struct uas_data*) invite_uas->mod_data[mod_tu.id];
if (uas_data2->uac_tsx && uas_data2->uac_tsx->status_code < 200) {
pjsip_tx_data *cancel;
pj_grp_lock_acquire(uas_data2->uac_tsx->grp_lock);
pjsip_endpt_create_cancel(global.endpt, uas_data2->uac_tsx->last_tx,
&cancel);
pjsip_endpt_send_request(global.endpt, cancel, -1, NULL, NULL);
pj_grp_lock_release(uas_data2->uac_tsx->grp_lock);
}
/* Unlock UAS tsx because it is locked in find_tsx() */
pj_grp_lock_release(invite_uas->grp_lock);
}
return PJ_TRUE;
}
开发者ID:RyanLee27,项目名称:pjproject,代码行数:101,代码来源:stateful_proxy.c
示例19: on_data_read
/*
* Notification from ioqueue when incoming UDP packet is received.
*/
static pj_bool_t on_data_read(pj_activesock_t *asock,
void *data,
pj_size_t size,
pj_status_t status,
pj_size_t *remainder)
{
pj_turn_sock *turn_sock;
pj_bool_t ret = PJ_TRUE;
turn_sock = (pj_turn_sock*) pj_activesock_get_user_data(asock);
pj_grp_lock_acquire(turn_sock->grp_lock);
if (status == PJ_SUCCESS && turn_sock->sess && !turn_sock->is_destroying) {
/* Report incoming packet to TURN session, repeat while we have
* "packet" in the buffer (required for stream-oriented transports)
*/
unsigned pkt_len;
//PJ_LOG(5,(turn_sock->pool->obj_name,
// "Incoming data, %lu bytes total buffer", size));
while ((pkt_len=has_packet(turn_sock, data, size)) != 0) {
pj_size_t parsed_len;
//const pj_uint8_t *pkt = (const pj_uint8_t*)data;
//PJ_LOG(5,(turn_sock->pool->obj_name,
// "Packet start: %02X %02X %02X %02X",
// pkt[0], pkt[1], pkt[2], pkt[3]));
//PJ_LOG(5,(turn_sock->pool->obj_name,
// "Processing %lu bytes packet of %lu bytes total buffer",
// pkt_len, size));
parsed_len = (unsigned)size;
pj_turn_session_on_rx_pkt(turn_sock->sess, data, size, &parsed_len);
/* parsed_len may be zero if we have parsing error, so use our
* previous calculation to exhaust the bad packet.
*/
if (parsed_len == 0)
parsed_len = pkt_len;
if (parsed_len < (unsigned)size) {
*remainder = size - parsed_len;
pj_memmove(data, ((char*)data)+parsed_len, *remainder);
} else {
*remainder = 0;
}
size = *remainder;
//PJ_LOG(5,(turn_sock->pool->obj_name,
// "Buffer size now %lu bytes", size));
}
} else if (status != PJ_SUCCESS &&
turn_sock->conn_type != PJ_TURN_TP_UDP)
{
sess_fail(turn_sock, "TCP connection closed", status);
ret = PJ_FALSE;
goto on_return;
}
on_return:
pj_grp_lock_release(turn_sock->grp_lock);
return ret;
}
开发者ID:0x0B501E7E,项目名称:pjproject,代码行数:69,代码来源:turn_sock.c
示例20: on_data_recvfrom
/* Callback from active socket when incoming packet is received */
static pj_bool_t on_data_recvfrom(pj_activesock_t *asock,
void *data,
pj_size_t size,
const pj_sockaddr_t *src_addr,
int addr_len,
pj_status_t status)
{
pj_stun_sock *stun_sock;
pj_stun_msg_hdr *hdr;
pj_uint16_t type;
stun_sock = (pj_stun_sock*) pj_activesock_get_user_data(asock);
if (!stun_sock)
return PJ_FALSE;
/* Log socket error */
if (status != PJ_SUCCESS) {
PJ_PERROR(2,(stun_sock->obj_name, status, "recvfrom() error"));
return PJ_TRUE;
}
pj_grp_lock_acquire(stun_sock->grp_lock);
/* Check that this is STUN message */
status = pj_stun_msg_check((const pj_uint8_t*)data, size,
PJ_STUN_IS_DATAGRAM | PJ_STUN_CHECK_PACKET);
if (status != PJ_SUCCESS) {
/* Not STUN -- give it to application */
goto process_app_data;
}
/* Treat packet as STUN header and copy the STUN message type.
* We don't want to access the type directly from the header
* since it may not be properly aligned.
*/
hdr = (pj_stun_msg_hdr*) data;
pj_memcpy(&type, &hdr->type, 2);
type = pj_ntohs(type);
/* If the packet is a STUN Binding response and part of the
* transaction ID matches our internal ID, then this is
* our internal STUN message (Binding request or keep alive).
* Give it to our STUN session.
*/
if (!PJ_STUN_IS_RESPONSE(type) ||
PJ_STUN_GET_METHOD(type) != PJ_STUN_BINDING_METHOD ||
pj_memcmp(hdr->tsx_id, stun_sock->tsx_id, 10) != 0)
{
/* Not STUN Binding response, or STUN transaction ID mismatch.
* This is not our message too -- give it to application.
*/
goto process_app_data;
}
/* This is our STUN Binding response. Give it to the STUN session */
status = pj_stun_session_on_rx_pkt(stun_sock->stun_sess, data, size,
PJ_STUN_IS_DATAGRAM, NULL, NULL,
src_addr, addr_len);
status = pj_grp_lock_release(stun_sock->grp_lock);
return status!=PJ_EGONE ? PJ_TRUE : PJ_FALSE;
process_app_data:
if (stun_sock->cb.on_rx_data) {
pj_bool_t ret;
ret = (*stun_sock->cb.on_rx_data)(stun_sock, data, size,
src_addr, addr_len);
status = pj_grp_lock_release(stun_sock->grp_lock);
return status!=PJ_EGONE ? PJ_TRUE : PJ_FALSE;
}
status = pj_grp_lock_release(stun_sock->grp_lock);
return status!=PJ_EGONE ? PJ_TRUE : PJ_FALSE;
}
开发者ID:AmoebaLabs,项目名称:pjsip,代码行数:77,代码来源:stun_sock.c
注:本文中的pj_grp_lock_acquire函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论