| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 usual to the nspr file descriptor returned by SSL_ImportFD, | 30 usual to the nspr file descriptor returned by SSL_ImportFD, |
| 31 your app must shuttle encrypted data between | 31 your app must shuttle encrypted data between |
| 32 the real network and memio's network buffers. | 32 the real network and memio's network buffers. |
| 33 memio_GetReadParams/memio_PutReadResult | 33 memio_GetReadParams/memio_PutReadResult |
| 34 are the hooks you need to pump data into memio's input buffer, | 34 are the hooks you need to pump data into memio's input buffer, |
| 35 and memio_GetWriteParams/memio_PutWriteResult | 35 and memio_GetWriteParams/memio_PutWriteResult |
| 36 are the hooks you need to pump data out of memio's output buffer. | 36 are the hooks you need to pump data out of memio's output buffer. |
| 37 ----------------------------------------------------------------------*/ | 37 ----------------------------------------------------------------------*/ |
| 38 | 38 |
| 39 /* Create the I/O layer and its two circular buffers. */ | 39 /* Create the I/O layer and its two circular buffers. */ |
| 40 PRFileDesc *memio_CreateIOLayer(int readbufsize, int writebufsize); | 40 PRFileDesc* memio_CreateIOLayer(int readbufsize, int writebufsize); |
| 41 | 41 |
| 42 /* Must call before trying to make an ssl connection */ | 42 /* Must call before trying to make an ssl connection */ |
| 43 void memio_SetPeerName(PRFileDesc *fd, const PRNetAddr *peername); | 43 void memio_SetPeerName(PRFileDesc* fd, const PRNetAddr* peername); |
| 44 | 44 |
| 45 /* Return a private pointer needed by the following | 45 /* Return a private pointer needed by the following |
| 46 * four functions. (We could have passed a PRFileDesc to | 46 * four functions. (We could have passed a PRFileDesc to |
| 47 * them, but that would be slower. Better for the caller | 47 * them, but that would be slower. Better for the caller |
| 48 * to grab the pointer once and cache it. | 48 * to grab the pointer once and cache it. |
| 49 * This may be a premature optimization.) | 49 * This may be a premature optimization.) |
| 50 */ | 50 */ |
| 51 memio_Private *memio_GetSecret(PRFileDesc *fd); | 51 memio_Private* memio_GetSecret(PRFileDesc* fd); |
| 52 | 52 |
| 53 /* Ask memio how many bytes were requested by a higher layer if the | 53 /* Ask memio how many bytes were requested by a higher layer if the |
| 54 * last attempt to read data resulted in PR_WOULD_BLOCK_ERROR, due to the | 54 * last attempt to read data resulted in PR_WOULD_BLOCK_ERROR, due to the |
| 55 * transport buffer being empty. If the last attempt to read data from the | 55 * transport buffer being empty. If the last attempt to read data from the |
| 56 * memio did not result in PR_WOULD_BLOCK_ERROR, returns 0. | 56 * memio did not result in PR_WOULD_BLOCK_ERROR, returns 0. |
| 57 */ | 57 */ |
| 58 int memio_GetReadRequest(memio_Private *secret); | 58 int memio_GetReadRequest(memio_Private* secret); |
| 59 | 59 |
| 60 /* Ask memio where to put bytes from the network, and how many it can handle. | 60 /* Ask memio where to put bytes from the network, and how many it can handle. |
| 61 * Returns bytes available to write, or 0 if none available. | 61 * Returns bytes available to write, or 0 if none available. |
| 62 * Puts current buffer position into *buf. | 62 * Puts current buffer position into *buf. |
| 63 */ | 63 */ |
| 64 int memio_GetReadParams(memio_Private *secret, char **buf); | 64 int memio_GetReadParams(memio_Private* secret, char** buf); |
| 65 | 65 |
| 66 /* Ask memio how many bytes are contained in the internal buffer. | 66 /* Ask memio how many bytes are contained in the internal buffer. |
| 67 * Returns bytes available to read, or 0 if none available. | 67 * Returns bytes available to read, or 0 if none available. |
| 68 */ | 68 */ |
| 69 int memio_GetReadableBufferSize(memio_Private *secret); | 69 int memio_GetReadableBufferSize(memio_Private* secret); |
| 70 | 70 |
| 71 /* Tell memio how many bytes were read from the network. | 71 /* Tell memio how many bytes were read from the network. |
| 72 * If bytes_read is 0, causes EOF to be reported to | 72 * If bytes_read is 0, causes EOF to be reported to |
| 73 * NSS after it reads the last byte from the circular buffer. | 73 * NSS after it reads the last byte from the circular buffer. |
| 74 * If bytes_read is < 0, it is treated as an NSPR error code. | 74 * If bytes_read is < 0, it is treated as an NSPR error code. |
| 75 * See nspr/pr/src/md/unix/unix_errors.c for how to | 75 * See nspr/pr/src/md/unix/unix_errors.c for how to |
| 76 * map from Unix errors to NSPR error codes. | 76 * map from Unix errors to NSPR error codes. |
| 77 * On EWOULDBLOCK or the equivalent, don't call this function. | 77 * On EWOULDBLOCK or the equivalent, don't call this function. |
| 78 */ | 78 */ |
| 79 void memio_PutReadResult(memio_Private *secret, int bytes_read); | 79 void memio_PutReadResult(memio_Private* secret, int bytes_read); |
| 80 | 80 |
| 81 /* Ask memio what data it has to send to the network. | 81 /* Ask memio what data it has to send to the network. |
| 82 * If there was previous a write error, the NSPR error code is returned. | 82 * If there was previous a write error, the NSPR error code is returned. |
| 83 * Otherwise, it returns 0 and provides up to two buffers of data by | 83 * Otherwise, it returns 0 and provides up to two buffers of data by |
| 84 * writing the positions and lengths into |buf1|, |len1| and |buf2|, |len2|. | 84 * writing the positions and lengths into |buf1|, |len1| and |buf2|, |len2|. |
| 85 */ | 85 */ |
| 86 int memio_GetWriteParams(memio_Private *secret, | 86 int memio_GetWriteParams(memio_Private* secret, |
| 87 const char **buf1, unsigned int *len1, | 87 const char** buf1, |
| 88 const char **buf2, unsigned int *len2); | 88 unsigned int* len1, |
| 89 const char** buf2, |
| 90 unsigned int* len2); |
| 89 | 91 |
| 90 /* Tell memio how many bytes were sent to the network. | 92 /* Tell memio how many bytes were sent to the network. |
| 91 * If bytes_written is < 0, it is treated as an NSPR error code. | 93 * If bytes_written is < 0, it is treated as an NSPR error code. |
| 92 * See nspr/pr/src/md/unix/unix_errors.c for how to | 94 * See nspr/pr/src/md/unix/unix_errors.c for how to |
| 93 * map from Unix errors to NSPR error codes. | 95 * map from Unix errors to NSPR error codes. |
| 94 * On EWOULDBLOCK or the equivalent, don't call this function. | 96 * On EWOULDBLOCK or the equivalent, don't call this function. |
| 95 */ | 97 */ |
| 96 void memio_PutWriteResult(memio_Private *secret, int bytes_written); | 98 void memio_PutWriteResult(memio_Private* secret, int bytes_written); |
| 97 | 99 |
| 98 #ifdef __cplusplus | 100 #ifdef __cplusplus |
| 99 } | 101 } |
| 100 #endif | 102 #endif |
| 101 | 103 |
| 102 #endif | 104 #endif |
| OLD | NEW |