OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // Written in NSPR style to also be suitable for adding to the NSS demo suite | 4 // Written in NSPR style to also be suitable for adding to the NSS demo suite |
5 | 5 |
6 #ifndef __MEMIO_H | 6 #ifndef __MEMIO_H |
7 #define __MEMIO_H | 7 #define __MEMIO_H |
8 | 8 |
| 9 #include <stddef.h> |
| 10 |
9 #ifdef __cplusplus | 11 #ifdef __cplusplus |
10 extern "C" { | 12 extern "C" { |
11 #endif | 13 #endif |
12 | 14 |
13 #include "prio.h" | 15 #include "prio.h" |
14 | 16 |
| 17 struct sockaddr; |
| 18 |
15 /* Opaque structure. Really just a more typesafe alias for PRFilePrivate. */ | 19 /* Opaque structure. Really just a more typesafe alias for PRFilePrivate. */ |
16 struct memio_Private; | 20 struct memio_Private; |
17 typedef struct memio_Private memio_Private; | 21 typedef struct memio_Private memio_Private; |
18 | 22 |
19 /*---------------------------------------------------------------------- | 23 /*---------------------------------------------------------------------- |
20 NSPR I/O layer that terminates in a pair of circular buffers | 24 NSPR I/O layer that terminates in a pair of circular buffers |
21 rather than talking to the real network. | 25 rather than talking to the real network. |
22 To use this with NSS: | 26 To use this with NSS: |
23 1) call memio_CreateIOLayer to create a fake NSPR socket | 27 1) call memio_CreateIOLayer to create a fake NSPR socket |
24 2) call SSL_ImportFD to ssl-ify the socket | 28 2) call SSL_ImportFD to ssl-ify the socket |
25 3) Do your own networking calls to set up a TCP connection | 29 3) Do your own networking calls to set up a TCP connection |
26 4) call memio_SetPeerName to tell NSS about the other end of the connection | 30 4) call memio_SetPeerName to tell NSS about the other end of the connection |
27 5) While at the same time doing plaintext nonblocking NSPR I/O as | 31 5) While at the same time doing plaintext nonblocking NSPR I/O as |
28 usual to the nspr file descriptor returned by SSL_ImportFD, | 32 usual to the nspr file descriptor returned by SSL_ImportFD, |
29 your app must shuttle encrypted data between | 33 your app must shuttle encrypted data between |
30 the real network and memio's network buffers. | 34 the real network and memio's network buffers. |
31 memio_GetReadParams/memio_PutReadResult | 35 memio_GetReadParams/memio_PutReadResult |
32 are the hooks you need to pump data into memio's input buffer, | 36 are the hooks you need to pump data into memio's input buffer, |
33 and memio_GetWriteParams/memio_PutWriteResult | 37 and memio_GetWriteParams/memio_PutWriteResult |
34 are the hooks you need to pump data out of memio's output buffer. | 38 are the hooks you need to pump data out of memio's output buffer. |
35 ----------------------------------------------------------------------*/ | 39 ----------------------------------------------------------------------*/ |
36 | 40 |
37 /* Create the I/O layer and its two circular buffers. */ | 41 /* Create the I/O layer and its two circular buffers. */ |
38 PRFileDesc *memio_CreateIOLayer(int bufsize); | 42 PRFileDesc *memio_CreateIOLayer(int bufsize); |
39 | 43 |
40 /* Must call before trying to make an ssl connection */ | 44 /* Must call before trying to make an ssl connection */ |
41 void memio_SetPeerName(PRFileDesc *fd, const PRNetAddr *peername); | 45 void memio_SetPeerName(PRFileDesc *fd, const struct sockaddr *peername, |
| 46 size_t peername_len); |
42 | 47 |
43 /* Return a private pointer needed by the following | 48 /* Return a private pointer needed by the following |
44 * four functions. (We could have passed a PRFileDesc to | 49 * four functions. (We could have passed a PRFileDesc to |
45 * them, but that would be slower. Better for the caller | 50 * them, but that would be slower. Better for the caller |
46 * to grab the pointer once and cache it. | 51 * to grab the pointer once and cache it. |
47 * This may be a premature optimization.) | 52 * This may be a premature optimization.) |
48 */ | 53 */ |
49 memio_Private *memio_GetSecret(PRFileDesc *fd); | 54 memio_Private *memio_GetSecret(PRFileDesc *fd); |
50 | 55 |
51 /* Ask memio where to put bytes from the network, and how many it can handle. | 56 /* Ask memio where to put bytes from the network, and how many it can handle. |
(...skipping 25 matching lines...) Expand all Loading... |
77 * On EWOULDBLOCK or the equivalent, don't call this function. | 82 * On EWOULDBLOCK or the equivalent, don't call this function. |
78 */ | 83 */ |
79 void memio_PutWriteResult(memio_Private *secret, int bytes_written); | 84 void memio_PutWriteResult(memio_Private *secret, int bytes_written); |
80 | 85 |
81 | 86 |
82 #ifdef __cplusplus | 87 #ifdef __cplusplus |
83 } | 88 } |
84 #endif | 89 #endif |
85 | 90 |
86 #endif | 91 #endif |
OLD | NEW |