summaryrefslogtreecommitdiff
path: root/cpputil/dummy_io.cc
blob: ef45db8339885a36aceb47d88ae5a03ca257f2e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <assert.h>
#include <iostream>

#include "prerror.h"
#include "prio.h"

#include "dummy_io.h"

#define UNIMPLEMENTED()                                        \
  std::cerr << "Unimplemented: " << __FUNCTION__ << std::endl; \
  assert(false);

extern const struct PRIOMethods DummyMethodsForward;

ScopedPRFileDesc DummyIOLayerMethods::CreateFD(PRDescIdentity id,
                                               DummyIOLayerMethods *methods) {
  ScopedPRFileDesc fd(PR_CreateIOLayerStub(id, &DummyMethodsForward));
  assert(fd);
  if (!fd) {
    return nullptr;
  }
  fd->secret = reinterpret_cast<PRFilePrivate *>(methods);
  return fd;
}

PRStatus DummyIOLayerMethods::Close(PRFileDesc *f) {
  f->secret = nullptr;
  f->dtor(f);
  return PR_SUCCESS;
}

int32_t DummyIOLayerMethods::Read(PRFileDesc *f, void *buf, int32_t length) {
  UNIMPLEMENTED();
  return -1;
}

int32_t DummyIOLayerMethods::Write(PRFileDesc *f, const void *buf,
                                   int32_t length) {
  UNIMPLEMENTED();
  return -1;
}

int32_t DummyIOLayerMethods::Available(PRFileDesc *f) {
  UNIMPLEMENTED();
  return -1;
}

int64_t DummyIOLayerMethods::Available64(PRFileDesc *f) {
  UNIMPLEMENTED();
  return -1;
}

PRStatus DummyIOLayerMethods::Sync(PRFileDesc *f) {
  UNIMPLEMENTED();
  return PR_FAILURE;
}

int32_t DummyIOLayerMethods::Seek(PRFileDesc *f, int32_t offset,
                                  PRSeekWhence how) {
  UNIMPLEMENTED();
  return -1;
}

int64_t DummyIOLayerMethods::Seek64(PRFileDesc *f, int64_t offset,
                                    PRSeekWhence how) {
  UNIMPLEMENTED();
  return -1;
}

PRStatus DummyIOLayerMethods::FileInfo(PRFileDesc *f, PRFileInfo *info) {
  UNIMPLEMENTED();
  return PR_FAILURE;
}

PRStatus DummyIOLayerMethods::FileInfo64(PRFileDesc *f, PRFileInfo64 *info) {
  UNIMPLEMENTED();
  return PR_FAILURE;
}

int32_t DummyIOLayerMethods::Writev(PRFileDesc *f, const PRIOVec *iov,
                                    int32_t iov_size, PRIntervalTime to) {
  UNIMPLEMENTED();
  return -1;
}

PRStatus DummyIOLayerMethods::Connect(PRFileDesc *f, const PRNetAddr *addr,
                                      PRIntervalTime to) {
  UNIMPLEMENTED();
  return PR_FAILURE;
}

PRFileDesc *DummyIOLayerMethods::Accept(PRFileDesc *sd, PRNetAddr *addr,
                                        PRIntervalTime to) {
  UNIMPLEMENTED();
  return nullptr;
}

PRStatus DummyIOLayerMethods::Bind(PRFileDesc *f, const PRNetAddr *addr) {
  UNIMPLEMENTED();
  return PR_FAILURE;
}

PRStatus DummyIOLayerMethods::Listen(PRFileDesc *f, int32_t depth) {
  UNIMPLEMENTED();
  return PR_FAILURE;
}

PRStatus DummyIOLayerMethods::Shutdown(PRFileDesc *f, int32_t how) {
  return PR_SUCCESS;
}

int32_t DummyIOLayerMethods::Recv(PRFileDesc *f, void *buf, int32_t buflen,
                                  int32_t flags, PRIntervalTime to) {
  UNIMPLEMENTED();
  return -1;
}

// Note: this is always nonblocking and assumes a zero timeout.
int32_t DummyIOLayerMethods::Send(PRFileDesc *f, const void *buf,
                                  int32_t amount, int32_t flags,
                                  PRIntervalTime to) {
  return Write(f, buf, amount);
}

int32_t DummyIOLayerMethods::Recvfrom(PRFileDesc *f, void *buf, int32_t amount,
                                      int32_t flags, PRNetAddr *addr,
                                      PRIntervalTime to) {
  UNIMPLEMENTED();
  return -1;
}

int32_t DummyIOLayerMethods::Sendto(PRFileDesc *f, const void *buf,
                                    int32_t amount, int32_t flags,
                                    const PRNetAddr *addr, PRIntervalTime to) {
  UNIMPLEMENTED();
  return -1;
}

int16_t DummyIOLayerMethods::Poll(PRFileDesc *f, int16_t in_flags,
                                  int16_t *out_flags) {
  UNIMPLEMENTED();
  return -1;
}

int32_t DummyIOLayerMethods::AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
                                        PRNetAddr **raddr, void *buf,
                                        int32_t amount, PRIntervalTime t) {
  UNIMPLEMENTED();
  return -1;
}

int32_t DummyIOLayerMethods::TransmitFile(PRFileDesc *sd, PRFileDesc *f,
                                          const void *headers, int32_t hlen,
                                          PRTransmitFileFlags flags,
                                          PRIntervalTime t) {
  UNIMPLEMENTED();
  return -1;
}

// TODO: Modify to return unique names for each channel
// somehow, as opposed to always the same static address. The current
// implementation messes up the session cache, which is why it's off
// elsewhere
PRStatus DummyIOLayerMethods::Getpeername(PRFileDesc *f, PRNetAddr *addr) {
  addr->inet.family = PR_AF_INET;
  addr->inet.port = 0;
  addr->inet.ip = 0;

  return PR_SUCCESS;
}

PRStatus DummyIOLayerMethods::Getsockname(PRFileDesc *f, PRNetAddr *addr) {
  UNIMPLEMENTED();
  return PR_FAILURE;
}

PRStatus DummyIOLayerMethods::Getsockoption(PRFileDesc *f,
                                            PRSocketOptionData *opt) {
  switch (opt->option) {
    case PR_SockOpt_Nonblocking:
      opt->value.non_blocking = PR_TRUE;
      return PR_SUCCESS;
    default:
      UNIMPLEMENTED();
      break;
  }

  return PR_FAILURE;
}

PRStatus DummyIOLayerMethods::Setsockoption(PRFileDesc *f,
                                            const PRSocketOptionData *opt) {
  switch (opt->option) {
    case PR_SockOpt_Nonblocking:
      return PR_SUCCESS;
    case PR_SockOpt_NoDelay:
      return PR_SUCCESS;
    default:
      UNIMPLEMENTED();
      break;
  }

  return PR_FAILURE;
}

int32_t DummyIOLayerMethods::Sendfile(PRFileDesc *out, PRSendFileData *in,
                                      PRTransmitFileFlags flags,
                                      PRIntervalTime to) {
  UNIMPLEMENTED();
  return -1;
}

PRStatus DummyIOLayerMethods::ConnectContinue(PRFileDesc *f, int16_t flags) {
  UNIMPLEMENTED();
  return PR_FAILURE;
}

int32_t DummyIOLayerMethods::Reserved(PRFileDesc *f) {
  UNIMPLEMENTED();
  return -1;
}