ADTast-experimentalpthread-emulationqualifiedEnum
Last change
on this file since 8c58e73 was
7f0ac12,
checked in by Thierry Delisle <tdelisle@…>, 2 years ago
|
First draft at acceptor thread webserver
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Line | |
---|
1 | #pragma once |
---|
2 | |
---|
3 | #include <iofwd.hfa> |
---|
4 | #include <queueLockFree.hfa> |
---|
5 | #include <thread.hfa> |
---|
6 | |
---|
7 | extern "C" { |
---|
8 | #include <sys/socket.h> |
---|
9 | } |
---|
10 | |
---|
11 | //============================================================================================= |
---|
12 | // Worker Thread |
---|
13 | //============================================================================================= |
---|
14 | |
---|
15 | extern const size_t zipf_sizes[]; |
---|
16 | enum { zipf_cnts = 36, }; |
---|
17 | |
---|
18 | struct sendfile_stats_t { |
---|
19 | volatile uint64_t calls; |
---|
20 | volatile uint64_t tries; |
---|
21 | volatile uint64_t header; |
---|
22 | volatile uint64_t splcin; |
---|
23 | volatile uint64_t splcot; |
---|
24 | struct { |
---|
25 | volatile uint64_t calls; |
---|
26 | volatile uint64_t bytes; |
---|
27 | } avgrd[zipf_cnts]; |
---|
28 | }; |
---|
29 | |
---|
30 | void ?{}( sendfile_stats_t & this ); |
---|
31 | |
---|
32 | struct connection { |
---|
33 | int pipe[2]; |
---|
34 | struct { |
---|
35 | sendfile_stats_t sendfile; |
---|
36 | } stats; |
---|
37 | }; |
---|
38 | |
---|
39 | static inline void ?{}( connection & this ) { |
---|
40 | this.pipe[0] = -1; |
---|
41 | this.pipe[1] = -1; |
---|
42 | } |
---|
43 | |
---|
44 | thread AcceptWorker { |
---|
45 | connection conn; |
---|
46 | int sockfd; |
---|
47 | struct sockaddr * addr; |
---|
48 | socklen_t * addrlen; |
---|
49 | int flags; |
---|
50 | volatile bool done; |
---|
51 | }; |
---|
52 | void ?{}( AcceptWorker & this); |
---|
53 | void main( AcceptWorker & ); |
---|
54 | |
---|
55 | |
---|
56 | struct PendingRead { |
---|
57 | PendingRead * volatile next; |
---|
58 | io_future_t f; |
---|
59 | struct { |
---|
60 | void * buf; |
---|
61 | size_t len; |
---|
62 | } in; |
---|
63 | struct { |
---|
64 | volatile int fd; |
---|
65 | } out; |
---|
66 | }; |
---|
67 | |
---|
68 | static inline PendingRead * volatile & ?`next ( PendingRead * node ) { |
---|
69 | return node->next; |
---|
70 | } |
---|
71 | |
---|
72 | thread ChannelWorker { |
---|
73 | connection conn; |
---|
74 | volatile bool done; |
---|
75 | mpsc_queue(PendingRead) * queue; |
---|
76 | }; |
---|
77 | void ?{}( ChannelWorker & ); |
---|
78 | void main( ChannelWorker & ); |
---|
79 | |
---|
80 | thread Acceptor { |
---|
81 | mpsc_queue(PendingRead) * queue; |
---|
82 | int sockfd; |
---|
83 | struct sockaddr * addr; |
---|
84 | socklen_t * addrlen; |
---|
85 | int flags; |
---|
86 | volatile bool done; |
---|
87 | }; |
---|
88 | void ?{}( Acceptor & ); |
---|
89 | void main( Acceptor & ); |
---|
Note: See
TracBrowser
for help on using the repository browser.