Lines Matching +full:poll +full:- +full:timeout +full:- +full:ms
1 #include <sys/poll.h>
17 * simply calls back into this code when poll()/etc. indicates it is ready.
142 conn->ssl_bio = out; in new_conn()
147 * Non-blocking transmission.
149 * Returns -1 on error. Returns -2 if the function would block (corresponds to
156 conn->tx_need_rx = 0; in tx()
158 l = BIO_write(conn->ssl_bio, buf, buf_len); in tx()
160 if (BIO_should_retry(conn->ssl_bio)) { in tx()
161 conn->tx_need_rx = BIO_should_read(conn->ssl_bio); in tx()
162 return -2; in tx()
164 return -1; in tx()
172 * Non-blocking reception.
174 * Returns -1 on error. Returns -2 if the function would block (corresponds to
181 conn->rx_need_tx = 0; in rx()
183 l = BIO_read(conn->ssl_bio, buf, buf_len); in rx()
185 if (BIO_should_retry(conn->ssl_bio)) { in rx()
186 conn->rx_need_tx = BIO_should_write(conn->ssl_bio); in rx()
187 return -2; in rx()
189 return -1; in rx()
197 * The application wants to know a fd it can poll on to determine when the
205 if (!BIO_get_rpoll_descriptor(conn->ssl_bio, &d)) in get_conn_fd()
206 return -1; in get_conn_fd()
210 return BIO_get_fd(conn->ssl_bio, NULL); in get_conn_fd()
230 return (SSL_net_read_desired(conn->ssl) ? POLLIN : 0) in get_conn_pending_tx()
231 | (SSL_net_write_desired(conn->ssl) ? POLLOUT : 0) in get_conn_pending_tx()
234 return (conn->tx_need_rx ? POLLIN : 0) | POLLOUT | POLLERR; in get_conn_pending_tx()
243 return (conn->rx_need_tx ? POLLOUT : 0) | POLLIN | POLLERR; in get_conn_pending_rx()
250 * made. Any call (BIO_read/BIO_write/BIO_pump) will do. Returns -1 if
261 if (!SSL_get_event_timeout(conn->ssl, &tv, &is_infinite)) in get_conn_pump_timeout()
262 return -1; in get_conn_pump_timeout()
264 return is_infinite ? -1 : timeval_to_ms(&tv); in get_conn_pump_timeout()
269 * perform an application-level read/write.
273 SSL_handle_events(conn->ssl); in pump()
283 BIO_free_all(conn->ssl_bio); in teardown()
303 static inline void ms_to_timeval(struct timeval *t, int ms) in ms_to_timeval() argument
305 t->tv_sec = ms < 0 ? -1 : ms/1000; in ms_to_timeval()
306 t->tv_usec = ms < 0 ? 0 : (ms%1000)*1000; in ms_to_timeval()
311 return t->tv_sec*1000 + t->tv_usec/1000; in timeval_to_ms()
321 struct timeval timeout; in main() local
323 int timeout = 2000 /* ms */; in main() local
329 ms_to_timeval(&timeout, 2000); in main()
358 tx_len -= l; in main()
359 } else if (l == -1) { in main()
361 } else if (l == -2) { in main()
369 if (t.tv_sec < 0 || timercmp(&t, &timeout, >)) in main()
370 t = timeout; in main()
373 timeradd(&start, &timeout, &deadline); in main()
379 if (poll(&pfd, 1, timeval_to_ms(&t)) == 0) in main()
381 if (poll(&pfd, 1, timeout) == 0) in main()
391 fprintf(stderr, "tx timeout\n"); in main()
403 } else if (l == -1) { in main()
405 } else if (l == -2) { in main()
413 if (t.tv_sec < 0 || timercmp(&t, &timeout, >)) in main()
414 t = timeout; in main()
417 timeradd(&start, &timeout, &deadline); in main()
423 if (poll(&pfd, 1, timeval_to_ms(&t)) == 0) in main()
425 if (poll(&pfd, 1, timeout) == 0) in main()
435 fprintf(stderr, "rx timeout\n"); in main()