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 /* memio is a simple NSPR I/O layer that lets you decouple NSS from | 6 /* memio is a simple NSPR I/O layer that lets you decouple NSS from |
7 * the real network. It's rather like openssl's memory bio, | 7 * the real network. It's rather like openssl's memory bio, |
8 * and is useful when your app absolutely, positively doesn't | 8 * and is useful when your app absolutely, positively doesn't |
9 * want to let NSS do its own networking. | 9 * want to let NSS do its own networking. |
10 */ | 10 */ |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 transferred += len; | 142 transferred += len; |
143 | 143 |
144 /* Handle part after wrap */ | 144 /* Handle part after wrap */ |
145 len = PR_MIN(n, memio_buffer_unused_contiguous(mb)); | 145 len = PR_MIN(n, memio_buffer_unused_contiguous(mb)); |
146 if (len > 0) { | 146 if (len > 0) { |
147 /* Output buffer still not full, input buffer still not empty */ | 147 /* Output buffer still not full, input buffer still not empty */ |
148 memcpy(&mb->buf[mb->tail], buf, len); | 148 memcpy(&mb->buf[mb->tail], buf, len); |
149 mb->tail += len; | 149 mb->tail += len; |
150 if (mb->tail == mb->bufsize) | 150 if (mb->tail == mb->bufsize) |
151 mb->tail = 0; | 151 mb->tail = 0; |
152 transferred += len; | 152 transferred += len; |
wtc
2013/08/12 17:11:42
Lines 145-152 are a copy of lines 133-142, except
| |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 return transferred; | 156 return transferred; |
157 } | 157 } |
158 | 158 |
159 | 159 |
160 /* Read n bytes from the buffer. Returns number of bytes read. */ | 160 /* Read n bytes from the buffer. Returns number of bytes read. */ |
161 static int memio_buffer_get(struct memio_buffer *mb, char *buf, int n) | 161 static int memio_buffer_get(struct memio_buffer *mb, char *buf, int n) |
162 { | 162 { |
163 int len; | 163 int len; |
164 int transferred = 0; | 164 int transferred = 0; |
165 | 165 |
166 /* Handle part before wrap */ | 166 /* Handle part before wrap */ |
167 len = PR_MIN(n, memio_buffer_used_contiguous(mb)); | 167 len = PR_MIN(n, memio_buffer_used_contiguous(mb)); |
168 if (len) { | 168 if (len) { |
169 memcpy(buf, &mb->buf[mb->head], len); | 169 memcpy(buf, &mb->buf[mb->head], len); |
170 mb->head += len; | 170 mb->head += len; |
171 if (mb->head == mb->bufsize) | 171 if (mb->head == mb->bufsize) |
172 mb->head = 0; | 172 mb->head = 0; |
173 n -= len; | 173 n -= len; |
174 buf += len; | 174 buf += len; |
175 transferred += len; | 175 transferred += len; |
176 | 176 |
177 /* Handle part after wrap */ | 177 /* Handle part after wrap */ |
178 len = PR_MIN(n, memio_buffer_used_contiguous(mb)); | 178 len = PR_MIN(n, memio_buffer_used_contiguous(mb)); |
179 if (len) { | 179 if (len) { |
180 memcpy(buf, &mb->buf[mb->head], len); | 180 memcpy(buf, &mb->buf[mb->head], len); |
181 mb->head += len; | 181 mb->head += len; |
182 if (mb->head == mb->bufsize) | 182 if (mb->head == mb->bufsize) |
183 mb->head = 0; | 183 mb->head = 0; |
184 transferred += len; | 184 transferred += len; |
wtc
2013/08/12 17:11:42
Similarly, lines 178-184 are a copy of lines 167-1
| |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 return transferred; | 188 return transferred; |
189 } | 189 } |
190 | 190 |
191 /*--------------- private memio functions -----------------------*/ | 191 /*--------------- private memio functions -----------------------*/ |
192 | 192 |
193 static PRStatus PR_CALLBACK memio_Close(PRFileDesc *fd) | 193 static PRStatus PR_CALLBACK memio_Close(PRFileDesc *fd) |
194 { | 194 { |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); | 524 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); |
525 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); | 525 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); |
526 | 526 |
527 /* TODO: add more cases */ | 527 /* TODO: add more cases */ |
528 | 528 |
529 printf("Test passed\n"); | 529 printf("Test passed\n"); |
530 exit(0); | 530 exit(0); |
531 } | 531 } |
532 | 532 |
533 #endif | 533 #endif |
OLD | NEW |