Changeset 1405 for pjproject/trunk/pjlib/src/pjlib-test/ioq_udp.c
- Timestamp:
- Jul 20, 2007 8:08:30 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pjlib-test/ioq_udp.c
r1235 r1405 134 134 char *send_buf, *recv_buf; 135 135 pj_ioqueue_t *ioque = NULL; 136 pj_ioqueue_key_t *skey , *ckey;136 pj_ioqueue_key_t *skey = NULL, *ckey = NULL; 137 137 pj_ioqueue_op_key_t read_op, write_op; 138 138 int bufsize = BUF_MIN_SIZE; … … 153 153 // Allocate sockets for sending and receiving. 154 154 TRACE_("creating sockets..."); 155 rc = pj_sock_socket( PJ_AF_INET, PJ_SOCK_DGRAM, 0, &ssock);155 rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &ssock); 156 156 if (rc==PJ_SUCCESS) 157 rc = pj_sock_socket( PJ_AF_INET, PJ_SOCK_DGRAM, 0, &csock);157 rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &csock); 158 158 else 159 159 csock = PJ_INVALID_SOCKET; … … 166 166 TRACE_("bind socket..."); 167 167 pj_bzero(&addr, sizeof(addr)); 168 addr.sin_family = PJ_AF_INET;168 addr.sin_family = pj_AF_INET(); 169 169 addr.sin_port = pj_htons(PORT); 170 170 if (pj_sock_bind(ssock, &addr, sizeof(addr))) { … … 259 259 260 260 TRACE_("poll..."); 261 #ifdef PJ_SYMBIAN 262 rc = pj_symbianos_poll(-1, 5000); 263 #else 261 264 rc = pj_ioqueue_poll(ioque, &timeout); 265 #endif 262 266 263 267 if (rc == 0) { … … 286 290 status=-68; goto on_error; 287 291 } 288 if (addr.sin_family != PJ_AF_INET) {292 if (addr.sin_family != pj_AF_INET()) { 289 293 status=-69; goto on_error; 290 294 } … … 313 317 314 318 on_error: 315 if (ssock) 319 if (skey) 320 pj_ioqueue_unregister(skey); 321 else if (ssock != -1) 316 322 pj_sock_close(ssock); 317 if (csock) 323 324 if (ckey) 325 pj_ioqueue_unregister(ckey); 326 else if (csock != -1) 318 327 pj_sock_close(csock); 328 319 329 if (ioque != NULL) 320 330 pj_ioqueue_destroy(ioque); … … 373 383 374 384 /* Create sender socket */ 375 status = app_socket( PJ_AF_INET, PJ_SOCK_DGRAM, 0, SPORT, &ssock);385 status = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, SPORT, &ssock); 376 386 if (status != PJ_SUCCESS) { 377 387 app_perror("Error initializing socket", status); … … 380 390 381 391 /* Create receiver socket. */ 382 status = app_socket( PJ_AF_INET, PJ_SOCK_DGRAM, 0, RPORT, &rsock);392 status = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, RPORT, &rsock); 383 393 if (status != PJ_SUCCESS) { 384 394 app_perror("Error initializing socket", status); … … 436 446 /* Check if packet is received. */ 437 447 timeout.sec = 1; timeout.msec = 0; 448 #ifdef PJ_SYMBIAN 449 pj_symbianos_poll(-1, 1000); 450 #else 438 451 pj_ioqueue_poll(ioqueue, &timeout); 452 #endif 439 453 440 454 if (packet_cnt != 1) { … … 470 484 471 485 /* Poll ioqueue. */ 486 #ifdef PJ_SYMBIAN 487 pj_symbianos_poll(-1, 1000); 488 #else 472 489 timeout.sec = 1; timeout.msec = 0; 473 490 pj_ioqueue_poll(ioqueue, &timeout); 491 #endif 474 492 475 493 /* Must NOT receive any packets after socket is closed! */ … … 525 543 for (count=0; count<MAX; ++count) { 526 544 sock[count] = PJ_INVALID_SOCKET; 527 rc = pj_sock_socket( PJ_AF_INET, PJ_SOCK_DGRAM, 0, &sock[count]);545 rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &sock[count]); 528 546 if (rc != PJ_SUCCESS || sock[count] == PJ_INVALID_SOCKET) { 529 547 PJ_LOG(3,(THIS_FILE, "....unable to create %d-th socket, rc=%d", … … 592 610 char *send_buf, *recv_buf; 593 611 pj_ioqueue_t *ioque = NULL; 594 pj_ioqueue_key_t *skey, *ckey, *key ;612 pj_ioqueue_key_t *skey, *ckey, *keys[SOCK_INACTIVE_MAX+2]; 595 613 pj_timestamp t1, t2, t_elapsed; 596 614 int rc=0, i; /* i must be signed */ … … 608 626 609 627 // Allocate sockets for sending and receiving. 610 rc = pj_sock_socket( PJ_AF_INET, PJ_SOCK_DGRAM, 0, &ssock);628 rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &ssock); 611 629 if (rc == PJ_SUCCESS) { 612 rc = pj_sock_socket( PJ_AF_INET, PJ_SOCK_DGRAM, 0, &csock);630 rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &csock); 613 631 } else 614 632 csock = PJ_INVALID_SOCKET; … … 620 638 // Bind server socket. 621 639 pj_bzero(&addr, sizeof(addr)); 622 addr.sin_family = PJ_AF_INET;640 addr.sin_family = pj_AF_INET(); 623 641 addr.sin_port = pj_htons(PORT); 624 642 if (pj_sock_bind(ssock, &addr, sizeof(addr))) … … 641 659 inactive_sock_count*sizeof(pj_ioqueue_op_key_t)); 642 660 pj_bzero(&addr, sizeof(addr)); 643 addr.sin_family = PJ_AF_INET;661 addr.sin_family = pj_AF_INET(); 644 662 for (i=0; i<inactive_sock_count; ++i) { 645 663 pj_ssize_t bytes; 646 664 647 rc = pj_sock_socket( PJ_AF_INET, PJ_SOCK_DGRAM, 0, &inactive_sock[i]);665 rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &inactive_sock[i]); 648 666 if (rc != PJ_SUCCESS || inactive_sock[i] < 0) { 649 667 app_perror("...error: pj_sock_socket()", rc); … … 657 675 } 658 676 rc = pj_ioqueue_register_sock(pool, ioque, inactive_sock[i], 659 NULL, &test_cb, &key );677 NULL, &test_cb, &keys[i]); 660 678 if (rc != PJ_SUCCESS) { 661 679 pj_sock_close(inactive_sock[i]); … … 666 684 } 667 685 bytes = bufsize; 668 rc = pj_ioqueue_recv(key , &inactive_read_op[i], recv_buf, &bytes, 0);686 rc = pj_ioqueue_recv(keys[i], &inactive_read_op[i], recv_buf, &bytes, 0); 669 687 if (rc != PJ_EPENDING) { 670 688 pj_sock_close(inactive_sock[i]); … … 736 754 do { 737 755 pj_time_val timeout = { 1, 0 }; 756 #ifdef PJ_SYMBIAN 757 rc = pj_symbianos_poll(-1, 1000); 758 #else 738 759 rc = pj_ioqueue_poll(ioque, &timeout); 760 #endif 739 761 TRACE__((THIS_FILE, " poll rc=%d", rc)); 740 762 } while (rc >= 0 && callback_read_key != skey); … … 761 783 do { 762 784 pj_time_val timeout = { 0, 10 }; 785 #ifdef PJ_SYMBIAN 786 rc = pj_symbianos_poll(-1, 100); 787 #else 763 788 rc = pj_ioqueue_poll(ioque, &timeout); 789 #endif 764 790 } while (rc>0); 765 791 … … 785 811 // Cleaning up. 786 812 for (i=inactive_sock_count-1; i>=0; --i) { 787 pj_ sock_close(inactive_sock[i]);788 } 789 790 pj_ sock_close(ssock);791 pj_ sock_close(csock);813 pj_ioqueue_unregister(keys[i]); 814 } 815 816 pj_ioqueue_unregister(skey); 817 pj_ioqueue_unregister(ckey); 792 818 793 819
Note: See TracChangeset
for help on using the changeset viewer.