- Timestamp:
- Jul 8, 2006 7:46:43 PM (18 years ago)
- Location:
- pjproject/trunk/pjlib/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/ioqueue_common_abs.c
r582 r592 197 197 h->connecting = 0; 198 198 199 ioqueue_remove_from_set(ioqueue, h ->fd, WRITEABLE_EVENT);200 ioqueue_remove_from_set(ioqueue, h ->fd, EXCEPTION_EVENT);199 ioqueue_remove_from_set(ioqueue, h, WRITEABLE_EVENT); 200 ioqueue_remove_from_set(ioqueue, h, EXCEPTION_EVENT); 201 201 202 202 … … 273 273 274 274 if (pj_list_empty(&h->write_list)) 275 ioqueue_remove_from_set(ioqueue, h ->fd, WRITEABLE_EVENT);275 ioqueue_remove_from_set(ioqueue, h, WRITEABLE_EVENT); 276 276 277 277 } … … 326 326 /* Clear operation if there's no more data to send. */ 327 327 if (pj_list_empty(&h->write_list)) 328 ioqueue_remove_from_set(ioqueue, h ->fd, WRITEABLE_EVENT);328 ioqueue_remove_from_set(ioqueue, h, WRITEABLE_EVENT); 329 329 330 330 } … … 379 379 /* Clear bit in fdset if there is no more pending accept */ 380 380 if (pj_list_empty(&h->accept_list)) 381 ioqueue_remove_from_set(ioqueue, h ->fd, READABLE_EVENT);381 ioqueue_remove_from_set(ioqueue, h, READABLE_EVENT); 382 382 383 383 rc=pj_sock_accept(h->fd, accept_op->accept_fd, … … 412 412 /* Clear fdset if there is no pending read. */ 413 413 if (pj_list_empty(&h->read_list)) 414 ioqueue_remove_from_set(ioqueue, h ->fd, READABLE_EVENT);414 ioqueue_remove_from_set(ioqueue, h, READABLE_EVENT); 415 415 416 416 bytes_read = read_op->size; … … 519 519 h->connecting = 0; 520 520 521 ioqueue_remove_from_set(ioqueue, h ->fd, WRITEABLE_EVENT);522 ioqueue_remove_from_set(ioqueue, h ->fd, EXCEPTION_EVENT);521 ioqueue_remove_from_set(ioqueue, h, WRITEABLE_EVENT); 522 ioqueue_remove_from_set(ioqueue, h, EXCEPTION_EVENT); 523 523 524 524 pj_mutex_unlock(h->mutex); … … 586 586 pj_mutex_lock(key->mutex); 587 587 pj_list_insert_before(&key->read_list, read_op); 588 ioqueue_add_to_set(key->ioqueue, key ->fd, READABLE_EVENT);588 ioqueue_add_to_set(key->ioqueue, key, READABLE_EVENT); 589 589 pj_mutex_unlock(key->mutex); 590 590 … … 654 654 pj_mutex_lock(key->mutex); 655 655 pj_list_insert_before(&key->read_list, read_op); 656 ioqueue_add_to_set(key->ioqueue, key ->fd, READABLE_EVENT);656 ioqueue_add_to_set(key->ioqueue, key, READABLE_EVENT); 657 657 pj_mutex_unlock(key->mutex); 658 658 … … 760 760 pj_mutex_lock(key->mutex); 761 761 pj_list_insert_before(&key->write_list, write_op); 762 ioqueue_add_to_set(key->ioqueue, key ->fd, WRITEABLE_EVENT);762 ioqueue_add_to_set(key->ioqueue, key, WRITEABLE_EVENT); 763 763 pj_mutex_unlock(key->mutex); 764 764 … … 828 828 status = status; 829 829 } 830 PJ_LOG(3,(THIS_FILE, "pending write operation!!")); 830 831 } 831 832 … … 877 878 pj_mutex_lock(key->mutex); 878 879 pj_list_insert_before(&key->write_list, write_op); 879 ioqueue_add_to_set(key->ioqueue, key ->fd, WRITEABLE_EVENT);880 ioqueue_add_to_set(key->ioqueue, key, WRITEABLE_EVENT); 880 881 pj_mutex_unlock(key->mutex); 881 882 … … 946 947 pj_mutex_lock(key->mutex); 947 948 pj_list_insert_before(&key->accept_list, accept_op); 948 ioqueue_add_to_set(key->ioqueue, key ->fd, READABLE_EVENT);949 ioqueue_add_to_set(key->ioqueue, key, READABLE_EVENT); 949 950 pj_mutex_unlock(key->mutex); 950 951 … … 982 983 pj_mutex_lock(key->mutex); 983 984 key->connecting = PJ_TRUE; 984 ioqueue_add_to_set(key->ioqueue, key ->fd, WRITEABLE_EVENT);985 ioqueue_add_to_set(key->ioqueue, key ->fd, EXCEPTION_EVENT);985 ioqueue_add_to_set(key->ioqueue, key, WRITEABLE_EVENT); 986 ioqueue_add_to_set(key->ioqueue, key, EXCEPTION_EVENT); 986 987 pj_mutex_unlock(key->mutex); 987 988 return PJ_EPENDING; -
pjproject/trunk/pjlib/src/pj/ioqueue_common_abs.h
r365 r592 129 129 130 130 static void ioqueue_add_to_set( pj_ioqueue_t *ioqueue, 131 pj_ sock_t fd,131 pj_ioqueue_key_t *key, 132 132 enum ioqueue_event_type event_type ); 133 133 static void ioqueue_remove_from_set( pj_ioqueue_t *ioqueue, 134 pj_ sock_t fd,134 pj_ioqueue_key_t *key, 135 135 enum ioqueue_event_type event_type); 136 136 -
pjproject/trunk/pjlib/src/pj/ioqueue_epoll.c
r590 r592 142 142 #define THIS_FILE "ioq_epoll" 143 143 144 #define TRACE_(expr) PJ_LOG(3,expr)145 //#define TRACE_(expr)144 //#define TRACE_(expr) PJ_LOG(3,expr) 145 #define TRACE_(expr) 146 146 147 147 /* … … 156 156 { 157 157 DECLARE_COMMON_KEY 158 }; 159 160 struct queue 161 { 162 pj_ioqueue_key_t *key; 163 enum ioqueue_event_type event_type; 158 164 }; 159 165 … … 168 174 pj_ioqueue_key_t hlist; 169 175 int epfd; 176 struct epoll_event *events; 177 struct queue *queue; 170 178 }; 171 179 … … 230 238 } 231 239 240 ioqueue->events = pj_pool_calloc(pool, max_fd, sizeof(struct epoll_event)); 241 PJ_ASSERT_RETURN(ioqueue->events != NULL, PJ_ENOMEM); 242 243 ioqueue->queue = pj_pool_calloc(pool, max_fd, sizeof(struct queue)); 244 PJ_ASSERT_RETURN(ioqueue->queue != NULL, PJ_ENOMEM); 245 232 246 PJ_LOG(4, ("pjlib", "epoll I/O Queue created (%p)", ioqueue)); 233 247 … … 306 320 307 321 /* os_epoll_ctl. */ 308 ev.events = EPOLLIN | EPOLL OUT | EPOLLERR;322 ev.events = EPOLLIN | EPOLLERR; 309 323 ev.epoll_data = (epoll_data_type)key; 310 324 status = os_epoll_ctl(ioqueue->epfd, EPOLL_CTL_ADD, sock, &ev); … … 323 337 ++ioqueue->count; 324 338 339 //TRACE_((THIS_FILE, "socket registered, count=%d", ioqueue->count)); 340 325 341 on_return: 326 342 *p_key = key; … … 374 390 */ 375 391 static void ioqueue_remove_from_set( pj_ioqueue_t *ioqueue, 376 pj_ sock_t fd,392 pj_ioqueue_key_t *key, 377 393 enum ioqueue_event_type event_type) 378 394 { 395 if (event_type == WRITEABLE_EVENT) { 396 struct epoll_event ev; 397 398 ev.events = EPOLLIN | EPOLLERR; 399 ev.epoll_data = (epoll_data_type)key; 400 os_epoll_ctl( ioqueue->epfd, EPOLL_CTL_MOD, key->fd, &ev); 401 } 379 402 } 380 403 … … 386 409 */ 387 410 static void ioqueue_add_to_set( pj_ioqueue_t *ioqueue, 388 pj_ sock_t fd,411 pj_ioqueue_key_t *key, 389 412 enum ioqueue_event_type event_type ) 390 413 { 414 if (event_type == WRITEABLE_EVENT) { 415 struct epoll_event ev; 416 417 ev.events = EPOLLIN | EPOLLOUT | EPOLLERR; 418 ev.epoll_data = (epoll_data_type)key; 419 os_epoll_ctl( ioqueue->epfd, EPOLL_CTL_MOD, key->fd, &ev); 420 } 391 421 } 392 422 … … 398 428 { 399 429 int i, count, processed; 400 struct epoll_event events[PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL];401 430 int msec; 402 struct queue { 403 pj_ioqueue_key_t *key; 404 enum ioqueue_event_type event_type; 405 } queue[PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL]; 431 struct epoll_event *events = ioqueue->events; 432 struct queue *queue = ioqueue->queue; 433 pj_timestamp t1, t2; 406 434 407 435 PJ_CHECK_STACK(); 408 436 409 437 msec = timeout ? PJ_TIME_VAL_MSEC(*timeout) : 9000; 410 411 count = os_epoll_wait( ioqueue->epfd, events, PJ_ARRAY_SIZE(events), msec); 412 if (count == 0) 438 439 TRACE_((THIS_FILE, "start os_epoll_wait, msec=%d", msec)); 440 pj_get_timestamp(&t1); 441 442 count = os_epoll_wait( ioqueue->epfd, events, ioqueue->max, msec); 443 if (count == 0) { 444 TRACE_((THIS_FILE, "os_epoll_wait timed out")); 413 445 return count; 414 else if (count < 0) 446 } 447 else if (count < 0) { 448 TRACE_((THIS_FILE, "os_epoll_wait error")); 415 449 return -pj_get_netos_error(); 450 } 451 452 pj_get_timestamp(&t2); 453 TRACE_((THIS_FILE, "os_epoll_wait returns %d, time=%d usec", 454 count, pj_elapsed_usec(&t1, &t2))); 416 455 417 456 /* Lock ioqueue. */ … … 421 460 pj_ioqueue_key_t *h = (pj_ioqueue_key_t*)(epoll_data_type) 422 461 events[i].epoll_data; 462 463 TRACE_((THIS_FILE, "event %d: events=%d", i, events[i].events)); 423 464 424 465 /* … … 487 528 pj_thread_sleep(msec); 488 529 } 530 531 pj_get_timestamp(&t1); 532 TRACE_((THIS_FILE, "ioqueue_poll() returns %d, time=%d usec", 533 processed, pj_elapsed_usec(&t2, &t1))); 534 489 535 return processed; 490 536 } -
pjproject/trunk/pjlib/src/pj/ioqueue_select.c
r433 r592 543 543 */ 544 544 static void ioqueue_remove_from_set( pj_ioqueue_t *ioqueue, 545 pj_ sock_t fd,545 pj_ioqueue_key_t *key, 546 546 enum ioqueue_event_type event_type) 547 547 { … … 549 549 550 550 if (event_type == READABLE_EVENT) 551 PJ_FD_CLR((pj_sock_t) fd, &ioqueue->rfdset);551 PJ_FD_CLR((pj_sock_t)key->fd, &ioqueue->rfdset); 552 552 else if (event_type == WRITEABLE_EVENT) 553 PJ_FD_CLR((pj_sock_t) fd, &ioqueue->wfdset);553 PJ_FD_CLR((pj_sock_t)key->fd, &ioqueue->wfdset); 554 554 else if (event_type == EXCEPTION_EVENT) 555 PJ_FD_CLR((pj_sock_t) fd, &ioqueue->xfdset);555 PJ_FD_CLR((pj_sock_t)key->fd, &ioqueue->xfdset); 556 556 else 557 557 pj_assert(0); … … 567 567 */ 568 568 static void ioqueue_add_to_set( pj_ioqueue_t *ioqueue, 569 pj_ sock_t fd,569 pj_ioqueue_key_t *key, 570 570 enum ioqueue_event_type event_type ) 571 571 { … … 573 573 574 574 if (event_type == READABLE_EVENT) 575 PJ_FD_SET((pj_sock_t) fd, &ioqueue->rfdset);575 PJ_FD_SET((pj_sock_t)key->fd, &ioqueue->rfdset); 576 576 else if (event_type == WRITEABLE_EVENT) 577 PJ_FD_SET((pj_sock_t) fd, &ioqueue->wfdset);577 PJ_FD_SET((pj_sock_t)key->fd, &ioqueue->wfdset); 578 578 else if (event_type == EXCEPTION_EVENT) 579 PJ_FD_SET((pj_sock_t) fd, &ioqueue->xfdset);579 PJ_FD_SET((pj_sock_t)key->fd, &ioqueue->xfdset); 580 580 else 581 581 pj_assert(0); -
pjproject/trunk/pjlib/src/pjlib-test/ioq_tcp.c
r559 r592 39 39 40 40 #define THIS_FILE "test_tcp" 41 #define PORT 5000042 41 #define NON_EXISTANT_PORT 50123 43 42 #define LOOP 100 … … 258 257 259 258 // Bind server socket. 260 memset(&addr, 0, sizeof(addr)); 261 addr.sin_family = PJ_AF_INET; 262 addr.sin_port = pj_htons(PORT); 263 if (pj_sock_bind(ssock, &addr, sizeof(addr))) { 259 pj_sockaddr_in_init(&addr, 0, 0); 260 if ((rc=pj_sock_bind(ssock, &addr, sizeof(addr))) != 0 ) { 264 261 app_perror("...bind error", rc); 265 262 status=-10; goto on_error; 266 263 } 264 265 // Get server address. 266 client_addr_len = sizeof(addr); 267 rc = pj_sock_getsockname(ssock, &addr, &client_addr_len); 268 if (rc != PJ_SUCCESS) { 269 app_perror("...ERROR in pj_sock_getsockname()", rc); 270 status=-15; goto on_error; 271 } 272 addr.sin_addr = pj_inet_addr(pj_cstr(&s, "127.0.0.1")); 267 273 268 274 // Create I/O Queue. … … 302 308 ++pending_op; 303 309 } 304 305 // Initialize remote address.306 memset(&addr, 0, sizeof(addr));307 addr.sin_family = PJ_AF_INET;308 addr.sin_port = pj_htons(PORT);309 addr.sin_addr = pj_inet_addr(pj_cstr(&s, "127.0.0.1"));310 310 311 311 // Client socket connect() … … 462 462 463 463 // Initialize remote address. 464 memset(&addr, 0, sizeof(addr)); 465 addr.sin_family = PJ_AF_INET; 466 addr.sin_port = pj_htons(NON_EXISTANT_PORT); 467 addr.sin_addr = pj_inet_addr(pj_cstr(&s, "127.0.0.1")); 464 pj_sockaddr_in_init(&addr, pj_cstr(&s, "127.0.0.1"), NON_EXISTANT_PORT); 468 465 469 466 // Client socket connect() -
pjproject/trunk/pjlib/src/pjlib-test/ioq_udp.c
r590 r592 41 41 #define THIS_FILE "test_udp" 42 42 #define PORT 51233 43 #define LOOP 10043 #define LOOP 2 44 44 ///#define LOOP 2 45 45 #define BUF_MIN_SIZE 32 … … 818 818 int bufsize, sock_count; 819 819 820 goto pass1;820 //goto pass1; 821 821 822 822 PJ_LOG(3, (THIS_FILE, "...compliance test (%s)", pj_ioqueue_name())); … … 837 837 } 838 838 839 //return 0; 840 839 841 PJ_LOG(4, (THIS_FILE, "...benchmarking different buffer size:")); 840 842 PJ_LOG(4, (THIS_FILE, "... note: buf=bytes sent, fds=# of fds, " … … 848 850 PJ_LOG(3, (THIS_FILE, "...=====================================")); 849 851 850 goto pass2;852 //goto pass2; 851 853 852 854 for (bufsize=BUF_MIN_SIZE; bufsize <= BUF_MAX_SIZE; bufsize *= 2) { … … 860 862 sock_count *= 2) 861 863 { 862 PJ_LOG(3,(THIS_FILE, "...testing with %d fds", sock_count));864 //PJ_LOG(3,(THIS_FILE, "...testing with %d fds", sock_count)); 863 865 if ((status=bench_test(bufsize, sock_count-2)) != 0) 864 866 return status; -
pjproject/trunk/pjlib/src/pjlib-test/test.h
r590 r592 25 25 #define GROUP_OS 0 26 26 #define GROUP_DATA_STRUCTURE 0 27 #define GROUP_NETWORK 027 #define GROUP_NETWORK 1 28 28 #define GROUP_FILE 0 29 29 … … 46 46 #define INCLUDE_SOCK_PERF_TEST GROUP_NETWORK 47 47 #define INCLUDE_SELECT_TEST GROUP_NETWORK 48 #define INCLUDE_UDP_IOQUEUE_TEST 1 //GROUP_NETWORK48 #define INCLUDE_UDP_IOQUEUE_TEST GROUP_NETWORK 49 49 #define INCLUDE_TCP_IOQUEUE_TEST GROUP_NETWORK 50 50 #define INCLUDE_IOQUEUE_PERF_TEST GROUP_NETWORK
Note: See TracChangeset
for help on using the changeset viewer.