Changeset 1879 for pjproject/trunk/pjnath/src/pjturn-srv/main.c
- Timestamp:
- Mar 20, 2008 4:32:06 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjturn-srv/main.c
r1869 r1879 22 22 #define REALM "pjsip.org" 23 23 24 static pj_caching_pool g_cp; 25 24 26 int err(const char *title, pj_status_t status) 25 27 { … … 31 33 } 32 34 35 static void dump_status(pj_turn_srv *srv) 36 { 37 char addr[80]; 38 pj_hash_iterator_t itbuf, *it; 39 pj_time_val now; 40 unsigned i; 41 42 for (i=0; i<srv->core.lis_cnt; ++i) { 43 pj_turn_listener *lis = srv->core.listener[i]; 44 printf("Server address : %s\n", lis->info); 45 } 46 47 printf("Worker threads : %d\n", srv->core.thread_cnt); 48 printf("Total mem usage: %d.%03dMB\n", g_cp.used_size / 1000000, 49 (g_cp.used_size % 1000000)/1000); 50 printf("UDP port range : %u %u %u (next/min/max)\n", srv->ports.next_udp, 51 srv->ports.min_udp, srv->ports.max_udp); 52 printf("TCP port range : %u %u %u (next/min/max)\n", srv->ports.next_tcp, 53 srv->ports.min_tcp, srv->ports.max_tcp); 54 printf("Clients # : %u\n", pj_hash_count(srv->tables.alloc)); 55 56 puts(""); 57 58 if (pj_hash_count(srv->tables.alloc)==0) { 59 return; 60 } 61 62 puts("# Client addr. Alloc addr. Username Lftm Expy #prm #chl"); 63 puts("------------------------------------------------------------------------------"); 64 65 pj_gettimeofday(&now); 66 67 it = pj_hash_first(srv->tables.alloc, &itbuf); 68 i=1; 69 while (it) { 70 pj_turn_allocation *alloc = (pj_turn_allocation*) 71 pj_hash_this(srv->tables.alloc, it); 72 printf("%-3d %-22s %-22s %-8.*s %-4d %-4d %-4d %-4d\n", 73 i, 74 alloc->info, 75 pj_sockaddr_print(&alloc->relay.hkey.addr, addr, sizeof(addr), 3), 76 (int)alloc->cred.data.static_cred.username.slen, 77 (int)alloc->cred.data.static_cred.username.ptr, 78 alloc->relay.lifetime, 79 alloc->relay.expiry.sec - now.sec, 80 pj_hash_count(alloc->peer_table), 81 pj_hash_count(alloc->ch_table)); 82 it = pj_hash_next(srv->tables.alloc, it); 83 ++i; 84 } 85 } 86 87 static void menu(void) 88 { 89 puts(""); 90 puts("Menu:"); 91 puts(" d Dump status"); 92 puts(" q Quit"); 93 printf(">> "); 94 } 95 96 static void console_main(pj_turn_srv *srv) 97 { 98 pj_bool_t quit = PJ_FALSE; 99 100 while (!quit) { 101 char line[10]; 102 103 menu(); 104 105 fgets(line, sizeof(line), stdin); 106 107 switch (line[0]) { 108 case 'd': 109 dump_status(srv); 110 break; 111 case 'q': 112 quit = PJ_TRUE; 113 break; 114 } 115 } 116 } 117 33 118 int main() 34 119 { 35 pj_caching_pool cp;36 120 pj_turn_srv *srv; 37 121 pj_turn_listener *listener; … … 45 129 pjnath_init(); 46 130 47 pj_caching_pool_init(& cp, NULL, 0);131 pj_caching_pool_init(&g_cp, NULL, 0); 48 132 49 133 pj_turn_auth_init(REALM); 50 134 51 status = pj_turn_srv_create(& cp.factory, &srv);135 status = pj_turn_srv_create(&g_cp.factory, &srv); 52 136 if (status != PJ_SUCCESS) 53 137 return err("Error creating server", status); … … 63 147 64 148 puts("Server is running"); 65 puts("Press <ENTER> to quit");66 149 67 { 68 char line[10]; 69 fgets(line, sizeof(line), stdin); 70 } 150 console_main(srv); 71 151 72 152 pj_turn_srv_destroy(srv); 73 pj_caching_pool_destroy(& cp);153 pj_caching_pool_destroy(&g_cp); 74 154 pj_shutdown(); 75 155
Note: See TracChangeset
for help on using the changeset viewer.