Lines Matching refs:ctx

1305 coap_io_prepare_epoll(coap_context_t *ctx, coap_tick_t now) {
1307 (void)ctx;
1318 timeout = coap_io_prepare_io(ctx, sockets, max_sockets, &num_sockets, now);
1320 ctx->next_timeout = timeout ? now + timeout : 0;
1321 if (ctx->eptimerfd != -1) {
1327 if (ctx->next_timeout != 0 && ctx->next_timeout > now) {
1328 coap_tick_t rem_timeout = ctx->next_timeout - now;
1329 /* Need to trigger an event on ctx->eptimerfd in the future */
1339 ret = timerfd_settime(ctx->eptimerfd, 0, &new_value, NULL);
1355 coap_io_prepare_io(coap_context_t *ctx,
1376 coap_check_notify(ctx);
1380 timeout = coap_check_async(ctx, now);
1385 nextpdu = coap_peek_next(ctx);
1386 while (nextpdu && now >= ctx->sendqueue_basetime &&
1387 nextpdu->t <= now - ctx->sendqueue_basetime) {
1388 coap_retransmit(ctx, coap_pop_next(ctx));
1389 nextpdu = coap_peek_next(ctx);
1392 nextpdu->t - (now - ctx->sendqueue_basetime) < timeout))
1393 timeout = nextpdu->t - (now - ctx->sendqueue_basetime);
1396 if (ctx->dtls_context) {
1398 coap_tick_t tls_timeout = coap_dtls_get_context_timeout(ctx->dtls_context);
1417 if (ctx->session_timeout > 0)
1418 session_timeout = ctx->session_timeout * COAP_TICKS_PER_SECOND;
1422 LL_FOREACH(ctx->endpoint, ep) {
1435 coap_handle_event(ctx, COAP_EVENT_SERVER_SESSION_DEL, s);
1504 SESSIONS_ITER_SAFE(ctx->sessions, s, rtmp) {
1507 ctx->ping_timeout > 0) {
1508 if (s->last_rx_tx + ctx->ping_timeout * COAP_TICKS_PER_SECOND <= now) {
1519 s_timeout = (s->last_rx_tx + ctx->ping_timeout * COAP_TICKS_PER_SECOND) - now;
1526 s->state == COAP_SESSION_STATE_CSM && ctx->csm_timeout > 0) {
1529 } else if (s->csm_tx + ctx->csm_timeout * COAP_TICKS_PER_SECOND <= now) {
1536 s_timeout = (s->csm_tx + ctx->csm_timeout * COAP_TICKS_PER_SECOND) - now;
1609 coap_io_process(coap_context_t *ctx, uint32_t timeout_ms) {
1610 return coap_io_process_with_fds(ctx, timeout_ms, 0, NULL, NULL, NULL);
1614 coap_io_process_with_fds(coap_context_t *ctx, uint32_t timeout_ms,
1630 timeout = coap_io_prepare_io(ctx, ctx->sockets,
1631 (sizeof(ctx->sockets) / sizeof(ctx->sockets[0])),
1632 &ctx->num_sockets, before);
1637 ctx->readfds = *ereadfds;
1640 FD_ZERO(&ctx->readfds);
1643 ctx->writefds = *ewritefds;
1646 FD_ZERO(&ctx->writefds);
1649 ctx->exceptfds = *eexceptfds;
1652 FD_ZERO(&ctx->exceptfds);
1654 for (i = 0; i < ctx->num_sockets; i++) {
1655 if (ctx->sockets[i]->fd + 1 > nfds)
1656 nfds = ctx->sockets[i]->fd + 1;
1657 if (ctx->sockets[i]->flags & COAP_SOCKET_WANT_READ)
1658 FD_SET(ctx->sockets[i]->fd, &ctx->readfds);
1659 if (ctx->sockets[i]->flags & COAP_SOCKET_WANT_WRITE)
1660 FD_SET(ctx->sockets[i]->fd, &ctx->writefds);
1662 if (ctx->sockets[i]->flags & COAP_SOCKET_WANT_ACCEPT)
1663 FD_SET(ctx->sockets[i]->fd, &ctx->readfds);
1664 if (ctx->sockets[i]->flags & COAP_SOCKET_WANT_CONNECT) {
1665 FD_SET(ctx->sockets[i]->fd, &ctx->writefds);
1666 FD_SET(ctx->sockets[i]->fd, &ctx->exceptfds);
1680 result = select((int)nfds, &ctx->readfds, &ctx->writefds, &ctx->exceptfds,
1693 *ereadfds = ctx->readfds;
1696 *ewritefds = ctx->writefds;
1699 *eexceptfds = ctx->exceptfds;
1703 for (i = 0; i < ctx->num_sockets; i++) {
1704 if ((ctx->sockets[i]->flags & COAP_SOCKET_WANT_READ) &&
1705 FD_ISSET(ctx->sockets[i]->fd, &ctx->readfds))
1706 ctx->sockets[i]->flags |= COAP_SOCKET_CAN_READ;
1708 if ((ctx->sockets[i]->flags & COAP_SOCKET_WANT_ACCEPT) &&
1709 FD_ISSET(ctx->sockets[i]->fd, &ctx->readfds))
1710 ctx->sockets[i]->flags |= COAP_SOCKET_CAN_ACCEPT;
1711 if ((ctx->sockets[i]->flags & COAP_SOCKET_WANT_WRITE) &&
1712 FD_ISSET(ctx->sockets[i]->fd, &ctx->writefds))
1713 ctx->sockets[i]->flags |= COAP_SOCKET_CAN_WRITE;
1714 if ((ctx->sockets[i]->flags & COAP_SOCKET_WANT_CONNECT) &&
1715 (FD_ISSET(ctx->sockets[i]->fd, &ctx->writefds) ||
1716 FD_ISSET(ctx->sockets[i]->fd, &ctx->exceptfds)))
1717 ctx->sockets[i]->flags |= COAP_SOCKET_CAN_CONNECT;
1723 coap_io_do_io(ctx, now);
1731 timeout = coap_io_prepare_epoll(ctx, before);
1751 nfds = epoll_wait(ctx->epfd, events, COAP_MAX_EPOLL_EVENTS, etimeout);
1760 coap_io_do_epoll(ctx, events, nfds);
1774 coap_expire_cache_entries(ctx);
1780 coap_check_async(ctx, now);