Changeset 592 for pjproject/trunk/pjlib/src/pj/ioqueue_epoll.c
- Timestamp:
- Jul 8, 2006 7:46:43 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.