正在显示
3 个修改的文件
包含
129 行增加
和
155 行删除
@@ -152,7 +152,6 @@ static struct _st_epolldata { | @@ -152,7 +152,6 @@ static struct _st_epolldata { | ||
152 | 152 | ||
153 | _st_eventsys_t *_st_eventsys = NULL; | 153 | _st_eventsys_t *_st_eventsys = NULL; |
154 | 154 | ||
155 | - | ||
156 | /***************************************** | 155 | /***************************************** |
157 | * select event system | 156 | * select event system |
158 | */ | 157 | */ |
@@ -160,8 +159,9 @@ _st_eventsys_t *_st_eventsys = NULL; | @@ -160,8 +159,9 @@ _st_eventsys_t *_st_eventsys = NULL; | ||
160 | ST_HIDDEN int _st_select_init(void) | 159 | ST_HIDDEN int _st_select_init(void) |
161 | { | 160 | { |
162 | _st_select_data = (struct _st_seldata *) malloc(sizeof(*_st_select_data)); | 161 | _st_select_data = (struct _st_seldata *) malloc(sizeof(*_st_select_data)); |
163 | - if (!_st_select_data) | 162 | + if (!_st_select_data) { |
164 | return -1; | 163 | return -1; |
164 | + } | ||
165 | 165 | ||
166 | memset(_st_select_data, 0, sizeof(*_st_select_data)); | 166 | memset(_st_select_data, 0, sizeof(*_st_select_data)); |
167 | _st_select_data->maxfd = -1; | 167 | _st_select_data->maxfd = -1; |
@@ -176,8 +176,7 @@ ST_HIDDEN int _st_select_pollset_add(struct pollfd *pds, int npds) | @@ -176,8 +176,7 @@ ST_HIDDEN int _st_select_pollset_add(struct pollfd *pds, int npds) | ||
176 | 176 | ||
177 | /* Do checks up front */ | 177 | /* Do checks up front */ |
178 | for (pd = pds; pd < epd; pd++) { | 178 | for (pd = pds; pd < epd; pd++) { |
179 | - if (pd->fd < 0 || pd->fd >= FD_SETSIZE || !pd->events || | ||
180 | - (pd->events & ~(POLLIN | POLLOUT | POLLPRI))) { | 179 | + if (pd->fd < 0 || pd->fd >= FD_SETSIZE || !pd->events || (pd->events & ~(POLLIN | POLLOUT | POLLPRI))) { |
181 | errno = EINVAL; | 180 | errno = EINVAL; |
182 | return -1; | 181 | return -1; |
183 | } | 182 | } |
@@ -210,16 +209,19 @@ ST_HIDDEN void _st_select_pollset_del(struct pollfd *pds, int npds) | @@ -210,16 +209,19 @@ ST_HIDDEN void _st_select_pollset_del(struct pollfd *pds, int npds) | ||
210 | 209 | ||
211 | for (pd = pds; pd < epd; pd++) { | 210 | for (pd = pds; pd < epd; pd++) { |
212 | if (pd->events & POLLIN) { | 211 | if (pd->events & POLLIN) { |
213 | - if (--_ST_SELECT_READ_CNT(pd->fd) == 0) | 212 | + if (--_ST_SELECT_READ_CNT(pd->fd) == 0) { |
214 | FD_CLR(pd->fd, &_ST_SELECT_READ_SET); | 213 | FD_CLR(pd->fd, &_ST_SELECT_READ_SET); |
214 | + } | ||
215 | } | 215 | } |
216 | if (pd->events & POLLOUT) { | 216 | if (pd->events & POLLOUT) { |
217 | - if (--_ST_SELECT_WRITE_CNT(pd->fd) == 0) | 217 | + if (--_ST_SELECT_WRITE_CNT(pd->fd) == 0) { |
218 | FD_CLR(pd->fd, &_ST_SELECT_WRITE_SET); | 218 | FD_CLR(pd->fd, &_ST_SELECT_WRITE_SET); |
219 | + } | ||
219 | } | 220 | } |
220 | if (pd->events & POLLPRI) { | 221 | if (pd->events & POLLPRI) { |
221 | - if (--_ST_SELECT_EXCEP_CNT(pd->fd) == 0) | 222 | + if (--_ST_SELECT_EXCEP_CNT(pd->fd) == 0) { |
222 | FD_CLR(pd->fd, &_ST_SELECT_EXCEP_SET); | 223 | FD_CLR(pd->fd, &_ST_SELECT_EXCEP_SET); |
224 | + } | ||
223 | } | 225 | } |
224 | } | 226 | } |
225 | } | 227 | } |
@@ -244,8 +246,9 @@ ST_HIDDEN void _st_select_find_bad_fd(void) | @@ -244,8 +246,9 @@ ST_HIDDEN void _st_select_find_bad_fd(void) | ||
244 | for (pds = pq->pds; pds < epds; pds++) { | 246 | for (pds = pq->pds; pds < epds; pds++) { |
245 | osfd = pds->fd; | 247 | osfd = pds->fd; |
246 | pds->revents = 0; | 248 | pds->revents = 0; |
247 | - if (pds->events == 0) | 249 | + if (pds->events == 0) { |
248 | continue; | 250 | continue; |
251 | + } | ||
249 | if (fcntl(osfd, F_GETFL, 0) < 0) { | 252 | if (fcntl(osfd, F_GETFL, 0) < 0) { |
250 | pds->revents = POLLNVAL; | 253 | pds->revents = POLLNVAL; |
251 | notify = 1; | 254 | notify = 1; |
@@ -282,13 +285,15 @@ ST_HIDDEN void _st_select_find_bad_fd(void) | @@ -282,13 +285,15 @@ ST_HIDDEN void _st_select_find_bad_fd(void) | ||
282 | } | 285 | } |
283 | } | 286 | } |
284 | 287 | ||
285 | - if (pq->thread->flags & _ST_FL_ON_SLEEPQ) | 288 | + if (pq->thread->flags & _ST_FL_ON_SLEEPQ) { |
286 | _ST_DEL_SLEEPQ(pq->thread); | 289 | _ST_DEL_SLEEPQ(pq->thread); |
290 | + } | ||
287 | pq->thread->state = _ST_ST_RUNNABLE; | 291 | pq->thread->state = _ST_ST_RUNNABLE; |
288 | _ST_ADD_RUNQ(pq->thread); | 292 | _ST_ADD_RUNQ(pq->thread); |
289 | } else { | 293 | } else { |
290 | - if (_ST_SELECT_MAX_OSFD < pq_max_osfd) | 294 | + if (_ST_SELECT_MAX_OSFD < pq_max_osfd) { |
291 | _ST_SELECT_MAX_OSFD = pq_max_osfd; | 295 | _ST_SELECT_MAX_OSFD = pq_max_osfd; |
296 | + } | ||
292 | } | 297 | } |
293 | } | 298 | } |
294 | } | 299 | } |
@@ -320,8 +325,7 @@ ST_HIDDEN void _st_select_dispatch(void) | @@ -320,8 +325,7 @@ ST_HIDDEN void _st_select_dispatch(void) | ||
320 | if (_ST_SLEEPQ == NULL) { | 325 | if (_ST_SLEEPQ == NULL) { |
321 | tvp = NULL; | 326 | tvp = NULL; |
322 | } else { | 327 | } else { |
323 | - min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 : | ||
324 | - (_ST_SLEEPQ->due - _ST_LAST_CLOCK); | 328 | + min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 : (_ST_SLEEPQ->due - _ST_LAST_CLOCK); |
325 | timeout.tv_sec = (int) (min_timeout / 1000000); | 329 | timeout.tv_sec = (int) (min_timeout / 1000000); |
326 | timeout.tv_usec = (int) (min_timeout % 1000000); | 330 | timeout.tv_usec = (int) (min_timeout % 1000000); |
327 | tvp = &timeout; | 331 | tvp = &timeout; |
@@ -387,13 +391,15 @@ ST_HIDDEN void _st_select_dispatch(void) | @@ -387,13 +391,15 @@ ST_HIDDEN void _st_select_dispatch(void) | ||
387 | } | 391 | } |
388 | } | 392 | } |
389 | 393 | ||
390 | - if (pq->thread->flags & _ST_FL_ON_SLEEPQ) | 394 | + if (pq->thread->flags & _ST_FL_ON_SLEEPQ) { |
391 | _ST_DEL_SLEEPQ(pq->thread); | 395 | _ST_DEL_SLEEPQ(pq->thread); |
396 | + } | ||
392 | pq->thread->state = _ST_ST_RUNNABLE; | 397 | pq->thread->state = _ST_ST_RUNNABLE; |
393 | _ST_ADD_RUNQ(pq->thread); | 398 | _ST_ADD_RUNQ(pq->thread); |
394 | } else { | 399 | } else { |
395 | - if (_ST_SELECT_MAX_OSFD < pq_max_osfd) | 400 | + if (_ST_SELECT_MAX_OSFD < pq_max_osfd) { |
396 | _ST_SELECT_MAX_OSFD = pq_max_osfd; | 401 | _ST_SELECT_MAX_OSFD = pq_max_osfd; |
402 | + } | ||
397 | } | 403 | } |
398 | } | 404 | } |
399 | } else if (nfd < 0) { | 405 | } else if (nfd < 0) { |
@@ -401,8 +407,9 @@ ST_HIDDEN void _st_select_dispatch(void) | @@ -401,8 +407,9 @@ ST_HIDDEN void _st_select_dispatch(void) | ||
401 | * It can happen when a thread closes file descriptor | 407 | * It can happen when a thread closes file descriptor |
402 | * that is being used by some other thread -- BAD! | 408 | * that is being used by some other thread -- BAD! |
403 | */ | 409 | */ |
404 | - if (errno == EBADF) | 410 | + if (errno == EBADF) { |
405 | _st_select_find_bad_fd(); | 411 | _st_select_find_bad_fd(); |
412 | + } | ||
406 | } | 413 | } |
407 | } | 414 | } |
408 | 415 | ||
@@ -418,8 +425,7 @@ ST_HIDDEN int _st_select_fd_new(int osfd) | @@ -418,8 +425,7 @@ ST_HIDDEN int _st_select_fd_new(int osfd) | ||
418 | 425 | ||
419 | ST_HIDDEN int _st_select_fd_close(int osfd) | 426 | ST_HIDDEN int _st_select_fd_close(int osfd) |
420 | { | 427 | { |
421 | - if (_ST_SELECT_READ_CNT(osfd) || _ST_SELECT_WRITE_CNT(osfd) || | ||
422 | - _ST_SELECT_EXCEP_CNT(osfd)) { | 428 | + if (_ST_SELECT_READ_CNT(osfd) || _ST_SELECT_WRITE_CNT(osfd) || _ST_SELECT_EXCEP_CNT(osfd)) { |
423 | errno = EBUSY; | 429 | errno = EBUSY; |
424 | return -1; | 430 | return -1; |
425 | } | 431 | } |
@@ -444,7 +450,6 @@ static _st_eventsys_t _st_select_eventsys = { | @@ -444,7 +450,6 @@ static _st_eventsys_t _st_select_eventsys = { | ||
444 | _st_select_fd_getlimit | 450 | _st_select_fd_getlimit |
445 | }; | 451 | }; |
446 | 452 | ||
447 | - | ||
448 | #ifdef MD_HAVE_POLL | 453 | #ifdef MD_HAVE_POLL |
449 | /***************************************** | 454 | /***************************************** |
450 | * poll event system | 455 | * poll event system |
@@ -453,11 +458,11 @@ static _st_eventsys_t _st_select_eventsys = { | @@ -453,11 +458,11 @@ static _st_eventsys_t _st_select_eventsys = { | ||
453 | ST_HIDDEN int _st_poll_init(void) | 458 | ST_HIDDEN int _st_poll_init(void) |
454 | { | 459 | { |
455 | _st_poll_data = (struct _st_polldata *) malloc(sizeof(*_st_poll_data)); | 460 | _st_poll_data = (struct _st_polldata *) malloc(sizeof(*_st_poll_data)); |
456 | - if (!_st_poll_data) | 461 | + if (!_st_poll_data) { |
457 | return -1; | 462 | return -1; |
463 | + } | ||
458 | 464 | ||
459 | - _ST_POLLFDS = (struct pollfd *) malloc(ST_MIN_POLLFDS_SIZE * | ||
460 | - sizeof(struct pollfd)); | 465 | + _ST_POLLFDS = (struct pollfd *) malloc(ST_MIN_POLLFDS_SIZE * sizeof(struct pollfd)); |
461 | if (!_ST_POLLFDS) { | 466 | if (!_ST_POLLFDS) { |
462 | free(_st_poll_data); | 467 | free(_st_poll_data); |
463 | _st_poll_data = NULL; | 468 | _st_poll_data = NULL; |
@@ -508,8 +513,7 @@ ST_HIDDEN void _st_poll_dispatch(void) | @@ -508,8 +513,7 @@ ST_HIDDEN void _st_poll_dispatch(void) | ||
508 | ST_ASSERT(_ST_POLL_OSFD_CNT >= 0); | 513 | ST_ASSERT(_ST_POLL_OSFD_CNT >= 0); |
509 | if (_ST_POLL_OSFD_CNT > _ST_POLLFDS_SIZE) { | 514 | if (_ST_POLL_OSFD_CNT > _ST_POLLFDS_SIZE) { |
510 | free(_ST_POLLFDS); | 515 | free(_ST_POLLFDS); |
511 | - _ST_POLLFDS = (struct pollfd *) malloc((_ST_POLL_OSFD_CNT + 10) * | ||
512 | - sizeof(struct pollfd)); | 516 | + _ST_POLLFDS = (struct pollfd *) malloc((_ST_POLL_OSFD_CNT + 10) * sizeof(struct pollfd)); |
513 | ST_ASSERT(_ST_POLLFDS != NULL); | 517 | ST_ASSERT(_ST_POLLFDS != NULL); |
514 | _ST_POLLFDS_SIZE = _ST_POLL_OSFD_CNT + 10; | 518 | _ST_POLLFDS_SIZE = _ST_POLL_OSFD_CNT + 10; |
515 | } | 519 | } |
@@ -526,8 +530,7 @@ ST_HIDDEN void _st_poll_dispatch(void) | @@ -526,8 +530,7 @@ ST_HIDDEN void _st_poll_dispatch(void) | ||
526 | if (_ST_SLEEPQ == NULL) { | 530 | if (_ST_SLEEPQ == NULL) { |
527 | timeout = -1; | 531 | timeout = -1; |
528 | } else { | 532 | } else { |
529 | - min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 : | ||
530 | - (_ST_SLEEPQ->due - _ST_LAST_CLOCK); | 533 | + min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 : (_ST_SLEEPQ->due - _ST_LAST_CLOCK); |
531 | timeout = (int) (min_timeout / 1000); | 534 | timeout = (int) (min_timeout / 1000); |
532 | } | 535 | } |
533 | 536 | ||
@@ -541,16 +544,18 @@ ST_HIDDEN void _st_poll_dispatch(void) | @@ -541,16 +544,18 @@ ST_HIDDEN void _st_poll_dispatch(void) | ||
541 | pq = _ST_POLLQUEUE_PTR(q); | 544 | pq = _ST_POLLQUEUE_PTR(q); |
542 | epds = pollfds + pq->npds; | 545 | epds = pollfds + pq->npds; |
543 | for (pds = pollfds; pds < epds; pds++) { | 546 | for (pds = pollfds; pds < epds; pds++) { |
544 | - if (pds->revents) | 547 | + if (pds->revents) { |
545 | break; | 548 | break; |
549 | + } | ||
546 | } | 550 | } |
547 | if (pds < epds) { | 551 | if (pds < epds) { |
548 | memcpy(pq->pds, pollfds, sizeof(struct pollfd) * pq->npds); | 552 | memcpy(pq->pds, pollfds, sizeof(struct pollfd) * pq->npds); |
549 | ST_REMOVE_LINK(&pq->links); | 553 | ST_REMOVE_LINK(&pq->links); |
550 | pq->on_ioq = 0; | 554 | pq->on_ioq = 0; |
551 | 555 | ||
552 | - if (pq->thread->flags & _ST_FL_ON_SLEEPQ) | 556 | + if (pq->thread->flags & _ST_FL_ON_SLEEPQ) { |
553 | _ST_DEL_SLEEPQ(pq->thread); | 557 | _ST_DEL_SLEEPQ(pq->thread); |
558 | + } | ||
554 | pq->thread->state = _ST_ST_RUNNABLE; | 559 | pq->thread->state = _ST_ST_RUNNABLE; |
555 | _ST_ADD_RUNQ(pq->thread); | 560 | _ST_ADD_RUNQ(pq->thread); |
556 | 561 | ||
@@ -609,8 +614,9 @@ ST_HIDDEN int _st_kq_init(void) | @@ -609,8 +614,9 @@ ST_HIDDEN int _st_kq_init(void) | ||
609 | int rv = 0; | 614 | int rv = 0; |
610 | 615 | ||
611 | _st_kq_data = (struct _st_kqdata *) calloc(1, sizeof(*_st_kq_data)); | 616 | _st_kq_data = (struct _st_kqdata *) calloc(1, sizeof(*_st_kq_data)); |
612 | - if (!_st_kq_data) | 617 | + if (!_st_kq_data) { |
613 | return -1; | 618 | return -1; |
619 | + } | ||
614 | 620 | ||
615 | if ((_st_kq_data->kq = kqueue()) < 0) { | 621 | if ((_st_kq_data->kq = kqueue()) < 0) { |
616 | err = errno; | 622 | err = errno; |
@@ -625,8 +631,7 @@ ST_HIDDEN int _st_kq_init(void) | @@ -625,8 +631,7 @@ ST_HIDDEN int _st_kq_init(void) | ||
625 | * FD_SETSIZE looks like good initial size. | 631 | * FD_SETSIZE looks like good initial size. |
626 | */ | 632 | */ |
627 | _st_kq_data->fd_data_size = FD_SETSIZE; | 633 | _st_kq_data->fd_data_size = FD_SETSIZE; |
628 | - _st_kq_data->fd_data = (_kq_fd_data_t *)calloc(_st_kq_data->fd_data_size, | ||
629 | - sizeof(_kq_fd_data_t)); | 634 | + _st_kq_data->fd_data = (_kq_fd_data_t *)calloc(_st_kq_data->fd_data_size, sizeof(_kq_fd_data_t)); |
630 | if (!_st_kq_data->fd_data) { | 635 | if (!_st_kq_data->fd_data) { |
631 | err = errno; | 636 | err = errno; |
632 | rv = -1; | 637 | rv = -1; |
@@ -635,14 +640,11 @@ ST_HIDDEN int _st_kq_init(void) | @@ -635,14 +640,11 @@ ST_HIDDEN int _st_kq_init(void) | ||
635 | 640 | ||
636 | /* Allocate event lists */ | 641 | /* Allocate event lists */ |
637 | _st_kq_data->evtlist_size = ST_KQ_MIN_EVTLIST_SIZE; | 642 | _st_kq_data->evtlist_size = ST_KQ_MIN_EVTLIST_SIZE; |
638 | - _st_kq_data->evtlist = (struct kevent *)malloc(_st_kq_data->evtlist_size * | ||
639 | - sizeof(struct kevent)); | 643 | + _st_kq_data->evtlist = (struct kevent *)malloc(_st_kq_data->evtlist_size * sizeof(struct kevent)); |
640 | _st_kq_data->addlist_size = ST_KQ_MIN_EVTLIST_SIZE; | 644 | _st_kq_data->addlist_size = ST_KQ_MIN_EVTLIST_SIZE; |
641 | - _st_kq_data->addlist = (struct kevent *)malloc(_st_kq_data->addlist_size * | ||
642 | - sizeof(struct kevent)); | 645 | + _st_kq_data->addlist = (struct kevent *)malloc(_st_kq_data->addlist_size * sizeof(struct kevent)); |
643 | _st_kq_data->dellist_size = ST_KQ_MIN_EVTLIST_SIZE; | 646 | _st_kq_data->dellist_size = ST_KQ_MIN_EVTLIST_SIZE; |
644 | - _st_kq_data->dellist = (struct kevent *)malloc(_st_kq_data->dellist_size * | ||
645 | - sizeof(struct kevent)); | 647 | + _st_kq_data->dellist = (struct kevent *)malloc(_st_kq_data->dellist_size * sizeof(struct kevent)); |
646 | if (!_st_kq_data->evtlist || !_st_kq_data->addlist || | 648 | if (!_st_kq_data->evtlist || !_st_kq_data->addlist || |
647 | !_st_kq_data->dellist) { | 649 | !_st_kq_data->dellist) { |
648 | err = ENOMEM; | 650 | err = ENOMEM; |
@@ -651,8 +653,9 @@ ST_HIDDEN int _st_kq_init(void) | @@ -651,8 +653,9 @@ ST_HIDDEN int _st_kq_init(void) | ||
651 | 653 | ||
652 | cleanup_kq: | 654 | cleanup_kq: |
653 | if (rv < 0) { | 655 | if (rv < 0) { |
654 | - if (_st_kq_data->kq >= 0) | 656 | + if (_st_kq_data->kq >= 0) { |
655 | close(_st_kq_data->kq); | 657 | close(_st_kq_data->kq); |
658 | + } | ||
656 | free(_st_kq_data->fd_data); | 659 | free(_st_kq_data->fd_data); |
657 | free(_st_kq_data->evtlist); | 660 | free(_st_kq_data->evtlist); |
658 | free(_st_kq_data->addlist); | 661 | free(_st_kq_data->addlist); |
@@ -670,16 +673,16 @@ ST_HIDDEN int _st_kq_fd_data_expand(int maxfd) | @@ -670,16 +673,16 @@ ST_HIDDEN int _st_kq_fd_data_expand(int maxfd) | ||
670 | _kq_fd_data_t *ptr; | 673 | _kq_fd_data_t *ptr; |
671 | int n = _st_kq_data->fd_data_size; | 674 | int n = _st_kq_data->fd_data_size; |
672 | 675 | ||
673 | - while (maxfd >= n) | 676 | + while (maxfd >= n) { |
674 | n <<= 1; | 677 | n <<= 1; |
678 | + } | ||
675 | 679 | ||
676 | - ptr = (_kq_fd_data_t *)realloc(_st_kq_data->fd_data, | ||
677 | - n * sizeof(_kq_fd_data_t)); | ||
678 | - if (!ptr) | 680 | + ptr = (_kq_fd_data_t *)realloc(_st_kq_data->fd_data, n * sizeof(_kq_fd_data_t)); |
681 | + if (!ptr) { | ||
679 | return -1; | 682 | return -1; |
683 | + } | ||
680 | 684 | ||
681 | - memset(ptr + _st_kq_data->fd_data_size, 0, | ||
682 | - (n - _st_kq_data->fd_data_size) * sizeof(_kq_fd_data_t)); | 685 | + memset(ptr + _st_kq_data->fd_data_size, 0, (n - _st_kq_data->fd_data_size) * sizeof(_kq_fd_data_t)); |
683 | 686 | ||
684 | _st_kq_data->fd_data = ptr; | 687 | _st_kq_data->fd_data = ptr; |
685 | _st_kq_data->fd_data_size = n; | 688 | _st_kq_data->fd_data_size = n; |
@@ -692,13 +695,14 @@ ST_HIDDEN int _st_kq_addlist_expand(int avail) | @@ -692,13 +695,14 @@ ST_HIDDEN int _st_kq_addlist_expand(int avail) | ||
692 | struct kevent *ptr; | 695 | struct kevent *ptr; |
693 | int n = _st_kq_data->addlist_size; | 696 | int n = _st_kq_data->addlist_size; |
694 | 697 | ||
695 | - while (avail > n - _st_kq_data->addlist_cnt) | 698 | + while (avail > n - _st_kq_data->addlist_cnt) { |
696 | n <<= 1; | 699 | n <<= 1; |
700 | + } | ||
697 | 701 | ||
698 | - ptr = (struct kevent *)realloc(_st_kq_data->addlist, | ||
699 | - n * sizeof(struct kevent)); | ||
700 | - if (!ptr) | 702 | + ptr = (struct kevent *)realloc(_st_kq_data->addlist, n * sizeof(struct kevent)); |
703 | + if (!ptr) { | ||
701 | return -1; | 704 | return -1; |
705 | + } | ||
702 | 706 | ||
703 | _st_kq_data->addlist = ptr; | 707 | _st_kq_data->addlist = ptr; |
704 | _st_kq_data->addlist_size = n; | 708 | _st_kq_data->addlist_size = n; |
@@ -707,8 +711,7 @@ ST_HIDDEN int _st_kq_addlist_expand(int avail) | @@ -707,8 +711,7 @@ ST_HIDDEN int _st_kq_addlist_expand(int avail) | ||
707 | * Try to expand the result event list too | 711 | * Try to expand the result event list too |
708 | * (although we don't have to do it). | 712 | * (although we don't have to do it). |
709 | */ | 713 | */ |
710 | - ptr = (struct kevent *)realloc(_st_kq_data->evtlist, | ||
711 | - n * sizeof(struct kevent)); | 714 | + ptr = (struct kevent *)realloc(_st_kq_data->evtlist, n * sizeof(struct kevent)); |
712 | if (ptr) { | 715 | if (ptr) { |
713 | _st_kq_data->evtlist = ptr; | 716 | _st_kq_data->evtlist = ptr; |
714 | _st_kq_data->evtlist_size = n; | 717 | _st_kq_data->evtlist_size = n; |
@@ -720,8 +723,7 @@ ST_HIDDEN int _st_kq_addlist_expand(int avail) | @@ -720,8 +723,7 @@ ST_HIDDEN int _st_kq_addlist_expand(int avail) | ||
720 | ST_HIDDEN void _st_kq_addlist_add(const struct kevent *kev) | 723 | ST_HIDDEN void _st_kq_addlist_add(const struct kevent *kev) |
721 | { | 724 | { |
722 | ST_ASSERT(_st_kq_data->addlist_cnt < _st_kq_data->addlist_size); | 725 | ST_ASSERT(_st_kq_data->addlist_cnt < _st_kq_data->addlist_size); |
723 | - memcpy(_st_kq_data->addlist + _st_kq_data->addlist_cnt, kev, | ||
724 | - sizeof(struct kevent)); | 726 | + memcpy(_st_kq_data->addlist + _st_kq_data->addlist_cnt, kev, sizeof(struct kevent)); |
725 | _st_kq_data->addlist_cnt++; | 727 | _st_kq_data->addlist_cnt++; |
726 | } | 728 | } |
727 | 729 | ||
@@ -733,8 +735,7 @@ ST_HIDDEN void _st_kq_dellist_add(const struct kevent *kev) | @@ -733,8 +735,7 @@ ST_HIDDEN void _st_kq_dellist_add(const struct kevent *kev) | ||
733 | struct kevent *ptr; | 735 | struct kevent *ptr; |
734 | 736 | ||
735 | n <<= 1; | 737 | n <<= 1; |
736 | - ptr = (struct kevent *)realloc(_st_kq_data->dellist, | ||
737 | - n * sizeof(struct kevent)); | 738 | + ptr = (struct kevent *)realloc(_st_kq_data->dellist, n * sizeof(struct kevent)); |
738 | if (!ptr) { | 739 | if (!ptr) { |
739 | /* See comment in _st_kq_pollset_del() */ | 740 | /* See comment in _st_kq_pollset_del() */ |
740 | return; | 741 | return; |
@@ -744,8 +745,7 @@ ST_HIDDEN void _st_kq_dellist_add(const struct kevent *kev) | @@ -744,8 +745,7 @@ ST_HIDDEN void _st_kq_dellist_add(const struct kevent *kev) | ||
744 | _st_kq_data->dellist_size = n; | 745 | _st_kq_data->dellist_size = n; |
745 | } | 746 | } |
746 | 747 | ||
747 | - memcpy(_st_kq_data->dellist + _st_kq_data->dellist_cnt, kev, | ||
748 | - sizeof(struct kevent)); | 748 | + memcpy(_st_kq_data->dellist + _st_kq_data->dellist_cnt, kev, sizeof(struct kevent)); |
749 | _st_kq_data->dellist_cnt++; | 749 | _st_kq_data->dellist_cnt++; |
750 | } | 750 | } |
751 | 751 | ||
@@ -767,9 +767,9 @@ ST_HIDDEN int _st_kq_pollset_add(struct pollfd *pds, int npds) | @@ -767,9 +767,9 @@ ST_HIDDEN int _st_kq_pollset_add(struct pollfd *pds, int npds) | ||
767 | errno = EINVAL; | 767 | errno = EINVAL; |
768 | return -1; | 768 | return -1; |
769 | } | 769 | } |
770 | - if (pd->fd >= _st_kq_data->fd_data_size && | ||
771 | - _st_kq_fd_data_expand(pd->fd) < 0) | 770 | + if (pd->fd >= _st_kq_data->fd_data_size && _st_kq_fd_data_expand(pd->fd) < 0) { |
772 | return -1; | 771 | return -1; |
772 | + } | ||
773 | } | 773 | } |
774 | 774 | ||
775 | /* | 775 | /* |
@@ -777,9 +777,9 @@ ST_HIDDEN int _st_kq_pollset_add(struct pollfd *pds, int npds) | @@ -777,9 +777,9 @@ ST_HIDDEN int _st_kq_pollset_add(struct pollfd *pds, int npds) | ||
777 | * descriptors as in the pollset (for both READ and WRITE filters). | 777 | * descriptors as in the pollset (for both READ and WRITE filters). |
778 | */ | 778 | */ |
779 | npds <<= 1; | 779 | npds <<= 1; |
780 | - if (npds > _st_kq_data->addlist_size - _st_kq_data->addlist_cnt && | ||
781 | - _st_kq_addlist_expand(npds) < 0) | 780 | + if (npds > _st_kq_data->addlist_size - _st_kq_data->addlist_cnt && _st_kq_addlist_expand(npds) < 0) { |
782 | return -1; | 781 | return -1; |
782 | + } | ||
783 | 783 | ||
784 | for (pd = pds; pd < epd; pd++) { | 784 | for (pd = pds; pd < epd; pd++) { |
785 | if ((pd->events & POLLIN) && (_ST_KQ_READ_CNT(pd->fd)++ == 0)) { | 785 | if ((pd->events & POLLIN) && (_ST_KQ_READ_CNT(pd->fd)++ == 0)) { |
@@ -841,8 +841,7 @@ ST_HIDDEN void _st_kq_pollset_del(struct pollfd *pds, int npds) | @@ -841,8 +841,7 @@ ST_HIDDEN void _st_kq_pollset_del(struct pollfd *pds, int npds) | ||
841 | int rv; | 841 | int rv; |
842 | do { | 842 | do { |
843 | /* This kevent() won't block since result list size is 0 */ | 843 | /* This kevent() won't block since result list size is 0 */ |
844 | - rv = kevent(_st_kq_data->kq, _st_kq_data->dellist, | ||
845 | - _st_kq_data->dellist_cnt, NULL, 0, NULL); | 844 | + rv = kevent(_st_kq_data->kq, _st_kq_data->dellist, _st_kq_data->dellist_cnt, NULL, 0, NULL); |
846 | } while (rv < 0 && errno == EINTR); | 845 | } while (rv < 0 && errno == EINTR); |
847 | } | 846 | } |
848 | } | 847 | } |
@@ -861,8 +860,7 @@ ST_HIDDEN void _st_kq_dispatch(void) | @@ -861,8 +860,7 @@ ST_HIDDEN void _st_kq_dispatch(void) | ||
861 | if (_ST_SLEEPQ == NULL) { | 860 | if (_ST_SLEEPQ == NULL) { |
862 | tsp = NULL; | 861 | tsp = NULL; |
863 | } else { | 862 | } else { |
864 | - min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 : | ||
865 | - (_ST_SLEEPQ->due - _ST_LAST_CLOCK); | 863 | + min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 : (_ST_SLEEPQ->due - _ST_LAST_CLOCK); |
866 | timeout.tv_sec = (time_t) (min_timeout / 1000000); | 864 | timeout.tv_sec = (time_t) (min_timeout / 1000000); |
867 | timeout.tv_nsec = (long) ((min_timeout % 1000000) * 1000); | 865 | timeout.tv_nsec = (long) ((min_timeout % 1000000) * 1000); |
868 | tsp = &timeout; | 866 | tsp = &timeout; |
@@ -870,9 +868,8 @@ ST_HIDDEN void _st_kq_dispatch(void) | @@ -870,9 +868,8 @@ ST_HIDDEN void _st_kq_dispatch(void) | ||
870 | 868 | ||
871 | retry_kevent: | 869 | retry_kevent: |
872 | /* Check for I/O operations */ | 870 | /* Check for I/O operations */ |
873 | - nfd = kevent(_st_kq_data->kq, | ||
874 | - _st_kq_data->addlist, _st_kq_data->addlist_cnt, | ||
875 | - _st_kq_data->evtlist, _st_kq_data->evtlist_size, tsp); | 871 | + nfd = kevent(_st_kq_data->kq, _st_kq_data->addlist, _st_kq_data->addlist_cnt, |
872 | + _st_kq_data->evtlist, _st_kq_data->evtlist_size, tsp); | ||
876 | 873 | ||
877 | _st_kq_data->addlist_cnt = 0; | 874 | _st_kq_data->addlist_cnt = 0; |
878 | 875 | ||
@@ -927,16 +924,14 @@ ST_HIDDEN void _st_kq_dispatch(void) | @@ -927,16 +924,14 @@ ST_HIDDEN void _st_kq_dispatch(void) | ||
927 | * We set EV_ONESHOT flag so we only need to delete | 924 | * We set EV_ONESHOT flag so we only need to delete |
928 | * descriptor if it didn't fire. | 925 | * descriptor if it didn't fire. |
929 | */ | 926 | */ |
930 | - if ((events & POLLIN) && (--_ST_KQ_READ_CNT(osfd) == 0) && | ||
931 | - ((_ST_KQ_REVENTS(osfd) & POLLIN) == 0)) { | 927 | + if ((events & POLLIN) && (--_ST_KQ_READ_CNT(osfd) == 0) && ((_ST_KQ_REVENTS(osfd) & POLLIN) == 0)) { |
932 | memset(&kev, 0, sizeof(kev)); | 928 | memset(&kev, 0, sizeof(kev)); |
933 | kev.ident = osfd; | 929 | kev.ident = osfd; |
934 | kev.filter = EVFILT_READ; | 930 | kev.filter = EVFILT_READ; |
935 | kev.flags = EV_DELETE; | 931 | kev.flags = EV_DELETE; |
936 | _st_kq_dellist_add(&kev); | 932 | _st_kq_dellist_add(&kev); |
937 | } | 933 | } |
938 | - if ((events & POLLOUT) && (--_ST_KQ_WRITE_CNT(osfd) == 0) | ||
939 | - && ((_ST_KQ_REVENTS(osfd) & POLLOUT) == 0)) { | 934 | + if ((events & POLLOUT) && (--_ST_KQ_WRITE_CNT(osfd) == 0) && ((_ST_KQ_REVENTS(osfd) & POLLOUT) == 0)) { |
940 | memset(&kev, 0, sizeof(kev)); | 935 | memset(&kev, 0, sizeof(kev)); |
941 | kev.ident = osfd; | 936 | kev.ident = osfd; |
942 | kev.filter = EVFILT_WRITE; | 937 | kev.filter = EVFILT_WRITE; |
@@ -945,8 +940,9 @@ ST_HIDDEN void _st_kq_dispatch(void) | @@ -945,8 +940,9 @@ ST_HIDDEN void _st_kq_dispatch(void) | ||
945 | } | 940 | } |
946 | } | 941 | } |
947 | 942 | ||
948 | - if (pq->thread->flags & _ST_FL_ON_SLEEPQ) | 943 | + if (pq->thread->flags & _ST_FL_ON_SLEEPQ) { |
949 | _ST_DEL_SLEEPQ(pq->thread); | 944 | _ST_DEL_SLEEPQ(pq->thread); |
945 | + } | ||
950 | pq->thread->state = _ST_ST_RUNNABLE; | 946 | pq->thread->state = _ST_ST_RUNNABLE; |
951 | _ST_ADD_RUNQ(pq->thread); | 947 | _ST_ADD_RUNQ(pq->thread); |
952 | } | 948 | } |
@@ -956,8 +952,7 @@ ST_HIDDEN void _st_kq_dispatch(void) | @@ -956,8 +952,7 @@ ST_HIDDEN void _st_kq_dispatch(void) | ||
956 | int rv; | 952 | int rv; |
957 | do { | 953 | do { |
958 | /* This kevent() won't block since result list size is 0 */ | 954 | /* This kevent() won't block since result list size is 0 */ |
959 | - rv = kevent(_st_kq_data->kq, _st_kq_data->dellist, | ||
960 | - _st_kq_data->dellist_cnt, NULL, 0, NULL); | 955 | + rv = kevent(_st_kq_data->kq, _st_kq_data->dellist, _st_kq_data->dellist_cnt, NULL, 0, NULL); |
961 | } while (rv < 0 && errno == EINTR); | 956 | } while (rv < 0 && errno == EINTR); |
962 | } | 957 | } |
963 | 958 | ||
@@ -965,7 +960,6 @@ ST_HIDDEN void _st_kq_dispatch(void) | @@ -965,7 +960,6 @@ ST_HIDDEN void _st_kq_dispatch(void) | ||
965 | osfd = _st_kq_data->evtlist[i].ident; | 960 | osfd = _st_kq_data->evtlist[i].ident; |
966 | _ST_KQ_REVENTS(osfd) = 0; | 961 | _ST_KQ_REVENTS(osfd) = 0; |
967 | } | 962 | } |
968 | - | ||
969 | } else if (nfd < 0) { | 963 | } else if (nfd < 0) { |
970 | if (errno == EBADF && _st_kq_data->pid != getpid()) { | 964 | if (errno == EBADF && _st_kq_data->pid != getpid()) { |
971 | /* We probably forked, reinitialize kqueue */ | 965 | /* We probably forked, reinitialize kqueue */ |
@@ -976,8 +970,7 @@ ST_HIDDEN void _st_kq_dispatch(void) | @@ -976,8 +970,7 @@ ST_HIDDEN void _st_kq_dispatch(void) | ||
976 | fcntl(_st_kq_data->kq, F_SETFD, FD_CLOEXEC); | 970 | fcntl(_st_kq_data->kq, F_SETFD, FD_CLOEXEC); |
977 | _st_kq_data->pid = getpid(); | 971 | _st_kq_data->pid = getpid(); |
978 | /* Re-register all descriptors on ioq with new kqueue */ | 972 | /* Re-register all descriptors on ioq with new kqueue */ |
979 | - memset(_st_kq_data->fd_data, 0, | ||
980 | - _st_kq_data->fd_data_size * sizeof(_kq_fd_data_t)); | 973 | + memset(_st_kq_data->fd_data, 0, _st_kq_data->fd_data_size * sizeof(_kq_fd_data_t)); |
981 | for (q = _ST_IOQ.next; q != &_ST_IOQ; q = q->next) { | 974 | for (q = _ST_IOQ.next; q != &_ST_IOQ; q = q->next) { |
982 | pq = _ST_POLLQUEUE_PTR(q); | 975 | pq = _ST_POLLQUEUE_PTR(q); |
983 | _st_kq_pollset_add(pq->pds, pq->npds); | 976 | _st_kq_pollset_add(pq->pds, pq->npds); |
@@ -989,8 +982,9 @@ ST_HIDDEN void _st_kq_dispatch(void) | @@ -989,8 +982,9 @@ ST_HIDDEN void _st_kq_dispatch(void) | ||
989 | 982 | ||
990 | ST_HIDDEN int _st_kq_fd_new(int osfd) | 983 | ST_HIDDEN int _st_kq_fd_new(int osfd) |
991 | { | 984 | { |
992 | - if (osfd >= _st_kq_data->fd_data_size && _st_kq_fd_data_expand(osfd) < 0) | 985 | + if (osfd >= _st_kq_data->fd_data_size && _st_kq_fd_data_expand(osfd) < 0) { |
993 | return -1; | 986 | return -1; |
987 | + } | ||
994 | 988 | ||
995 | return 0; | 989 | return 0; |
996 | } | 990 | } |
@@ -1024,7 +1018,6 @@ static _st_eventsys_t _st_kq_eventsys = { | @@ -1024,7 +1018,6 @@ static _st_eventsys_t _st_kq_eventsys = { | ||
1024 | }; | 1018 | }; |
1025 | #endif /* MD_HAVE_KQUEUE */ | 1019 | #endif /* MD_HAVE_KQUEUE */ |
1026 | 1020 | ||
1027 | - | ||
1028 | #ifdef MD_HAVE_EPOLL | 1021 | #ifdef MD_HAVE_EPOLL |
1029 | /***************************************** | 1022 | /***************************************** |
1030 | * epoll event system | 1023 | * epoll event system |
@@ -1036,14 +1029,13 @@ ST_HIDDEN int _st_epoll_init(void) | @@ -1036,14 +1029,13 @@ ST_HIDDEN int _st_epoll_init(void) | ||
1036 | int err = 0; | 1029 | int err = 0; |
1037 | int rv = 0; | 1030 | int rv = 0; |
1038 | 1031 | ||
1039 | - _st_epoll_data = | ||
1040 | - (struct _st_epolldata *) calloc(1, sizeof(*_st_epoll_data)); | ||
1041 | - if (!_st_epoll_data) | 1032 | + _st_epoll_data = (struct _st_epolldata *) calloc(1, sizeof(*_st_epoll_data)); |
1033 | + if (!_st_epoll_data) { | ||
1042 | return -1; | 1034 | return -1; |
1035 | + } | ||
1043 | 1036 | ||
1044 | fdlim = st_getfdlimit(); | 1037 | fdlim = st_getfdlimit(); |
1045 | - _st_epoll_data->fd_hint = (fdlim > 0 && fdlim < ST_EPOLL_EVTLIST_SIZE) ? | ||
1046 | - fdlim : ST_EPOLL_EVTLIST_SIZE; | 1038 | + _st_epoll_data->fd_hint = (fdlim > 0 && fdlim < ST_EPOLL_EVTLIST_SIZE) ? fdlim : ST_EPOLL_EVTLIST_SIZE; |
1047 | 1039 | ||
1048 | if ((_st_epoll_data->epfd = epoll_create(_st_epoll_data->fd_hint)) < 0) { | 1040 | if ((_st_epoll_data->epfd = epoll_create(_st_epoll_data->fd_hint)) < 0) { |
1049 | err = errno; | 1041 | err = errno; |
@@ -1055,9 +1047,7 @@ ST_HIDDEN int _st_epoll_init(void) | @@ -1055,9 +1047,7 @@ ST_HIDDEN int _st_epoll_init(void) | ||
1055 | 1047 | ||
1056 | /* Allocate file descriptor data array */ | 1048 | /* Allocate file descriptor data array */ |
1057 | _st_epoll_data->fd_data_size = _st_epoll_data->fd_hint; | 1049 | _st_epoll_data->fd_data_size = _st_epoll_data->fd_hint; |
1058 | - _st_epoll_data->fd_data = | ||
1059 | - (_epoll_fd_data_t *)calloc(_st_epoll_data->fd_data_size, | ||
1060 | - sizeof(_epoll_fd_data_t)); | 1050 | + _st_epoll_data->fd_data = (_epoll_fd_data_t *)calloc(_st_epoll_data->fd_data_size, sizeof(_epoll_fd_data_t)); |
1061 | if (!_st_epoll_data->fd_data) { | 1051 | if (!_st_epoll_data->fd_data) { |
1062 | err = errno; | 1052 | err = errno; |
1063 | rv = -1; | 1053 | rv = -1; |
@@ -1066,9 +1056,7 @@ ST_HIDDEN int _st_epoll_init(void) | @@ -1066,9 +1056,7 @@ ST_HIDDEN int _st_epoll_init(void) | ||
1066 | 1056 | ||
1067 | /* Allocate event lists */ | 1057 | /* Allocate event lists */ |
1068 | _st_epoll_data->evtlist_size = _st_epoll_data->fd_hint; | 1058 | _st_epoll_data->evtlist_size = _st_epoll_data->fd_hint; |
1069 | - _st_epoll_data->evtlist = | ||
1070 | - (struct epoll_event *)malloc(_st_epoll_data->evtlist_size * | ||
1071 | - sizeof(struct epoll_event)); | 1059 | + _st_epoll_data->evtlist = (struct epoll_event *)malloc(_st_epoll_data->evtlist_size * sizeof(struct epoll_event)); |
1072 | if (!_st_epoll_data->evtlist) { | 1060 | if (!_st_epoll_data->evtlist) { |
1073 | err = errno; | 1061 | err = errno; |
1074 | rv = -1; | 1062 | rv = -1; |
@@ -1076,8 +1064,9 @@ ST_HIDDEN int _st_epoll_init(void) | @@ -1076,8 +1064,9 @@ ST_HIDDEN int _st_epoll_init(void) | ||
1076 | 1064 | ||
1077 | cleanup_epoll: | 1065 | cleanup_epoll: |
1078 | if (rv < 0) { | 1066 | if (rv < 0) { |
1079 | - if (_st_epoll_data->epfd >= 0) | 1067 | + if (_st_epoll_data->epfd >= 0) { |
1080 | close(_st_epoll_data->epfd); | 1068 | close(_st_epoll_data->epfd); |
1069 | + } | ||
1081 | free(_st_epoll_data->fd_data); | 1070 | free(_st_epoll_data->fd_data); |
1082 | free(_st_epoll_data->evtlist); | 1071 | free(_st_epoll_data->evtlist); |
1083 | free(_st_epoll_data); | 1072 | free(_st_epoll_data); |
@@ -1093,16 +1082,16 @@ ST_HIDDEN int _st_epoll_fd_data_expand(int maxfd) | @@ -1093,16 +1082,16 @@ ST_HIDDEN int _st_epoll_fd_data_expand(int maxfd) | ||
1093 | _epoll_fd_data_t *ptr; | 1082 | _epoll_fd_data_t *ptr; |
1094 | int n = _st_epoll_data->fd_data_size; | 1083 | int n = _st_epoll_data->fd_data_size; |
1095 | 1084 | ||
1096 | - while (maxfd >= n) | 1085 | + while (maxfd >= n) { |
1097 | n <<= 1; | 1086 | n <<= 1; |
1087 | + } | ||
1098 | 1088 | ||
1099 | - ptr = (_epoll_fd_data_t *)realloc(_st_epoll_data->fd_data, | ||
1100 | - n * sizeof(_epoll_fd_data_t)); | ||
1101 | - if (!ptr) | 1089 | + ptr = (_epoll_fd_data_t *)realloc(_st_epoll_data->fd_data, n * sizeof(_epoll_fd_data_t)); |
1090 | + if (!ptr) { | ||
1102 | return -1; | 1091 | return -1; |
1092 | + } | ||
1103 | 1093 | ||
1104 | - memset(ptr + _st_epoll_data->fd_data_size, 0, | ||
1105 | - (n - _st_epoll_data->fd_data_size) * sizeof(_epoll_fd_data_t)); | 1094 | + memset(ptr + _st_epoll_data->fd_data_size, 0, (n - _st_epoll_data->fd_data_size) * sizeof(_epoll_fd_data_t)); |
1106 | 1095 | ||
1107 | _st_epoll_data->fd_data = ptr; | 1096 | _st_epoll_data->fd_data = ptr; |
1108 | _st_epoll_data->fd_data_size = n; | 1097 | _st_epoll_data->fd_data_size = n; |
@@ -1115,11 +1104,11 @@ ST_HIDDEN void _st_epoll_evtlist_expand(void) | @@ -1115,11 +1104,11 @@ ST_HIDDEN void _st_epoll_evtlist_expand(void) | ||
1115 | struct epoll_event *ptr; | 1104 | struct epoll_event *ptr; |
1116 | int n = _st_epoll_data->evtlist_size; | 1105 | int n = _st_epoll_data->evtlist_size; |
1117 | 1106 | ||
1118 | - while (_st_epoll_data->evtlist_cnt > n) | 1107 | + while (_st_epoll_data->evtlist_cnt > n) { |
1119 | n <<= 1; | 1108 | n <<= 1; |
1109 | + } | ||
1120 | 1110 | ||
1121 | - ptr = (struct epoll_event *)realloc(_st_epoll_data->evtlist, | ||
1122 | - n * sizeof(struct epoll_event)); | 1111 | + ptr = (struct epoll_event *)realloc(_st_epoll_data->evtlist, n * sizeof(struct epoll_event)); |
1123 | if (ptr) { | 1112 | if (ptr) { |
1124 | _st_epoll_data->evtlist = ptr; | 1113 | _st_epoll_data->evtlist = ptr; |
1125 | _st_epoll_data->evtlist_size = n; | 1114 | _st_epoll_data->evtlist_size = n; |
@@ -1141,12 +1130,15 @@ ST_HIDDEN void _st_epoll_pollset_del(struct pollfd *pds, int npds) | @@ -1141,12 +1130,15 @@ ST_HIDDEN void _st_epoll_pollset_del(struct pollfd *pds, int npds) | ||
1141 | for (pd = pds; pd < epd; pd++) { | 1130 | for (pd = pds; pd < epd; pd++) { |
1142 | old_events = _ST_EPOLL_EVENTS(pd->fd); | 1131 | old_events = _ST_EPOLL_EVENTS(pd->fd); |
1143 | 1132 | ||
1144 | - if (pd->events & POLLIN) | 1133 | + if (pd->events & POLLIN) { |
1145 | _ST_EPOLL_READ_CNT(pd->fd)--; | 1134 | _ST_EPOLL_READ_CNT(pd->fd)--; |
1146 | - if (pd->events & POLLOUT) | 1135 | + } |
1136 | + if (pd->events & POLLOUT) { | ||
1147 | _ST_EPOLL_WRITE_CNT(pd->fd)--; | 1137 | _ST_EPOLL_WRITE_CNT(pd->fd)--; |
1148 | - if (pd->events & POLLPRI) | 1138 | + } |
1139 | + if (pd->events & POLLPRI) { | ||
1149 | _ST_EPOLL_EXCEP_CNT(pd->fd)--; | 1140 | _ST_EPOLL_EXCEP_CNT(pd->fd)--; |
1141 | + } | ||
1150 | 1142 | ||
1151 | events = _ST_EPOLL_EVENTS(pd->fd); | 1143 | events = _ST_EPOLL_EVENTS(pd->fd); |
1152 | /* | 1144 | /* |
@@ -1158,8 +1150,7 @@ ST_HIDDEN void _st_epoll_pollset_del(struct pollfd *pds, int npds) | @@ -1158,8 +1150,7 @@ ST_HIDDEN void _st_epoll_pollset_del(struct pollfd *pds, int npds) | ||
1158 | op = events ? EPOLL_CTL_MOD : EPOLL_CTL_DEL; | 1150 | op = events ? EPOLL_CTL_MOD : EPOLL_CTL_DEL; |
1159 | ev.events = events; | 1151 | ev.events = events; |
1160 | ev.data.fd = pd->fd; | 1152 | ev.data.fd = pd->fd; |
1161 | - if (epoll_ctl(_st_epoll_data->epfd, op, pd->fd, &ev) == 0 && | ||
1162 | - op == EPOLL_CTL_DEL) { | 1153 | + if (epoll_ctl(_st_epoll_data->epfd, op, pd->fd, &ev) == 0 && op == EPOLL_CTL_DEL) { |
1163 | _st_epoll_data->evtlist_cnt--; | 1154 | _st_epoll_data->evtlist_cnt--; |
1164 | } | 1155 | } |
1165 | } | 1156 | } |
@@ -1175,39 +1166,42 @@ ST_HIDDEN int _st_epoll_pollset_add(struct pollfd *pds, int npds) | @@ -1175,39 +1166,42 @@ ST_HIDDEN int _st_epoll_pollset_add(struct pollfd *pds, int npds) | ||
1175 | /* Do as many checks as possible up front */ | 1166 | /* Do as many checks as possible up front */ |
1176 | for (i = 0; i < npds; i++) { | 1167 | for (i = 0; i < npds; i++) { |
1177 | fd = pds[i].fd; | 1168 | fd = pds[i].fd; |
1178 | - if (fd < 0 || !pds[i].events || | ||
1179 | - (pds[i].events & ~(POLLIN | POLLOUT | POLLPRI))) { | 1169 | + if (fd < 0 || !pds[i].events || (pds[i].events & ~(POLLIN | POLLOUT | POLLPRI))) { |
1180 | errno = EINVAL; | 1170 | errno = EINVAL; |
1181 | return -1; | 1171 | return -1; |
1182 | } | 1172 | } |
1183 | - if (fd >= _st_epoll_data->fd_data_size && | ||
1184 | - _st_epoll_fd_data_expand(fd) < 0) | 1173 | + if (fd >= _st_epoll_data->fd_data_size && _st_epoll_fd_data_expand(fd) < 0) { |
1185 | return -1; | 1174 | return -1; |
1175 | + } | ||
1186 | } | 1176 | } |
1187 | 1177 | ||
1188 | for (i = 0; i < npds; i++) { | 1178 | for (i = 0; i < npds; i++) { |
1189 | fd = pds[i].fd; | 1179 | fd = pds[i].fd; |
1190 | old_events = _ST_EPOLL_EVENTS(fd); | 1180 | old_events = _ST_EPOLL_EVENTS(fd); |
1191 | 1181 | ||
1192 | - if (pds[i].events & POLLIN) | 1182 | + if (pds[i].events & POLLIN) { |
1193 | _ST_EPOLL_READ_CNT(fd)++; | 1183 | _ST_EPOLL_READ_CNT(fd)++; |
1194 | - if (pds[i].events & POLLOUT) | 1184 | + } |
1185 | + if (pds[i].events & POLLOUT) { | ||
1195 | _ST_EPOLL_WRITE_CNT(fd)++; | 1186 | _ST_EPOLL_WRITE_CNT(fd)++; |
1196 | - if (pds[i].events & POLLPRI) | 1187 | + } |
1188 | + if (pds[i].events & POLLPRI) { | ||
1197 | _ST_EPOLL_EXCEP_CNT(fd)++; | 1189 | _ST_EPOLL_EXCEP_CNT(fd)++; |
1190 | + } | ||
1198 | 1191 | ||
1199 | events = _ST_EPOLL_EVENTS(fd); | 1192 | events = _ST_EPOLL_EVENTS(fd); |
1200 | if (events != old_events) { | 1193 | if (events != old_events) { |
1201 | op = old_events ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; | 1194 | op = old_events ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; |
1202 | ev.events = events; | 1195 | ev.events = events; |
1203 | ev.data.fd = fd; | 1196 | ev.data.fd = fd; |
1204 | - if (epoll_ctl(_st_epoll_data->epfd, op, fd, &ev) < 0 && | ||
1205 | - (op != EPOLL_CTL_ADD || errno != EEXIST)) | 1197 | + if (epoll_ctl(_st_epoll_data->epfd, op, fd, &ev) < 0 && (op != EPOLL_CTL_ADD || errno != EEXIST)) { |
1206 | break; | 1198 | break; |
1199 | + } | ||
1207 | if (op == EPOLL_CTL_ADD) { | 1200 | if (op == EPOLL_CTL_ADD) { |
1208 | _st_epoll_data->evtlist_cnt++; | 1201 | _st_epoll_data->evtlist_cnt++; |
1209 | - if (_st_epoll_data->evtlist_cnt > _st_epoll_data->evtlist_size) | 1202 | + if (_st_epoll_data->evtlist_cnt > _st_epoll_data->evtlist_size) { |
1210 | _st_epoll_evtlist_expand(); | 1203 | _st_epoll_evtlist_expand(); |
1204 | + } | ||
1211 | } | 1205 | } |
1212 | } | 1206 | } |
1213 | } | 1207 | } |
@@ -1238,8 +1232,7 @@ ST_HIDDEN void _st_epoll_dispatch(void) | @@ -1238,8 +1232,7 @@ ST_HIDDEN void _st_epoll_dispatch(void) | ||
1238 | if (_ST_SLEEPQ == NULL) { | 1232 | if (_ST_SLEEPQ == NULL) { |
1239 | timeout = -1; | 1233 | timeout = -1; |
1240 | } else { | 1234 | } else { |
1241 | - min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 : | ||
1242 | - (_ST_SLEEPQ->due - _ST_LAST_CLOCK); | 1235 | + min_timeout = (_ST_SLEEPQ->due <= _ST_LAST_CLOCK) ? 0 : (_ST_SLEEPQ->due - _ST_LAST_CLOCK); |
1243 | timeout = (int) (min_timeout / 1000); | 1236 | timeout = (int) (min_timeout / 1000); |
1244 | } | 1237 | } |
1245 | 1238 | ||
@@ -1255,8 +1248,7 @@ ST_HIDDEN void _st_epoll_dispatch(void) | @@ -1255,8 +1248,7 @@ ST_HIDDEN void _st_epoll_dispatch(void) | ||
1255 | _st_epoll_data->pid = getpid(); | 1248 | _st_epoll_data->pid = getpid(); |
1256 | 1249 | ||
1257 | /* Put all descriptors on ioq into new epoll set */ | 1250 | /* Put all descriptors on ioq into new epoll set */ |
1258 | - memset(_st_epoll_data->fd_data, 0, | ||
1259 | - _st_epoll_data->fd_data_size * sizeof(_epoll_fd_data_t)); | 1251 | + memset(_st_epoll_data->fd_data, 0, _st_epoll_data->fd_data_size * sizeof(_epoll_fd_data_t)); |
1260 | _st_epoll_data->evtlist_cnt = 0; | 1252 | _st_epoll_data->evtlist_cnt = 0; |
1261 | for (q = _ST_IOQ.next; q != &_ST_IOQ; q = q->next) { | 1253 | for (q = _ST_IOQ.next; q != &_ST_IOQ; q = q->next) { |
1262 | pq = _ST_POLLQUEUE_PTR(q); | 1254 | pq = _ST_POLLQUEUE_PTR(q); |
@@ -1265,8 +1257,7 @@ ST_HIDDEN void _st_epoll_dispatch(void) | @@ -1265,8 +1257,7 @@ ST_HIDDEN void _st_epoll_dispatch(void) | ||
1265 | } | 1257 | } |
1266 | 1258 | ||
1267 | /* Check for I/O operations */ | 1259 | /* Check for I/O operations */ |
1268 | - nfd = epoll_wait(_st_epoll_data->epfd, _st_epoll_data->evtlist, | ||
1269 | - _st_epoll_data->evtlist_size, timeout); | 1260 | + nfd = epoll_wait(_st_epoll_data->epfd, _st_epoll_data->evtlist, _st_epoll_data->evtlist_size, timeout); |
1270 | 1261 | ||
1271 | if (nfd > 0) { | 1262 | if (nfd > 0) { |
1272 | for (i = 0; i < nfd; i++) { | 1263 | for (i = 0; i < nfd; i++) { |
@@ -1291,16 +1282,21 @@ ST_HIDDEN void _st_epoll_dispatch(void) | @@ -1291,16 +1282,21 @@ ST_HIDDEN void _st_epoll_dispatch(void) | ||
1291 | osfd = pds->fd; | 1282 | osfd = pds->fd; |
1292 | events = pds->events; | 1283 | events = pds->events; |
1293 | revents = 0; | 1284 | revents = 0; |
1294 | - if ((events & POLLIN) && (_ST_EPOLL_REVENTS(osfd) & EPOLLIN)) | 1285 | + if ((events & POLLIN) && (_ST_EPOLL_REVENTS(osfd) & EPOLLIN)) { |
1295 | revents |= POLLIN; | 1286 | revents |= POLLIN; |
1296 | - if ((events & POLLOUT) && (_ST_EPOLL_REVENTS(osfd) & EPOLLOUT)) | 1287 | + } |
1288 | + if ((events & POLLOUT) && (_ST_EPOLL_REVENTS(osfd) & EPOLLOUT)) { | ||
1297 | revents |= POLLOUT; | 1289 | revents |= POLLOUT; |
1298 | - if ((events & POLLPRI) && (_ST_EPOLL_REVENTS(osfd) & EPOLLPRI)) | 1290 | + } |
1291 | + if ((events & POLLPRI) && (_ST_EPOLL_REVENTS(osfd) & EPOLLPRI)) { | ||
1299 | revents |= POLLPRI; | 1292 | revents |= POLLPRI; |
1300 | - if (_ST_EPOLL_REVENTS(osfd) & EPOLLERR) | 1293 | + } |
1294 | + if (_ST_EPOLL_REVENTS(osfd) & EPOLLERR) { | ||
1301 | revents |= POLLERR; | 1295 | revents |= POLLERR; |
1302 | - if (_ST_EPOLL_REVENTS(osfd) & EPOLLHUP) | 1296 | + } |
1297 | + if (_ST_EPOLL_REVENTS(osfd) & EPOLLHUP) { | ||
1303 | revents |= POLLHUP; | 1298 | revents |= POLLHUP; |
1299 | + } | ||
1304 | 1300 | ||
1305 | pds->revents = revents; | 1301 | pds->revents = revents; |
1306 | if (revents) { | 1302 | if (revents) { |
@@ -1316,8 +1312,9 @@ ST_HIDDEN void _st_epoll_dispatch(void) | @@ -1316,8 +1312,9 @@ ST_HIDDEN void _st_epoll_dispatch(void) | ||
1316 | */ | 1312 | */ |
1317 | _st_epoll_pollset_del(pq->pds, pq->npds); | 1313 | _st_epoll_pollset_del(pq->pds, pq->npds); |
1318 | 1314 | ||
1319 | - if (pq->thread->flags & _ST_FL_ON_SLEEPQ) | 1315 | + if (pq->thread->flags & _ST_FL_ON_SLEEPQ) { |
1320 | _ST_DEL_SLEEPQ(pq->thread); | 1316 | _ST_DEL_SLEEPQ(pq->thread); |
1317 | + } | ||
1321 | pq->thread->state = _ST_ST_RUNNABLE; | 1318 | pq->thread->state = _ST_ST_RUNNABLE; |
1322 | _ST_ADD_RUNQ(pq->thread); | 1319 | _ST_ADD_RUNQ(pq->thread); |
1323 | } | 1320 | } |
@@ -1331,8 +1328,7 @@ ST_HIDDEN void _st_epoll_dispatch(void) | @@ -1331,8 +1328,7 @@ ST_HIDDEN void _st_epoll_dispatch(void) | ||
1331 | op = events ? EPOLL_CTL_MOD : EPOLL_CTL_DEL; | 1328 | op = events ? EPOLL_CTL_MOD : EPOLL_CTL_DEL; |
1332 | ev.events = events; | 1329 | ev.events = events; |
1333 | ev.data.fd = osfd; | 1330 | ev.data.fd = osfd; |
1334 | - if (epoll_ctl(_st_epoll_data->epfd, op, osfd, &ev) == 0 && | ||
1335 | - op == EPOLL_CTL_DEL) { | 1331 | + if (epoll_ctl(_st_epoll_data->epfd, op, osfd, &ev) == 0 && op == EPOLL_CTL_DEL) { |
1336 | _st_epoll_data->evtlist_cnt--; | 1332 | _st_epoll_data->evtlist_cnt--; |
1337 | } | 1333 | } |
1338 | } | 1334 | } |
@@ -1341,17 +1337,16 @@ ST_HIDDEN void _st_epoll_dispatch(void) | @@ -1341,17 +1337,16 @@ ST_HIDDEN void _st_epoll_dispatch(void) | ||
1341 | 1337 | ||
1342 | ST_HIDDEN int _st_epoll_fd_new(int osfd) | 1338 | ST_HIDDEN int _st_epoll_fd_new(int osfd) |
1343 | { | 1339 | { |
1344 | - if (osfd >= _st_epoll_data->fd_data_size && | ||
1345 | - _st_epoll_fd_data_expand(osfd) < 0) | 1340 | + if (osfd >= _st_epoll_data->fd_data_size && _st_epoll_fd_data_expand(osfd) < 0) { |
1346 | return -1; | 1341 | return -1; |
1342 | + } | ||
1347 | 1343 | ||
1348 | return 0; | 1344 | return 0; |
1349 | } | 1345 | } |
1350 | 1346 | ||
1351 | ST_HIDDEN int _st_epoll_fd_close(int osfd) | 1347 | ST_HIDDEN int _st_epoll_fd_close(int osfd) |
1352 | { | 1348 | { |
1353 | - if (_ST_EPOLL_READ_CNT(osfd) || _ST_EPOLL_WRITE_CNT(osfd) || | ||
1354 | - _ST_EPOLL_EXCEP_CNT(osfd)) { | 1349 | + if (_ST_EPOLL_READ_CNT(osfd) || _ST_EPOLL_WRITE_CNT(osfd) || _ST_EPOLL_EXCEP_CNT(osfd)) { |
1355 | errno = EBUSY; | 1350 | errno = EBUSY; |
1356 | return -1; | 1351 | return -1; |
1357 | } | 1352 | } |
@@ -1425,8 +1420,9 @@ int st_set_eventsys(int eventsys) | @@ -1425,8 +1420,9 @@ int st_set_eventsys(int eventsys) | ||
1425 | #if defined (MD_HAVE_KQUEUE) | 1420 | #if defined (MD_HAVE_KQUEUE) |
1426 | _st_eventsys = &_st_kq_eventsys; | 1421 | _st_eventsys = &_st_kq_eventsys; |
1427 | #elif defined (MD_HAVE_EPOLL) | 1422 | #elif defined (MD_HAVE_EPOLL) |
1428 | - if (_st_epoll_is_supported()) | 1423 | + if (_st_epoll_is_supported()) { |
1429 | _st_eventsys = &_st_epoll_eventsys; | 1424 | _st_eventsys = &_st_epoll_eventsys; |
1425 | + } | ||
1430 | #endif | 1426 | #endif |
1431 | break; | 1427 | break; |
1432 | default: | 1428 | default: |
@@ -52,7 +52,6 @@ | @@ -52,7 +52,6 @@ | ||
52 | #include <errno.h> | 52 | #include <errno.h> |
53 | #include "common.h" | 53 | #include "common.h" |
54 | 54 | ||
55 | - | ||
56 | #if EAGAIN != EWOULDBLOCK | 55 | #if EAGAIN != EWOULDBLOCK |
57 | #define _IO_NOT_READY_ERROR ((errno == EAGAIN) || (errno == EWOULDBLOCK)) | 56 | #define _IO_NOT_READY_ERROR ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
58 | #else | 57 | #else |
@@ -100,13 +99,11 @@ int _st_io_init(void) | @@ -100,13 +99,11 @@ int _st_io_init(void) | ||
100 | return 0; | 99 | return 0; |
101 | } | 100 | } |
102 | 101 | ||
103 | - | ||
104 | int st_getfdlimit(void) | 102 | int st_getfdlimit(void) |
105 | { | 103 | { |
106 | return _st_osfd_limit; | 104 | return _st_osfd_limit; |
107 | } | 105 | } |
108 | 106 | ||
109 | - | ||
110 | void st_netfd_free(_st_netfd_t *fd) | 107 | void st_netfd_free(_st_netfd_t *fd) |
111 | { | 108 | { |
112 | if (!fd->inuse) { | 109 | if (!fd->inuse) { |
@@ -126,7 +123,6 @@ void st_netfd_free(_st_netfd_t *fd) | @@ -126,7 +123,6 @@ void st_netfd_free(_st_netfd_t *fd) | ||
126 | _st_netfd_freelist = fd; | 123 | _st_netfd_freelist = fd; |
127 | } | 124 | } |
128 | 125 | ||
129 | - | ||
130 | static _st_netfd_t *_st_netfd_new(int osfd, int nonblock, int is_socket) | 126 | static _st_netfd_t *_st_netfd_new(int osfd, int nonblock, int is_socket) |
131 | { | 127 | { |
132 | _st_netfd_t *fd; | 128 | _st_netfd_t *fd; |
@@ -165,19 +161,16 @@ static _st_netfd_t *_st_netfd_new(int osfd, int nonblock, int is_socket) | @@ -165,19 +161,16 @@ static _st_netfd_t *_st_netfd_new(int osfd, int nonblock, int is_socket) | ||
165 | return fd; | 161 | return fd; |
166 | } | 162 | } |
167 | 163 | ||
168 | - | ||
169 | _st_netfd_t *st_netfd_open(int osfd) | 164 | _st_netfd_t *st_netfd_open(int osfd) |
170 | { | 165 | { |
171 | return _st_netfd_new(osfd, 1, 0); | 166 | return _st_netfd_new(osfd, 1, 0); |
172 | } | 167 | } |
173 | 168 | ||
174 | - | ||
175 | _st_netfd_t *st_netfd_open_socket(int osfd) | 169 | _st_netfd_t *st_netfd_open_socket(int osfd) |
176 | { | 170 | { |
177 | return _st_netfd_new(osfd, 1, 1); | 171 | return _st_netfd_new(osfd, 1, 1); |
178 | } | 172 | } |
179 | 173 | ||
180 | - | ||
181 | int st_netfd_close(_st_netfd_t *fd) | 174 | int st_netfd_close(_st_netfd_t *fd) |
182 | { | 175 | { |
183 | if ((*_st_eventsys->fd_close)(fd->osfd) < 0) { | 176 | if ((*_st_eventsys->fd_close)(fd->osfd) < 0) { |
@@ -188,13 +181,11 @@ int st_netfd_close(_st_netfd_t *fd) | @@ -188,13 +181,11 @@ int st_netfd_close(_st_netfd_t *fd) | ||
188 | return close(fd->osfd); | 181 | return close(fd->osfd); |
189 | } | 182 | } |
190 | 183 | ||
191 | - | ||
192 | int st_netfd_fileno(_st_netfd_t *fd) | 184 | int st_netfd_fileno(_st_netfd_t *fd) |
193 | { | 185 | { |
194 | return (fd->osfd); | 186 | return (fd->osfd); |
195 | } | 187 | } |
196 | 188 | ||
197 | - | ||
198 | void st_netfd_setspecific(_st_netfd_t *fd, void *value, _st_destructor_t destructor) | 189 | void st_netfd_setspecific(_st_netfd_t *fd, void *value, _st_destructor_t destructor) |
199 | { | 190 | { |
200 | if (value != fd->private_data) { | 191 | if (value != fd->private_data) { |
@@ -207,13 +198,11 @@ void st_netfd_setspecific(_st_netfd_t *fd, void *value, _st_destructor_t destruc | @@ -207,13 +198,11 @@ void st_netfd_setspecific(_st_netfd_t *fd, void *value, _st_destructor_t destruc | ||
207 | fd->destructor = destructor; | 198 | fd->destructor = destructor; |
208 | } | 199 | } |
209 | 200 | ||
210 | - | ||
211 | void *st_netfd_getspecific(_st_netfd_t *fd) | 201 | void *st_netfd_getspecific(_st_netfd_t *fd) |
212 | { | 202 | { |
213 | return (fd->private_data); | 203 | return (fd->private_data); |
214 | } | 204 | } |
215 | 205 | ||
216 | - | ||
217 | /* | 206 | /* |
218 | * Wait for I/O on a single descriptor. | 207 | * Wait for I/O on a single descriptor. |
219 | */ | 208 | */ |
@@ -407,7 +396,6 @@ _st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen, st_ | @@ -407,7 +396,6 @@ _st_netfd_t *st_accept(_st_netfd_t *fd, struct sockaddr *addr, int *addrlen, st_ | ||
407 | } | 396 | } |
408 | #endif /* MD_ALWAYS_UNSERIALIZED_ACCEPT */ | 397 | #endif /* MD_ALWAYS_UNSERIALIZED_ACCEPT */ |
409 | 398 | ||
410 | - | ||
411 | int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int addrlen, st_utime_t timeout) | 399 | int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int addrlen, st_utime_t timeout) |
412 | { | 400 | { |
413 | int n, err = 0; | 401 | int n, err = 0; |
@@ -446,7 +434,6 @@ int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int addrlen, st_uti | @@ -446,7 +434,6 @@ int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int addrlen, st_uti | ||
446 | return 0; | 434 | return 0; |
447 | } | 435 | } |
448 | 436 | ||
449 | - | ||
450 | ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout) | 437 | ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout) |
451 | { | 438 | { |
452 | ssize_t n; | 439 | ssize_t n; |
@@ -467,7 +454,6 @@ ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout) | @@ -467,7 +454,6 @@ ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout) | ||
467 | return n; | 454 | return n; |
468 | } | 455 | } |
469 | 456 | ||
470 | - | ||
471 | int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid, st_utime_t timeout) | 457 | int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid, st_utime_t timeout) |
472 | { | 458 | { |
473 | struct iovec iov, *riov; | 459 | struct iovec iov, *riov; |
@@ -482,7 +468,6 @@ int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid, st_utime_t timeout) | @@ -482,7 +468,6 @@ int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid, st_utime_t timeout) | ||
482 | return rv; | 468 | return rv; |
483 | } | 469 | } |
484 | 470 | ||
485 | - | ||
486 | ssize_t st_readv(_st_netfd_t *fd, const struct iovec *iov, int iov_size, st_utime_t timeout) | 471 | ssize_t st_readv(_st_netfd_t *fd, const struct iovec *iov, int iov_size, st_utime_t timeout) |
487 | { | 472 | { |
488 | ssize_t n; | 473 | ssize_t n; |
@@ -741,7 +726,6 @@ int st_sendto(_st_netfd_t *fd, const void *msg, int len, const struct sockaddr * | @@ -741,7 +726,6 @@ int st_sendto(_st_netfd_t *fd, const void *msg, int len, const struct sockaddr * | ||
741 | return n; | 726 | return n; |
742 | } | 727 | } |
743 | 728 | ||
744 | - | ||
745 | int st_recvmsg(_st_netfd_t *fd, struct msghdr *msg, int flags, st_utime_t timeout) | 729 | int st_recvmsg(_st_netfd_t *fd, struct msghdr *msg, int flags, st_utime_t timeout) |
746 | { | 730 | { |
747 | int n; | 731 | int n; |
@@ -43,14 +43,12 @@ | @@ -43,14 +43,12 @@ | ||
43 | #include <errno.h> | 43 | #include <errno.h> |
44 | #include "common.h" | 44 | #include "common.h" |
45 | 45 | ||
46 | - | ||
47 | /* | 46 | /* |
48 | * Destructor table for per-thread private data | 47 | * Destructor table for per-thread private data |
49 | */ | 48 | */ |
50 | static _st_destructor_t _st_destructors[ST_KEYS_MAX]; | 49 | static _st_destructor_t _st_destructors[ST_KEYS_MAX]; |
51 | static int key_max = 0; | 50 | static int key_max = 0; |
52 | 51 | ||
53 | - | ||
54 | /* | 52 | /* |
55 | * Return a key to be used for thread specific data | 53 | * Return a key to be used for thread specific data |
56 | */ | 54 | */ |
@@ -67,13 +65,11 @@ int st_key_create(int *keyp, _st_destructor_t destructor) | @@ -67,13 +65,11 @@ int st_key_create(int *keyp, _st_destructor_t destructor) | ||
67 | return 0; | 65 | return 0; |
68 | } | 66 | } |
69 | 67 | ||
70 | - | ||
71 | int st_key_getlimit(void) | 68 | int st_key_getlimit(void) |
72 | { | 69 | { |
73 | return ST_KEYS_MAX; | 70 | return ST_KEYS_MAX; |
74 | } | 71 | } |
75 | 72 | ||
76 | - | ||
77 | int st_thread_setspecific(int key, void *value) | 73 | int st_thread_setspecific(int key, void *value) |
78 | { | 74 | { |
79 | _st_thread_t *me = _ST_CURRENT_THREAD(); | 75 | _st_thread_t *me = _ST_CURRENT_THREAD(); |
@@ -94,7 +90,6 @@ int st_thread_setspecific(int key, void *value) | @@ -94,7 +90,6 @@ int st_thread_setspecific(int key, void *value) | ||
94 | return 0; | 90 | return 0; |
95 | } | 91 | } |
96 | 92 | ||
97 | - | ||
98 | void *st_thread_getspecific(int key) | 93 | void *st_thread_getspecific(int key) |
99 | { | 94 | { |
100 | if (key < 0 || key >= key_max) { | 95 | if (key < 0 || key >= key_max) { |
@@ -104,7 +99,6 @@ void *st_thread_getspecific(int key) | @@ -104,7 +99,6 @@ void *st_thread_getspecific(int key) | ||
104 | return ((_ST_CURRENT_THREAD())->private_data[key]); | 99 | return ((_ST_CURRENT_THREAD())->private_data[key]); |
105 | } | 100 | } |
106 | 101 | ||
107 | - | ||
108 | /* | 102 | /* |
109 | * Free up all per-thread private data | 103 | * Free up all per-thread private data |
110 | */ | 104 | */ |
-
请 注册 或 登录 后发表评论