Debian Codegraph @

src/common/fdwatch_select.cpp

raw symbols SCIP
1 /*
2 * Abstraction API/layer for the various ways PvPGN can inspect sockets state
3 * 2003 (C)
4 *
5 * Code is based on the ideas found in thttpd project.
6 *
7 * select() based backend
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 #define FDWATCH_BACKENDcxx . . $ `src/common/fdwatch_select.cpp:24:9`!
25 #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/
26 #include "fdwatch_select.h"cxx . . $ `<file>/src/common/fdwatch_select.h`/
27
28 #include <cstring>
29
30 #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/
31 #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/
32
33 #ifdef HAVE_SELECTcxx . . $ `build/config.h:65:9`!
34
35 namespace pvpgncxx . . $ pvpgn/
36 {
37
38 FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend#::FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend#FDWSelectBackend(d4f767463ce0a6b3).(int nfds_)
39 :FDWBackendcxx . . $ pvpgn/FDWBackend#(nfds_), srcxx . . $ pvpgn/FDWSelectBackend#sr.(0), smaxfdcxx . . $ pvpgn/FDWSelectBackend#smaxfd.(0)
40 {
41 /* this should not happen */
42 if (nfdscxx . . $ pvpgn/FDWBackend#nfds. > FD_SETSIZEcxx . . $ `<external>/946878812840035423/select.h:73:9`!)
43 throw InitErrorcxx . . $ pvpgn/FDWBackend#InitError#("nfds over FD_SETSIZE"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
44
45 rfdscxx . . $ pvpgn/FDWSelectBackend#rfds..resetcxx . . $ pvpgn/scoped_ptr#reset(ebd0a1552f8ce24f).(new t_psock_fd_setcxx . . $ `src/compat/psock.h:277:9`!);
46 wfdscxx . . $ pvpgn/FDWSelectBackend#wfds..resetcxx . . $ pvpgn/scoped_ptr#reset(ebd0a1552f8ce24f).(new t_psock_fd_setcxx . . $ `src/compat/psock.h:277:9`!);
47 trfdscxx . . $ pvpgn/FDWSelectBackend#trfds..resetcxx . . $ pvpgn/scoped_ptr#reset(ebd0a1552f8ce24f).(new t_psock_fd_setcxx . . $ `src/compat/psock.h:277:9`!);
48 twfdscxx . . $ pvpgn/FDWSelectBackend#twfds..resetcxx . . $ pvpgn/scoped_ptr#reset(ebd0a1552f8ce24f).(new t_psock_fd_setcxx . . $ `src/compat/psock.h:277:9`!);
49
50 PSOCK_FD_ZEROcxx . . $ `src/compat/psock.h:278:9`!(trfds.get()); PSOCK_FD_ZEROcxx . . $ `src/compat/psock.h:278:9`!(twfds.get());
51
52 INFO1cxx . . $ `src/common/eventlog.h:84:9`!("fdwatch select() based layer initialized (max {} sockets)", nfds);
53 }
54
55 FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend#::~cxx . . $ pvpgn/FDWSelectBackend#`~FDWSelectBackend`(ced63f7c635d850d).FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend#() throw()
56 {}
57
58 int
59 FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend#::addcxx . . $ pvpgn/FDWSelectBackend#add(b223e862534b1804).(int idx, unsigned rw)
60 {
61 // eventlog(eventlog_level_trace, __FUNCTION__, "called fd: {} rw: {}", fd, rw);
62 int fd = fdw_fdcxx . . $ `src/common/fdwatch.h:56:9`!(fdw_fds + idx);
63
64 /* select() interface is limited by FD_SETSIZE max socket value */
65 if (fd >= FD_SETSIZEcxx . . $ `<external>/946878812840035423/select.h:73:9`!) return -1;
66
67 if (rw & fdwatch_type_readcxx . . $ pvpgn/fdwatch_type_read.) PSOCK_FD_SETcxx . . $ `src/compat/psock.h:280:9`!(fd, trfds.get());
68 else PSOCK_FD_CLRcxx . . $ `src/compat/psock.h:279:9`!(fd, trfds.get());
69 if (rw & fdwatch_type_writecxx . . $ pvpgn/fdwatch_type_write.) PSOCK_FD_SETcxx . . $ `src/compat/psock.h:280:9`!(fd, twfds.get());
70 else PSOCK_FD_CLRcxx . . $ `src/compat/psock.h:279:9`!(fd, twfds.get());
71 if (smaxfdcxx . . $ pvpgn/FDWSelectBackend#smaxfd. < fd) smaxfdcxx . . $ pvpgn/FDWSelectBackend#smaxfd. = fd;
72
73 return 0;
74 }
75
76 int
77 FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend#::delcxx . . $ pvpgn/FDWSelectBackend#del(7864480464b09eea).(int idx)
78 {
79 int fd = fdw_fdcxx . . $ `src/common/fdwatch.h:56:9`!(fdw_fds + idx);
80 // eventlog(eventlog_level_trace, __FUNCTION__, "called fd: {}", fd);
81 if (srcxx . . $ pvpgn/FDWSelectBackend#sr. > 0)
82 ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("BUG: called while still handling sockets");
83 PSOCK_FD_CLRcxx . . $ `src/compat/psock.h:279:9`!(fd, trfds.get());
84 PSOCK_FD_CLRcxx . . $ `src/compat/psock.h:279:9`!(fd, twfds.get());
85
86 return 0;
87 }
88
89 int
90 FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend#::watchcxx . . $ pvpgn/FDWSelectBackend#watch(a9e4e82268fd7bfa).(long timeout_msec)
91 {
92 static struct timeval tv;
93
94 tv.tv_sec = timeout_msec / 1000;
95 tv.tv_usec = timeout_msec % 1000;
96
97 /* set the working sets based on the templates */
98 stdcxx . . $ std/::memcpy(rfdscxx . . $ pvpgn/FDWSelectBackend#rfds..getcxx . . $ pvpgn/scoped_ptr#get(5a2a78a048fb49a8).(), trfdscxx . . $ pvpgn/FDWSelectBackend#trfds..getcxx . . $ pvpgn/scoped_ptr#get(5a2a78a048fb49a8).(), sizeof(t_psock_fd_setcxx . . $ `src/compat/psock.h:277:9`!));
99 stdcxx . . $ std/::memcpy(wfdscxx . . $ pvpgn/FDWSelectBackend#wfds..getcxx . . $ pvpgn/scoped_ptr#get(5a2a78a048fb49a8).(), twfdscxx . . $ pvpgn/FDWSelectBackend#twfds..getcxx . . $ pvpgn/scoped_ptr#get(5a2a78a048fb49a8).(), sizeof(t_psock_fd_setcxx . . $ `src/compat/psock.h:277:9`!));
100
101 return (srcxx . . $ pvpgn/FDWSelectBackend#sr. = psock_selectcxx . . $ `src/compat/psock.h:301:9`!(smaxfd + 1, rfds.get(), wfds.get(), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, &tv));
102 }
103
104 namespacecxx . . $ pvpgn/`$anonymous_namespace_src/common/fdwatch_select.cpp`/
105 {
106
107 int fdw_select_cbcxx . . $ pvpgn/`$anonymous_namespace_src/common/fdwatch_select.cpp`/fdw_select_cb(e3120144fe415ce2).(t_fdwatch_fdcxx . . $ pvpgn/t_fdwatch_fd# *cfd, void *data)
108 {
109 FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend# *obj = static_cast<FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend#*>(data);
110
111 return obj->cbcxx . . $ pvpgn/FDWSelectBackend#cb(1bc072288fb75793).(cfd);
112 }
113
114 }
115
116 int
117 FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend#::cbcxx . . $ pvpgn/FDWSelectBackend#cb(1bc072288fb75793).(t_fdwatch_fdcxx . . $ pvpgn/t_fdwatch_fd#* cfd)
118 {
119 // eventlog(eventlog_level_trace, __FUNCTION__, "idx: {} fd: {}", idx, fdw_fd->fd);
120 if (fdw_rwcxx . . $ `src/common/fdwatch.h:57:9`!(cfd) & fdwatch_type_readcxx . . $ pvpgn/fdwatch_type_read. && PSOCK_FD_ISSETcxx . . $ `src/compat/psock.h:281:9`!(fdw_fdcxx . . $ `src/common/fdwatch.h:56:9`!(cfd), rfds.get())
121 && fdw_hndcxx . . $ `src/common/fdwatch.h:59:9`!(cfd)(fdw_datacxx . . $ `src/common/fdwatch.h:58:9`!(cfd), fdwatch_type_readcxx . . $ pvpgn/fdwatch_type_read.) == -2) return 0;
122 if (fdw_rwcxx . . $ `src/common/fdwatch.h:57:9`!(cfd) & fdwatch_type_writecxx . . $ pvpgn/fdwatch_type_write. && PSOCK_FD_ISSETcxx . . $ `src/compat/psock.h:281:9`!(fdw_fdcxx . . $ `src/common/fdwatch.h:56:9`!(cfd), wfds.get()))
123 fdw_hndcxx . . $ `src/common/fdwatch.h:59:9`!(cfd)(fdw_datacxx . . $ `src/common/fdwatch.h:58:9`!(cfd), fdwatch_type_writecxx . . $ pvpgn/fdwatch_type_write.);
124
125 return 0;
126 }
127
128 void
129 FDWSelectBackendcxx . . $ pvpgn/FDWSelectBackend#::handlecxx . . $ pvpgn/FDWSelectBackend#handle(49f6e7a06ebc5aa8).()
130 {
131 // eventlog(eventlog_level_trace, __FUNCTION__, "called nofds: {}", fdw_nofds);
132 fdwatch_traversecxx . . $ pvpgn/fdwatch_traverse(8b1391bcbb30f1df).(fdw_select_cbcxx . . $ pvpgn/`$anonymous_namespace_src/common/fdwatch_select.cpp`/fdw_select_cb(e3120144fe415ce2)., this);
133 srcxx . . $ pvpgn/FDWSelectBackend#sr. = 0;
134 }
135
136 }
137
138 #endif /* HAVE_SELECT */