|
47 | 47 | #include "mstats.h" |
48 | 48 |
|
49 | 49 | #include <sys/select.h> |
| 50 | +#include <sys/socket.h> |
50 | 51 | #include <sys/time.h> |
| 52 | +#include <pthread.h> |
51 | 53 |
|
52 | 54 | counter_type link_read_bytes_global; /* GLOBAL */ |
53 | 55 | counter_type link_write_bytes_global; /* GLOBAL */ |
@@ -2524,8 +2526,24 @@ io_wait_dowork(struct context *c, const unsigned int flags) |
2524 | 2526 | dmsg(D_EVENT_WAIT, "I/O WAIT status=0x%04x", c->c2.event_set_status); |
2525 | 2527 | } |
2526 | 2528 |
|
| 2529 | +void threaded_read_tun(struct context *c, struct link_socket *sock, struct thread_pointer *b) |
| 2530 | +{ |
| 2531 | + if (b->p->h == b->p->n) |
| 2532 | + { |
| 2533 | + int size; |
| 2534 | + uint8_t temp[1]; |
| 2535 | + size = read(c->c1.tuntap->fd, temp, 1); |
| 2536 | + if (size < 1) { /* no-op */ } |
| 2537 | + if (!IS_SIG(c)) |
| 2538 | + { |
| 2539 | + process_incoming_tun(c, sock); |
| 2540 | + } |
| 2541 | + size = write(c->c1.tuntap->fz, temp, 1); |
| 2542 | + } |
| 2543 | +} |
| 2544 | + |
2527 | 2545 | void |
2528 | | -process_io(struct context *c, struct link_socket *sock) |
| 2546 | +process_io(struct context *c, struct link_socket *sock, struct thread_pointer *b) |
2529 | 2547 | { |
2530 | 2548 | const unsigned int status = c->c2.event_set_status; |
2531 | 2549 |
|
@@ -2559,11 +2577,7 @@ process_io(struct context *c, struct link_socket *sock) |
2559 | 2577 | /* Incoming data on TUN device */ |
2560 | 2578 | else if (status & TUN_READ) |
2561 | 2579 | { |
2562 | | - read_incoming_tun(c); |
2563 | | - if (!IS_SIG(c)) |
2564 | | - { |
2565 | | - process_incoming_tun(c, sock); |
2566 | | - } |
| 2580 | + threaded_read_tun(c, sock, b); |
2567 | 2581 | } |
2568 | 2582 | else if (status & DCO_READ) |
2569 | 2583 | { |
|
0 commit comments