| 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 395 |
| 396 int memio_GetReadParams(memio_Private *secret, char **buf) | 396 int memio_GetReadParams(memio_Private *secret, char **buf) |
| 397 { | 397 { |
| 398 struct memio_buffer* mb = &((PRFilePrivate *)secret)->readbuf; | 398 struct memio_buffer* mb = &((PRFilePrivate *)secret)->readbuf; |
| 399 PR_ASSERT(mb->bufsize); | 399 PR_ASSERT(mb->bufsize); |
| 400 | 400 |
| 401 *buf = &mb->buf[mb->tail]; | 401 *buf = &mb->buf[mb->tail]; |
| 402 return memio_buffer_unused_contiguous(mb); | 402 return memio_buffer_unused_contiguous(mb); |
| 403 } | 403 } |
| 404 | 404 |
| 405 int memio_GetReadableBufferSize(memio_Private *secret) |
| 406 { |
| 407 struct memio_buffer* mb = &((PRFilePrivate *)secret)->readbuf; |
| 408 PR_ASSERT(mb->bufsize); |
| 409 |
| 410 return memio_buffer_used_contiguous(mb); |
| 411 } |
| 412 |
| 405 void memio_PutReadResult(memio_Private *secret, int bytes_read) | 413 void memio_PutReadResult(memio_Private *secret, int bytes_read) |
| 406 { | 414 { |
| 407 struct memio_buffer* mb = &((PRFilePrivate *)secret)->readbuf; | 415 struct memio_buffer* mb = &((PRFilePrivate *)secret)->readbuf; |
| 408 PR_ASSERT(mb->bufsize); | 416 PR_ASSERT(mb->bufsize); |
| 409 | 417 |
| 410 if (bytes_read > 0) { | 418 if (bytes_read > 0) { |
| 411 mb->tail += bytes_read; | 419 mb->tail += bytes_read; |
| 412 if (mb->tail == mb->bufsize) | 420 if (mb->tail == mb->bufsize) |
| 413 mb->tail = 0; | 421 mb->tail = 0; |
| 414 } else if (bytes_read == 0) { | 422 } else if (bytes_read == 0) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); | 510 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); |
| 503 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); | 511 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); |
| 504 | 512 |
| 505 /* TODO: add more cases */ | 513 /* TODO: add more cases */ |
| 506 | 514 |
| 507 printf("Test passed\n"); | 515 printf("Test passed\n"); |
| 508 exit(0); | 516 exit(0); |
| 509 } | 517 } |
| 510 | 518 |
| 511 #endif | 519 #endif |
| OLD | NEW |