Changeset 1495 for pjproject/trunk/pjnath/src/pjstun-client/client_main.c
- Timestamp:
- Oct 12, 2007 12:14:27 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjstun-client/client_main.c
r1405 r1495 50 50 char data_buf[256]; 51 51 char *data; 52 pj_bool_t detect; 53 pj_status_t detect_result; 52 54 } g; 53 55 … … 153 155 154 156 pj_timer_heap_poll(g.th, NULL); 157 pj_ioqueue_poll(g.stun_config.ioqueue, &timeout); 155 158 156 159 PJ_FD_ZERO(&readset); … … 331 334 } 332 335 336 status = pj_ioqueue_create(g.pool, 16, &g.stun_config.ioqueue); 337 if (status != PJ_SUCCESS) 338 return status; 339 333 340 status = pj_thread_create(g.pool, "stun", &worker_thread, NULL, 334 341 0, 0, &g.thread); … … 588 595 } 589 596 597 598 static void nat_detect_cb(void *user_data, 599 const pj_stun_nat_detect_result *res) 600 { 601 g.detect_result = res->status; 602 603 if (res->status == PJ_SUCCESS) { 604 PJ_LOG(3,(THIS_FILE, "NAT successfully detected as %s", res->nat_type_name)); 605 } else { 606 PJ_LOG(2,(THIS_FILE, "Error detecting NAT type: %s", res->status_text)); 607 } 608 } 609 610 static pj_status_t perform_detection() 611 { 612 pj_status_t status; 613 614 g.detect_result = PJ_EPENDING; 615 status = pj_stun_detect_nat_type(&g.srv_addr, &g.stun_config, NULL, 616 &nat_detect_cb); 617 if (status != PJ_SUCCESS) 618 return status; 619 620 while (g.detect_result == PJ_EPENDING) 621 pj_thread_sleep(100); 622 623 status = g.detect_result; 624 625 return status; 626 } 627 628 590 629 static void menu(void) 591 630 { 592 631 puts("Menu:"); 632 puts(" d Perform NAT detection"); 593 633 printf(" pr Set peer address (currently %s:%d)\n", 594 634 pj_inet_ntoa(g.peer_addr.sin_addr), pj_ntohs(g.peer_addr.sin_port)); … … 617 657 fgets(input, sizeof(input), stdin); 618 658 619 if (0) { 659 if (input[0] == 'd' && (input[1]=='\r' || input[1]=='\n')) { 660 661 perform_detection(); 620 662 621 663 } else if (input[0]=='d' && input[1]=='t') { … … 664 706 puts(""); 665 707 puts("and OPTIONS:"); 708 puts(" --detect, -d Perform NAT type detection first"); 666 709 puts(" --realm, -r Set realm of the credential"); 667 710 puts(" --username, -u Set username of the credential"); … … 677 720 { 678 721 struct pj_getopt_option long_options[] = { 722 { "detect", 0, 0, 'd'}, 679 723 { "realm", 1, 0, 'r'}, 680 724 { "username", 1, 0, 'u'}, … … 693 737 pj_ansi_strcpy(g.data, "Hello world"); 694 738 695 while((c=pj_getopt_long(argc,argv, "r:u:p:N: hF", long_options, &opt_id))!=-1) {739 while((c=pj_getopt_long(argc,argv, "r:u:p:N:dhF", long_options, &opt_id))!=-1) { 696 740 switch (c) { 741 case 'd': 742 g.detect = PJ_TRUE; 743 break; 697 744 case 'r': 698 745 o.realm = pj_optarg; … … 744 791 goto on_return; 745 792 793 if (g.detect) { 794 status = perform_detection(); 795 if (status != PJ_SUCCESS) 796 goto on_return; 797 } 798 746 799 console_main(); 747 800
Note: See TracChangeset
for help on using the changeset viewer.