dummy_io.cc 6.1 KB

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