/src/nss/cpputil/dummy_io.cc
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
3 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #include <assert.h> |
6 | | #include <iostream> |
7 | | |
8 | | #include "prerror.h" |
9 | | #include "prio.h" |
10 | | |
11 | | #include "dummy_io.h" |
12 | | |
13 | | #define UNIMPLEMENTED() \ |
14 | 0 | std::cerr << "Unimplemented: " << __FUNCTION__ << std::endl; \ |
15 | 0 | assert(false); |
16 | | |
17 | | extern const struct PRIOMethods DummyMethodsForward; |
18 | | |
19 | | ScopedPRFileDesc DummyIOLayerMethods::CreateFD(PRDescIdentity id, |
20 | 68.7k | DummyIOLayerMethods *methods) { |
21 | 68.7k | ScopedPRFileDesc fd(PR_CreateIOLayerStub(id, &DummyMethodsForward)); |
22 | 68.7k | assert(fd); |
23 | 68.7k | if (!fd) { |
24 | 0 | return nullptr; |
25 | 0 | } |
26 | 68.7k | fd->secret = reinterpret_cast<PRFilePrivate *>(methods); |
27 | 68.7k | return fd; |
28 | 68.7k | } |
29 | | |
30 | 68.7k | PRStatus DummyIOLayerMethods::Close(PRFileDesc *f) { |
31 | 68.7k | f->secret = nullptr; |
32 | 68.7k | f->dtor(f); |
33 | 68.7k | return PR_SUCCESS; |
34 | 68.7k | } |
35 | | |
36 | 0 | int32_t DummyIOLayerMethods::Read(PRFileDesc *f, void *buf, int32_t length) { |
37 | 0 | UNIMPLEMENTED(); |
38 | 0 | return -1; |
39 | 0 | } |
40 | | |
41 | | int32_t DummyIOLayerMethods::Write(PRFileDesc *f, const void *buf, |
42 | 0 | int32_t length) { |
43 | 0 | UNIMPLEMENTED(); |
44 | 0 | return -1; |
45 | 0 | } |
46 | | |
47 | 0 | int32_t DummyIOLayerMethods::Available(PRFileDesc *f) { |
48 | 0 | UNIMPLEMENTED(); |
49 | 0 | return -1; |
50 | 0 | } |
51 | | |
52 | 0 | int64_t DummyIOLayerMethods::Available64(PRFileDesc *f) { |
53 | 0 | UNIMPLEMENTED(); |
54 | 0 | return -1; |
55 | 0 | } |
56 | | |
57 | 0 | PRStatus DummyIOLayerMethods::Sync(PRFileDesc *f) { |
58 | 0 | UNIMPLEMENTED(); |
59 | 0 | return PR_FAILURE; |
60 | 0 | } |
61 | | |
62 | | int32_t DummyIOLayerMethods::Seek(PRFileDesc *f, int32_t offset, |
63 | 0 | PRSeekWhence how) { |
64 | 0 | UNIMPLEMENTED(); |
65 | 0 | return -1; |
66 | 0 | } |
67 | | |
68 | | int64_t DummyIOLayerMethods::Seek64(PRFileDesc *f, int64_t offset, |
69 | 0 | PRSeekWhence how) { |
70 | 0 | UNIMPLEMENTED(); |
71 | 0 | return -1; |
72 | 0 | } |
73 | | |
74 | 0 | PRStatus DummyIOLayerMethods::FileInfo(PRFileDesc *f, PRFileInfo *info) { |
75 | 0 | UNIMPLEMENTED(); |
76 | 0 | return PR_FAILURE; |
77 | 0 | } |
78 | | |
79 | 0 | PRStatus DummyIOLayerMethods::FileInfo64(PRFileDesc *f, PRFileInfo64 *info) { |
80 | 0 | UNIMPLEMENTED(); |
81 | 0 | return PR_FAILURE; |
82 | 0 | } |
83 | | |
84 | | int32_t DummyIOLayerMethods::Writev(PRFileDesc *f, const PRIOVec *iov, |
85 | 0 | int32_t iov_size, PRIntervalTime to) { |
86 | 0 | UNIMPLEMENTED(); |
87 | 0 | return -1; |
88 | 0 | } |
89 | | |
90 | | PRStatus DummyIOLayerMethods::Connect(PRFileDesc *f, const PRNetAddr *addr, |
91 | 0 | PRIntervalTime to) { |
92 | 0 | UNIMPLEMENTED(); |
93 | 0 | return PR_FAILURE; |
94 | 0 | } |
95 | | |
96 | | PRFileDesc *DummyIOLayerMethods::Accept(PRFileDesc *sd, PRNetAddr *addr, |
97 | 0 | PRIntervalTime to) { |
98 | 0 | UNIMPLEMENTED(); |
99 | 0 | return nullptr; |
100 | 0 | } |
101 | | |
102 | 0 | PRStatus DummyIOLayerMethods::Bind(PRFileDesc *f, const PRNetAddr *addr) { |
103 | 0 | UNIMPLEMENTED(); |
104 | 0 | return PR_FAILURE; |
105 | 0 | } |
106 | | |
107 | 0 | PRStatus DummyIOLayerMethods::Listen(PRFileDesc *f, int32_t depth) { |
108 | 0 | UNIMPLEMENTED(); |
109 | 0 | return PR_FAILURE; |
110 | 0 | } |
111 | | |
112 | 17 | PRStatus DummyIOLayerMethods::Shutdown(PRFileDesc *f, int32_t how) { |
113 | 17 | return PR_SUCCESS; |
114 | 17 | } |
115 | | |
116 | | int32_t DummyIOLayerMethods::Recv(PRFileDesc *f, void *buf, int32_t buflen, |
117 | 0 | int32_t flags, PRIntervalTime to) { |
118 | 0 | UNIMPLEMENTED(); |
119 | 0 | return -1; |
120 | 0 | } |
121 | | |
122 | | // Note: this is always nonblocking and assumes a zero timeout. |
123 | | int32_t DummyIOLayerMethods::Send(PRFileDesc *f, const void *buf, |
124 | | int32_t amount, int32_t flags, |
125 | 318k | PRIntervalTime to) { |
126 | 318k | return Write(f, buf, amount); |
127 | 318k | } |
128 | | |
129 | | int32_t DummyIOLayerMethods::Recvfrom(PRFileDesc *f, void *buf, int32_t amount, |
130 | | int32_t flags, PRNetAddr *addr, |
131 | 0 | PRIntervalTime to) { |
132 | 0 | UNIMPLEMENTED(); |
133 | 0 | return -1; |
134 | 0 | } |
135 | | |
136 | | int32_t DummyIOLayerMethods::Sendto(PRFileDesc *f, const void *buf, |
137 | | int32_t amount, int32_t flags, |
138 | 0 | const PRNetAddr *addr, PRIntervalTime to) { |
139 | 0 | UNIMPLEMENTED(); |
140 | 0 | return -1; |
141 | 0 | } |
142 | | |
143 | | int16_t DummyIOLayerMethods::Poll(PRFileDesc *f, int16_t in_flags, |
144 | 0 | int16_t *out_flags) { |
145 | 0 | UNIMPLEMENTED(); |
146 | 0 | return -1; |
147 | 0 | } |
148 | | |
149 | | int32_t DummyIOLayerMethods::AcceptRead(PRFileDesc *sd, PRFileDesc **nd, |
150 | | PRNetAddr **raddr, void *buf, |
151 | 0 | int32_t amount, PRIntervalTime t) { |
152 | 0 | UNIMPLEMENTED(); |
153 | 0 | return -1; |
154 | 0 | } |
155 | | |
156 | | int32_t DummyIOLayerMethods::TransmitFile(PRFileDesc *sd, PRFileDesc *f, |
157 | | const void *headers, int32_t hlen, |
158 | | PRTransmitFileFlags flags, |
159 | 0 | PRIntervalTime t) { |
160 | 0 | UNIMPLEMENTED(); |
161 | 0 | return -1; |
162 | 0 | } |
163 | | |
164 | | // TODO: Modify to return unique names for each channel |
165 | | // somehow, as opposed to always the same static address. The current |
166 | | // implementation messes up the session cache, which is why it's off |
167 | | // elsewhere |
168 | 178k | PRStatus DummyIOLayerMethods::Getpeername(PRFileDesc *f, PRNetAddr *addr) { |
169 | 178k | addr->inet.family = PR_AF_INET; |
170 | 178k | addr->inet.port = 0; |
171 | 178k | addr->inet.ip = 0; |
172 | | |
173 | 178k | return PR_SUCCESS; |
174 | 178k | } |
175 | | |
176 | 0 | PRStatus DummyIOLayerMethods::Getsockname(PRFileDesc *f, PRNetAddr *addr) { |
177 | 0 | UNIMPLEMENTED(); |
178 | 0 | return PR_FAILURE; |
179 | 0 | } |
180 | | |
181 | | PRStatus DummyIOLayerMethods::Getsockoption(PRFileDesc *f, |
182 | 115k | PRSocketOptionData *opt) { |
183 | 115k | switch (opt->option) { |
184 | 115k | case PR_SockOpt_Nonblocking: |
185 | 115k | opt->value.non_blocking = PR_TRUE; |
186 | 115k | return PR_SUCCESS; |
187 | 0 | default: |
188 | 0 | UNIMPLEMENTED(); |
189 | 0 | break; |
190 | 115k | } |
191 | | |
192 | 0 | return PR_FAILURE; |
193 | 115k | } |
194 | | |
195 | | PRStatus DummyIOLayerMethods::Setsockoption(PRFileDesc *f, |
196 | 4.39k | const PRSocketOptionData *opt) { |
197 | 4.39k | switch (opt->option) { |
198 | 0 | case PR_SockOpt_Nonblocking: |
199 | 0 | return PR_SUCCESS; |
200 | 4.39k | case PR_SockOpt_NoDelay: |
201 | 4.39k | return PR_SUCCESS; |
202 | 0 | default: |
203 | 0 | UNIMPLEMENTED(); |
204 | 0 | break; |
205 | 4.39k | } |
206 | | |
207 | 0 | return PR_FAILURE; |
208 | 4.39k | } |
209 | | |
210 | | int32_t DummyIOLayerMethods::Sendfile(PRFileDesc *out, PRSendFileData *in, |
211 | | PRTransmitFileFlags flags, |
212 | 0 | PRIntervalTime to) { |
213 | 0 | UNIMPLEMENTED(); |
214 | 0 | return -1; |
215 | 0 | } |
216 | | |
217 | 0 | PRStatus DummyIOLayerMethods::ConnectContinue(PRFileDesc *f, int16_t flags) { |
218 | 0 | UNIMPLEMENTED(); |
219 | 0 | return PR_FAILURE; |
220 | 0 | } |
221 | | |
222 | 0 | int32_t DummyIOLayerMethods::Reserved(PRFileDesc *f) { |
223 | 0 | UNIMPLEMENTED(); |
224 | 0 | return -1; |
225 | 0 | } |