|
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 */ |
@@ -2570,3 +2572,67 @@ process_io(struct context *c, struct link_socket *sock) |
2570 | 2572 | } |
2571 | 2573 | } |
2572 | 2574 | } |
| 2575 | + |
| 2576 | +void threaded_read_tun(struct context *c, struct link_socket *sock, struct thread_pointer *b) |
| 2577 | +{ |
| 2578 | + if (b->i != b->p->i) |
| 2579 | + { |
| 2580 | + if (pthread_mutex_trylock(&(b->p->l)) == 0) |
| 2581 | + { |
| 2582 | + read_incoming_tun(c); |
| 2583 | + b->p->i = ((b->p->i % b->p->n) + 1); |
| 2584 | + pthread_mutex_unlock(&(b->p->l)); |
| 2585 | + if (!IS_SIG(c)) |
| 2586 | + { |
| 2587 | + process_incoming_tun(c, sock); |
| 2588 | + } |
| 2589 | + } |
| 2590 | + } |
| 2591 | +} |
| 2592 | + |
| 2593 | +void threaded_io(struct context *c, struct link_socket *sock, struct thread_pointer *b) |
| 2594 | +{ |
| 2595 | + const unsigned int status = c->c2.event_set_status; |
| 2596 | + |
| 2597 | +#ifdef ENABLE_MANAGEMENT |
| 2598 | + if (status & (MANAGEMENT_READ | MANAGEMENT_WRITE)) |
| 2599 | + { |
| 2600 | + ASSERT(management); |
| 2601 | + management_io(management); |
| 2602 | + } |
| 2603 | +#endif |
| 2604 | + |
| 2605 | + //msg(M_INFO, "MTIO MODE DEBUG PROC [%d] [%d][%d][%d][%d] [%d] [%d][%d][%p]",status,SOCKET_READ,SOCKET_WRITE,TUN_READ,TUN_WRITE,sock->sd,b->n,b->l,c->c2.buffers); |
| 2606 | + |
| 2607 | + /* TCP/UDP port ready to accept write */ |
| 2608 | + if (status & SOCKET_WRITE) |
| 2609 | + { |
| 2610 | + process_outgoing_link(c, sock); |
| 2611 | + } |
| 2612 | + /* TUN device ready to accept write */ |
| 2613 | + else if (status & TUN_WRITE) |
| 2614 | + { |
| 2615 | + process_outgoing_tun(c, sock); |
| 2616 | + } |
| 2617 | + /* Incoming data on TCP/UDP port */ |
| 2618 | + else if (status & SOCKET_READ) |
| 2619 | + { |
| 2620 | + read_incoming_link(c, sock); |
| 2621 | + if (!IS_SIG(c)) |
| 2622 | + { |
| 2623 | + process_incoming_link(c, sock); |
| 2624 | + } |
| 2625 | + } |
| 2626 | + /* Incoming data on TUN device */ |
| 2627 | + else if (status & TUN_READ) |
| 2628 | + { |
| 2629 | + threaded_read_tun(c, sock, b); |
| 2630 | + } |
| 2631 | + else if (status & DCO_READ) |
| 2632 | + { |
| 2633 | + if (!IS_SIG(c)) |
| 2634 | + { |
| 2635 | + process_incoming_dco(c); |
| 2636 | + } |
| 2637 | + } |
| 2638 | +} |
0 commit comments