本文整理汇总了C++中pj_SOCK_DGRAM函数的典型用法代码示例。如果您正苦于以下问题:C++ pj_SOCK_DGRAM函数的具体用法?C++ pj_SOCK_DGRAM怎么用?C++ pj_SOCK_DGRAM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_SOCK_DGRAM函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PJ_DEF
PJ_DEF(pj_status_t) pj_activesock_create_udp( pj_pool_t *pool,
const pj_sockaddr *addr,
const pj_activesock_cfg *opt,
pj_ioqueue_t *ioqueue,
const pj_activesock_cb *cb,
void *user_data,
pj_activesock_t **p_asock,
pj_sockaddr *bound_addr)
{
pj_sock_t sock_fd;
pj_sockaddr default_addr;
pj_status_t status;
if (addr == NULL) {
pj_sockaddr_init(pj_AF_INET(), &default_addr, NULL, 0);
addr = &default_addr;
}
status = pj_sock_socket(addr->addr.sa_family, pj_SOCK_DGRAM(), 0,
&sock_fd);
if (status != PJ_SUCCESS) {
return status;
}
status = pj_sock_bind(sock_fd, addr, pj_sockaddr_get_len(addr));
if (status != PJ_SUCCESS) {
pj_sock_close(sock_fd);
return status;
}
status = pj_activesock_create(pool, sock_fd, pj_SOCK_DGRAM(), opt,
ioqueue, cb, user_data, p_asock);
if (status != PJ_SUCCESS) {
pj_sock_close(sock_fd);
return status;
}
if (bound_addr) {
int addr_len = sizeof(*bound_addr);
status = pj_sock_getsockname(sock_fd, bound_addr, &addr_len);
if (status != PJ_SUCCESS) {
pj_activesock_close(*p_asock);
return status;
}
}
return PJ_SUCCESS;
}
示例2: create_socket
/* Create socket */
static pj_status_t create_socket(int af, const pj_sockaddr_t *local_a,
int addr_len, pj_sock_t *p_sock)
{
pj_sock_t sock;
pj_sockaddr_in tmp_addr;
pj_status_t status;
status = pj_sock_socket(af, pj_SOCK_DGRAM(), 0, &sock);
if (status != PJ_SUCCESS)
return status;
if (local_a == NULL) {
pj_sockaddr_in_init(&tmp_addr, NULL, 0);
local_a = &tmp_addr;
addr_len = sizeof(tmp_addr);
}
status = pj_sock_bind(sock, local_a, addr_len);
if (status != PJ_SUCCESS) {
pj_sock_close(sock);
return status;
}
*p_sock = sock;
return PJ_SUCCESS;
}
示例3: simple_sock_test
static int simple_sock_test(void)
{
int types[2];
pj_sock_t sock;
int i;
pj_status_t rc = PJ_SUCCESS;
types[0] = pj_SOCK_STREAM();
types[1] = pj_SOCK_DGRAM();
PJ_LOG(3,("test", "...simple_sock_test()"));
for (i=0; i<(int)(sizeof(types)/sizeof(types[0])); ++i) {
rc = pj_sock_socket(pj_AF_INET(), types[i], 0, &sock);
if (rc != PJ_SUCCESS) {
app_perror("...error: unable to create socket", rc);
break;
} else {
rc = pj_sock_close(sock);
if (rc != 0) {
app_perror("...error: close socket", rc);
break;
}
}
}
return rc;
}
示例4: PJ_DEF
/* Get the default IP interface */
PJ_DEF(pj_status_t) pj_getdefaultipinterface(int af, pj_sockaddr *addr)
{
pj_sock_t fd;
pj_str_t cp;
pj_sockaddr a;
int len;
pj_uint8_t zero[64];
pj_status_t status;
addr->addr.sa_family = (pj_uint16_t)af;
status = pj_sock_socket(af, pj_SOCK_DGRAM(), 0, &fd);
if (status != PJ_SUCCESS) {
return status;
}
PJ_LOG(4, ("sock_common.c", "pj_getdefaultipinterface() pj_sock_socket."));
if (af == PJ_AF_INET) {
cp = pj_str("1.1.1.1");
} else {
cp = pj_str("1::1");
}
status = pj_sockaddr_init(af, &a, &cp, 53);
if (status != PJ_SUCCESS) {
pj_sock_close(fd);
return status;
}
PJ_LOG(4, ("sock_common.c", "pj_getdefaultipinterface() pj_sockaddr_init."));
status = pj_sock_connect(fd, &a, pj_sockaddr_get_len(&a));
if (status != PJ_SUCCESS) {
pj_sock_close(fd);
return status;
}
PJ_LOG(4, ("sock_common.c", "pj_getdefaultipinterface() pj_sock_connect."));
len = sizeof(a);
status = pj_sock_getsockname(fd, &a, &len);
if (status != PJ_SUCCESS) {
pj_sock_close(fd);
return status;
}
PJ_LOG(4, ("sock_common.c", "pj_getdefaultipinterface() pj_sock_getsockname."));
pj_sock_close(fd);
/* Check that the address returned is not zero */
pj_bzero(zero, sizeof(zero));
if (pj_memcmp(pj_sockaddr_get_addr(&a), zero,
pj_sockaddr_get_addr_len(&a))==0)
{
PJ_LOG(4, ("sock_common.c", "pj_getdefaultipinterface() interface not found."));
return PJ_ENOTFOUND;
}
pj_sockaddr_copy_addr(addr, &a);
/* Success */
return PJ_SUCCESS;
}
示例5: create_socket
/* Create socket */
static pj_status_t create_socket(int af, const pj_sockaddr_t *local_a,
int addr_len, pj_sock_t *p_sock)
{
pj_sock_t sock;
pj_sockaddr_in tmp_addr;
pj_sockaddr_in6 tmp_addr6;
pj_status_t status;
status = pj_sock_socket(af, pj_SOCK_DGRAM(), 0, &sock);
if (status != PJ_SUCCESS)
return status;
if (local_a == NULL) {
if (af == pj_AF_INET6()) {
pj_bzero(&tmp_addr6, sizeof(tmp_addr6));
tmp_addr6.sin6_family = (pj_uint16_t)af;
local_a = &tmp_addr6;
addr_len = sizeof(tmp_addr6);
} else {
pj_sockaddr_in_init(&tmp_addr, NULL, 0);
local_a = &tmp_addr;
addr_len = sizeof(tmp_addr);
}
}
status = pj_sock_bind(sock, local_a, addr_len);
if (status != PJ_SUCCESS) {
pj_sock_close(sock);
return status;
}
*p_sock = sock;
return PJ_SUCCESS;
}
示例6: sock_perf_test
/*
* sock_perf_test()
*
* Main test entry.
*/
int sock_perf_test(void)
{
enum { LOOP = 64 * 1024 };
int rc;
unsigned bandwidth;
PJ_LOG(3,("", "...benchmarking socket "
"(2 sockets, packet=512, single threaded):"));
/* Disable this test on Symbian since UDP connect()/send() failed
* with S60 3rd edition (including MR2).
* See http://www.pjsip.org/trac/ticket/264
*/
#if !defined(PJ_SYMBIAN) || PJ_SYMBIAN==0
/* Benchmarking UDP */
rc = sock_producer_consumer(pj_SOCK_DGRAM(), 512, LOOP, &bandwidth);
if (rc != 0) return rc;
PJ_LOG(3,("", "....bandwidth UDP = %d KB/s", bandwidth));
#endif
/* Benchmarking TCP */
rc = sock_producer_consumer(pj_SOCK_STREAM(), 512, LOOP, &bandwidth);
if (rc != 0) return rc;
PJ_LOG(3,("", "....bandwidth TCP = %d KB/s", bandwidth));
return rc;
}
示例7: PJ_DEF
/*
* Create new socket/endpoint for communication and returns a descriptor.
*/
PJ_DEF(pj_status_t) pj_sock_socket(int af,
int type,
int proto,
pj_sock_t *sock)
{
PJ_CHECK_STACK();
/* Sanity checks. */
PJ_ASSERT_RETURN(sock!=NULL, PJ_EINVAL);
PJ_ASSERT_RETURN(PJ_INVALID_SOCKET==-1,
(*sock=PJ_INVALID_SOCKET, PJ_EINVAL));
*sock = socket(af, type, proto);
if (*sock == PJ_INVALID_SOCKET)
return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
else {
pj_int32_t val = 1;
if (type == pj_SOCK_STREAM()) {
pj_sock_setsockopt(*sock, pj_SOL_SOCKET(), pj_SO_NOSIGPIPE(),
&val, sizeof(val));
}
#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \
PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0
if (type == pj_SOCK_DGRAM()) {
pj_sock_setsockopt(*sock, pj_SOL_SOCKET(), SO_NOSIGPIPE,
&val, sizeof(val));
}
#endif
return PJ_SUCCESS;
}
}
示例8: udp_echo_srv_ioqueue
int udp_echo_srv_ioqueue(void)
{
pj_pool_t *pool;
pj_sock_t sock;
pj_ioqueue_t *ioqueue;
pj_ioqueue_callback callback;
int i;
pj_thread_t *thread[ECHO_SERVER_MAX_THREADS];
pj_status_t rc;
pj_bzero(&callback, sizeof(callback));
callback.on_read_complete = &on_read_complete;
callback.on_write_complete = &on_write_complete;
pool = pj_pool_create(mem, NULL, 4000, 4000, NULL);
if (!pool)
return -10;
rc = pj_ioqueue_create(pool, 2, &ioqueue);
if (rc != PJ_SUCCESS) {
app_perror("...pj_ioqueue_create error", rc);
return -20;
}
rc = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0,
ECHO_SERVER_START_PORT, &sock);
if (rc != PJ_SUCCESS) {
app_perror("...app_socket error", rc);
return -30;
}
rc = pj_ioqueue_register_sock(pool, ioqueue, sock, NULL,
&callback, &key);
if (rc != PJ_SUCCESS) {
app_perror("...error registering socket", rc);
return -40;
}
rc = pj_atomic_create(pool, 0, &total_bytes);
if (rc != PJ_SUCCESS) {
app_perror("...error creating atomic variable", rc);
return -45;
}
for (i=0; i<ECHO_SERVER_MAX_THREADS; ++i) {
rc = pj_thread_create(pool, NULL, &worker_thread, ioqueue,
PJ_THREAD_DEFAULT_STACK_SIZE, 0,
&thread[i]);
if (rc != PJ_SUCCESS) {
app_perror("...create thread error", rc);
return -50;
}
}
echo_srv_common_loop(total_bytes);
return 0;
}
示例9: main
int main(int argc, char *argv[])
{
int rc;
int interractive = 0;
boost();
init_signals();
while (argc > 1) {
char *arg = argv[--argc];
if (*arg=='-' && *(arg+1)=='i') {
interractive = 1;
} else if (*arg=='-' && *(arg+1)=='p') {
pj_str_t port = pj_str(argv[--argc]);
param_echo_port = pj_strtoul(&port);
} else if (*arg=='-' && *(arg+1)=='s') {
param_echo_server = argv[--argc];
} else if (*arg=='-' && *(arg+1)=='t') {
pj_str_t type = pj_str(argv[--argc]);
if (pj_stricmp2(&type, "tcp")==0)
param_echo_sock_type = pj_SOCK_STREAM();
else if (pj_stricmp2(&type, "udp")==0)
param_echo_sock_type = pj_SOCK_DGRAM();
else {
PJ_LOG(3,("", "error: unknown socket type %s", type.ptr));
return 1;
}
}
}
rc = test_main();
if (interractive) {
char s[10];
puts("");
puts("Press <ENTER> to exit");
if (!fgets(s, sizeof(s), stdin))
return rc;
}
return rc;
}
示例10: PJ_DEF
/*
* Create new socket/endpoint for communication and returns a descriptor.
*/
PJ_DEF(pj_status_t) pj_sock_socket(int af,
int type,
int proto,
pj_sock_t *p_sock)
{
TInt rc;
PJ_CHECK_STACK();
/* Sanity checks. */
PJ_ASSERT_RETURN(p_sock!=NULL, PJ_EINVAL);
// Return failure if access point is marked as down by app.
PJ_SYMBIAN_CHECK_CONNECTION();
/* Set proto if none is specified. */
if (proto == 0) {
if (type == pj_SOCK_STREAM())
proto = KProtocolInetTcp;
else if (type == pj_SOCK_DGRAM())
proto = KProtocolInetUdp;
}
/* Create Symbian RSocket */
RSocket rSock;
if (PjSymbianOS::Instance()->Connection())
rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(),
af, type, proto,
*PjSymbianOS::Instance()->Connection());
else
rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(),
af, type, proto);
if (rc != KErrNone)
return PJ_RETURN_OS_ERROR(rc);
/* Wrap Symbian RSocket into PJLIB's CPjSocket, and return to caller */
CPjSocket *pjSock = new CPjSocket(af, type, rSock);
*p_sock = (pj_sock_t)pjSock;
return PJ_SUCCESS;
}
示例11: echo_srv_sync
int echo_srv_sync(void)
{
pj_pool_t *pool;
pj_sock_t sock;
pj_thread_t *thread[ECHO_SERVER_MAX_THREADS];
pj_status_t rc;
int i;
pool = pj_pool_create(mem, NULL, 4000, 4000, NULL);
if (!pool)
return -5;
rc = pj_atomic_create(pool, 0, &total_bytes);
if (rc != PJ_SUCCESS) {
app_perror("...unable to create atomic_var", rc);
return -6;
}
rc = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(),0, ECHO_SERVER_START_PORT, &sock);
if (rc != PJ_SUCCESS) {
app_perror("...socket error", rc);
return -10;
}
for (i=0; i<ECHO_SERVER_MAX_THREADS; ++i) {
rc = pj_thread_create(pool, NULL, &worker_thread, (void*)sock,
PJ_THREAD_DEFAULT_STACK_SIZE, 0,
&thread[i]);
if (rc != PJ_SUCCESS) {
app_perror("...unable to create thread", rc);
return -20;
}
}
PJ_LOG(3,("", "...UDP echo server running with %d threads at port %d",
ECHO_SERVER_MAX_THREADS, ECHO_SERVER_START_PORT));
PJ_LOG(3,("", "...Press Ctrl-C to abort"));
echo_srv_common_loop(total_bytes);
return 0;
}
示例12: init_sock
/* Initialize UDP socket */
static pj_status_t init_sock(pj_dns_resolver *resv)
{
pj_ioqueue_callback socket_cb;
pj_status_t status;
/* Create the UDP socket */
status = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &resv->udp_sock);
if (status != PJ_SUCCESS)
return status;
/* Bind to any address/port */
status = pj_sock_bind_in(resv->udp_sock, 0, 0);
if (status != PJ_SUCCESS)
return status;
/* Register to ioqueue */
pj_bzero(&socket_cb, sizeof(socket_cb));
socket_cb.on_read_complete = &on_read_complete;
status = pj_ioqueue_register_sock(resv->pool, resv->ioqueue,
resv->udp_sock, resv, &socket_cb,
&resv->udp_key);
if (status != PJ_SUCCESS)
return status;
pj_ioqueue_op_key_init(&resv->udp_op_rx_key, sizeof(resv->udp_op_rx_key));
pj_ioqueue_op_key_init(&resv->udp_op_tx_key, sizeof(resv->udp_op_tx_key));
/* Start asynchronous read to the UDP socket */
resv->udp_len = sizeof(resv->udp_rx_pkt);
resv->udp_addr_len = sizeof(resv->udp_src_addr);
status = pj_ioqueue_recvfrom(resv->udp_key, &resv->udp_op_rx_key,
resv->udp_rx_pkt, &resv->udp_len,
PJ_IOQUEUE_ALWAYS_ASYNC,
&resv->udp_src_addr, &resv->udp_addr_len);
if (status != PJ_EPENDING)
return status;
return PJ_SUCCESS;
}
示例13: get_local_interface
static pj_status_t get_local_interface(const pj_sockaddr *server,
pj_sockaddr *local_addr)
{
pj_sock_t sock;
pj_sockaddr tmp, local;
int addr_len;
pj_status_t status;
status = pj_sock_socket(server->addr.sa_family, pj_SOCK_DGRAM(),
0, &sock);
if (status != PJ_SUCCESS)
return status;
addr_len = pj_sockaddr_get_len(server);
pj_sockaddr_init(server->addr.sa_family, &local, NULL, 0);
status = pj_sock_bind(sock, &local, addr_len);
if (status != PJ_SUCCESS) {
pj_sock_close(sock);
return status;
}
status = pj_sock_connect(sock, server, addr_len);
if (status != PJ_SUCCESS) {
pj_sock_close(sock);
return status;
}
status = pj_sock_getsockname(sock, &tmp, &addr_len);
if (status != PJ_SUCCESS) {
pj_sock_close(sock);
return status;
}
pj_sockaddr_cp(local_addr, &tmp);
pj_sock_close(sock);
return PJ_SUCCESS;
}
示例14: get_local_interface
static pj_status_t get_local_interface(const pj_sockaddr_in *server,
pj_in_addr *local_addr)
{
pj_sock_t sock;
pj_sockaddr_in tmp;
int addr_len;
pj_status_t status;
status = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &sock);
if (status != PJ_SUCCESS)
return status;
status = pj_sock_bind_in(sock, 0, 0);
if (status != PJ_SUCCESS) {
pj_sock_close(sock);
return status;
}
status = pj_sock_connect(sock, server, sizeof(pj_sockaddr_in));
if (status != PJ_SUCCESS) {
pj_sock_close(sock);
return status;
}
addr_len = sizeof(pj_sockaddr_in);
status = pj_sock_getsockname(sock, &tmp, &addr_len);
if (status != PJ_SUCCESS) {
pj_sock_close(sock);
return status;
}
local_addr->s_addr = tmp.sin_addr.s_addr;
pj_sock_close(sock);
return PJ_SUCCESS;
}
示例15: turn_on_state
/*
* Callback from TURN session when state has changed
*/
static void turn_on_state(pj_turn_session *sess,
pj_turn_state_t old_state,
pj_turn_state_t new_state)
{
pj_turn_sock *turn_sock = (pj_turn_sock*)
pj_turn_session_get_user_data(sess);
pj_status_t status;
if (turn_sock == NULL) {
/* We've been destroyed */
return;
}
/* Notify app first */
if (turn_sock->cb.on_state) {
(*turn_sock->cb.on_state)(turn_sock, old_state, new_state);
}
/* Make sure user hasn't destroyed us in the callback */
if (turn_sock->sess && new_state == PJ_TURN_STATE_RESOLVED) {
pj_turn_session_info info;
pj_turn_session_get_info(turn_sock->sess, &info);
new_state = info.state;
}
if (turn_sock->sess && new_state == PJ_TURN_STATE_RESOLVED) {
/*
* Once server has been resolved, initiate outgoing TCP
* connection to the server.
*/
pj_turn_session_info info;
char addrtxt[PJ_INET6_ADDRSTRLEN+8];
int sock_type;
pj_sock_t sock;
pj_activesock_cfg asock_cfg;
pj_activesock_cb asock_cb;
pj_sockaddr bound_addr, *cfg_bind_addr;
pj_uint16_t max_bind_retry;
/* Close existing connection, if any. This happens when
* we're switching to alternate TURN server when either TCP
* connection or ALLOCATE request failed.
*/
if (turn_sock->active_sock) {
pj_activesock_close(turn_sock->active_sock);
turn_sock->active_sock = NULL;
}
/* Get server address from session info */
pj_turn_session_get_info(sess, &info);
if (turn_sock->conn_type == PJ_TURN_TP_UDP)
sock_type = pj_SOCK_DGRAM();
else
sock_type = pj_SOCK_STREAM();
/* Init socket */
status = pj_sock_socket(turn_sock->af, sock_type, 0, &sock);
if (status != PJ_SUCCESS) {
pj_turn_sock_destroy(turn_sock);
return;
}
/* Bind socket */
cfg_bind_addr = &turn_sock->setting.bound_addr;
max_bind_retry = MAX_BIND_RETRY;
if (turn_sock->setting.port_range &&
turn_sock->setting.port_range < max_bind_retry)
{
max_bind_retry = turn_sock->setting.port_range;
}
pj_sockaddr_init(turn_sock->af, &bound_addr, NULL, 0);
if (cfg_bind_addr->addr.sa_family == pj_AF_INET() ||
cfg_bind_addr->addr.sa_family == pj_AF_INET6())
{
pj_sockaddr_cp(&bound_addr, cfg_bind_addr);
}
status = pj_sock_bind_random(sock, &bound_addr,
turn_sock->setting.port_range,
max_bind_retry);
if (status != PJ_SUCCESS) {
pj_turn_sock_destroy(turn_sock);
return;
}
/* Apply QoS, if specified */
status = pj_sock_apply_qos2(sock, turn_sock->setting.qos_type,
&turn_sock->setting.qos_params,
(turn_sock->setting.qos_ignore_error?2:1),
turn_sock->pool->obj_name, NULL);
if (status != PJ_SUCCESS && !turn_sock->setting.qos_ignore_error) {
pj_turn_sock_destroy(turn_sock);
return;
}
/* Apply socket buffer size */
if (turn_sock->setting.so_rcvbuf_size > 0) {
//.........这里部分代码省略.........