dummy_io.cc (6242B)
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 std::cerr << "Unimplemented: " << __FUNCTION__ << std::endl; \ 15 assert(false); 16 17 extern const struct PRIOMethods DummyMethodsForward; 18 19 ScopedPRFileDesc DummyIOLayerMethods::CreateFD(PRDescIdentity id, 20 DummyIOLayerMethods *methods) { 21 ScopedPRFileDesc fd(PR_CreateIOLayerStub(id, &DummyMethodsForward)); 22 assert(fd); 23 if (!fd) { 24 return nullptr; 25 } 26 fd->secret = reinterpret_cast<PRFilePrivate *>(methods); 27 return fd; 28 } 29 30 PRStatus DummyIOLayerMethods::Close(PRFileDesc *f) { 31 f->secret = nullptr; 32 f->dtor(f); 33 return PR_SUCCESS; 34 } 35 36 int32_t DummyIOLayerMethods::Read(PRFileDesc *f, void *buf, int32_t length) { 37 UNIMPLEMENTED(); 38 return -1; 39 } 40 41 int32_t DummyIOLayerMethods::Write(PRFileDesc *f, const void *buf, 42 int32_t length) { 43 UNIMPLEMENTED(); 44 return -1; 45 } 46 47 int32_t DummyIOLayerMethods::Available(PRFileDesc *f) { 48 UNIMPLEMENTED(); 49 return -1; 50 } 51 52 int64_t DummyIOLayerMethods::Available64(PRFileDesc *f) { 53 UNIMPLEMENTED(); 54 return -1; 55 } 56 57 PRStatus DummyIOLayerMethods::Sync(PRFileDesc *f) { 58 UNIMPLEMENTED(); 59 return PR_FAILURE; 60 } 61 62 int32_t DummyIOLayerMethods::Seek(PRFileDesc *f, int32_t offset, 63 PRSeekWhence how) { 64 UNIMPLEMENTED(); 65 return -1; 66 } 67 68 int64_t DummyIOLayerMethods::Seek64(PRFileDesc *f, int64_t offset, 69 PRSeekWhence how) { 70 UNIMPLEMENTED(); 71 return -1; 72 } 73 74 PRStatus DummyIOLayerMethods::FileInfo(PRFileDesc *f, PRFileInfo *info) { 75 UNIMPLEMENTED(); 76 return PR_FAILURE; 77 } 78 79 PRStatus DummyIOLayerMethods::FileInfo64(PRFileDesc *f, PRFileInfo64 *info) { 80 UNIMPLEMENTED(); 81 return PR_FAILURE; 82 } 83 84 int32_t DummyIOLayerMethods::Writev(PRFileDesc *f, const PRIOVec *iov, 85 int32_t iov_size, PRIntervalTime to) { 86 UNIMPLEMENTED(); 87 return -1; 88 } 89 90 PRStatus DummyIOLayerMethods::Connect(PRFileDesc *f, const PRNetAddr *addr, 91 PRIntervalTime to) { 92 UNIMPLEMENTED(); 93 return PR_FAILURE; 94 } 95 96 PRFileDesc *DummyIOLayerMethods::Accept(PRFileDesc *sd, PRNetAddr *addr, 97 PRIntervalTime to) { 98 UNIMPLEMENTED(); 99 return nullptr; 100 } 101 102 PRStatus DummyIOLayerMethods::Bind(PRFileDesc *f, const PRNetAddr *addr) { 103 UNIMPLEMENTED(); 104 return PR_FAILURE; 105 } 106 107 PRStatus DummyIOLayerMethods::Listen(PRFileDesc *f, int32_t depth) { 108 UNIMPLEMENTED(); 109 return PR_FAILURE; 110 } 111 112 PRStatus DummyIOLayerMethods::Shutdown(PRFileDesc *f, int32_t how) { 113 return PR_SUCCESS; 114 } 115 116 int32_t DummyIOLayerMethods::Recv(PRFileDesc *f, void *buf, int32_t buflen, 117 int32_t flags, PRIntervalTime to) { 118 UNIMPLEMENTED(); 119 return -1; 120 } 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 PRIntervalTime to) { 126 return Write(f, buf, amount); 127 } 128 129 int32_t DummyIOLayerMethods::Recvfrom(PRFileDesc *f, void *buf, int32_t amount, 130 int32_t flags, PRNetAddr *addr, 131 PRIntervalTime to) { 132 UNIMPLEMENTED(); 133 return -1; 134 } 135 136 int32_t DummyIOLayerMethods::Sendto(PRFileDesc *f, const void *buf, 137 int32_t amount, int32_t flags, 138 const PRNetAddr *addr, PRIntervalTime to) { 139 UNIMPLEMENTED(); 140 return -1; 141 } 142 143 int16_t DummyIOLayerMethods::Poll(PRFileDesc *f, int16_t in_flags, 144 int16_t *out_flags) { 145 UNIMPLEMENTED(); 146 return -1; 147 } 148 149 int32_t DummyIOLayerMethods::AcceptRead(PRFileDesc *sd, PRFileDesc **nd, 150 PRNetAddr **raddr, void *buf, 151 int32_t amount, PRIntervalTime t) { 152 UNIMPLEMENTED(); 153 return -1; 154 } 155 156 int32_t DummyIOLayerMethods::TransmitFile(PRFileDesc *sd, PRFileDesc *f, 157 const void *headers, int32_t hlen, 158 PRTransmitFileFlags flags, 159 PRIntervalTime t) { 160 UNIMPLEMENTED(); 161 return -1; 162 } 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 PRStatus DummyIOLayerMethods::Getpeername(PRFileDesc *f, PRNetAddr *addr) { 169 addr->inet.family = PR_AF_INET; 170 addr->inet.port = 0; 171 addr->inet.ip = 0; 172 173 return PR_SUCCESS; 174 } 175 176 PRStatus DummyIOLayerMethods::Getsockname(PRFileDesc *f, PRNetAddr *addr) { 177 UNIMPLEMENTED(); 178 return PR_FAILURE; 179 } 180 181 PRStatus DummyIOLayerMethods::Getsockoption(PRFileDesc *f, 182 PRSocketOptionData *opt) { 183 switch (opt->option) { 184 case PR_SockOpt_Nonblocking: 185 opt->value.non_blocking = PR_TRUE; 186 return PR_SUCCESS; 187 default: 188 UNIMPLEMENTED(); 189 break; 190 } 191 192 return PR_FAILURE; 193 } 194 195 PRStatus DummyIOLayerMethods::Setsockoption(PRFileDesc *f, 196 const PRSocketOptionData *opt) { 197 switch (opt->option) { 198 case PR_SockOpt_Nonblocking: 199 return PR_SUCCESS; 200 case PR_SockOpt_NoDelay: 201 return PR_SUCCESS; 202 default: 203 UNIMPLEMENTED(); 204 break; 205 } 206 207 return PR_FAILURE; 208 } 209 210 int32_t DummyIOLayerMethods::Sendfile(PRFileDesc *out, PRSendFileData *in, 211 PRTransmitFileFlags flags, 212 PRIntervalTime to) { 213 UNIMPLEMENTED(); 214 return -1; 215 } 216 217 PRStatus DummyIOLayerMethods::ConnectContinue(PRFileDesc *f, int16_t flags) { 218 UNIMPLEMENTED(); 219 return PR_FAILURE; 220 } 221 222 int32_t DummyIOLayerMethods::Reserved(PRFileDesc *f) { 223 UNIMPLEMENTED(); 224 return -1; 225 }