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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 462 |
463 if (bytes_written > 0) { | 463 if (bytes_written > 0) { |
464 mb->head += bytes_written; | 464 mb->head += bytes_written; |
465 if (mb->head >= mb->bufsize) | 465 if (mb->head >= mb->bufsize) |
466 mb->head -= mb->bufsize; | 466 mb->head -= mb->bufsize; |
467 } else if (bytes_written < 0) { | 467 } else if (bytes_written < 0) { |
468 mb->last_err = bytes_written; | 468 mb->last_err = bytes_written; |
469 } | 469 } |
470 } | 470 } |
471 | 471 |
| 472 int memio_LastWriteError(memio_Private *secret) |
| 473 { |
| 474 struct memio_buffer* mb = &((PRFilePrivate *)secret)->writebuf; |
| 475 PR_ASSERT(mb->bufsize); |
| 476 |
| 477 return mb->last_err; |
| 478 } |
| 479 |
472 /*--------------- private memio_buffer self-test -----------------*/ | 480 /*--------------- private memio_buffer self-test -----------------*/ |
473 | 481 |
474 /* Even a trivial unit test is very helpful when doing circular buffers. */ | 482 /* Even a trivial unit test is very helpful when doing circular buffers. */ |
475 /*#define TRIVIAL_SELF_TEST*/ | 483 /*#define TRIVIAL_SELF_TEST*/ |
476 #ifdef TRIVIAL_SELF_TEST | 484 #ifdef TRIVIAL_SELF_TEST |
477 #include <stdio.h> | 485 #include <stdio.h> |
478 | 486 |
479 #define TEST_BUFLEN 7 | 487 #define TEST_BUFLEN 7 |
480 | 488 |
481 #define CHECKEQ(a, b) { \ | 489 #define CHECKEQ(a, b) { \ |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); | 533 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); |
526 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); | 534 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); |
527 | 535 |
528 /* TODO: add more cases */ | 536 /* TODO: add more cases */ |
529 | 537 |
530 printf("Test passed\n"); | 538 printf("Test passed\n"); |
531 exit(0); | 539 exit(0); |
532 } | 540 } |
533 | 541 |
534 #endif | 542 #endif |
OLD | NEW |