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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 if (mb->tail == mb->bufsize) | 435 if (mb->tail == mb->bufsize) |
436 mb->tail = 0; | 436 mb->tail = 0; |
437 } else if (bytes_read == 0) { | 437 } else if (bytes_read == 0) { |
438 /* Record EOF condition and report to caller when buffer runs dry */ | 438 /* Record EOF condition and report to caller when buffer runs dry */ |
439 ((PRFilePrivate *)secret)->eof = PR_TRUE; | 439 ((PRFilePrivate *)secret)->eof = PR_TRUE; |
440 } else /* if (bytes_read < 0) */ { | 440 } else /* if (bytes_read < 0) */ { |
441 mb->last_err = bytes_read; | 441 mb->last_err = bytes_read; |
442 } | 442 } |
443 } | 443 } |
444 | 444 |
445 void memio_GetWriteParams(memio_Private *secret, | 445 int memio_GetWriteParams(memio_Private *secret, |
446 const char **buf1, unsigned int *len1, | 446 const char **buf1, unsigned int *len1, |
447 const char **buf2, unsigned int *len2) | 447 const char **buf2, unsigned int *len2) |
448 { | 448 { |
449 struct memio_buffer* mb = &((PRFilePrivate *)secret)->writebuf; | 449 struct memio_buffer* mb = &((PRFilePrivate *)secret)->writebuf; |
450 PR_ASSERT(mb->bufsize); | 450 PR_ASSERT(mb->bufsize); |
451 | 451 |
| 452 if (mb->last_err) |
| 453 return mb->last_err; |
| 454 |
452 *buf1 = &mb->buf[mb->head]; | 455 *buf1 = &mb->buf[mb->head]; |
453 *len1 = memio_buffer_used_contiguous(mb); | 456 *len1 = memio_buffer_used_contiguous(mb); |
454 *buf2 = mb->buf; | 457 *buf2 = mb->buf; |
455 *len2 = memio_buffer_wrapped_bytes(mb); | 458 *len2 = memio_buffer_wrapped_bytes(mb); |
| 459 return 0; |
456 } | 460 } |
457 | 461 |
458 void memio_PutWriteResult(memio_Private *secret, int bytes_written) | 462 void memio_PutWriteResult(memio_Private *secret, int bytes_written) |
459 { | 463 { |
460 struct memio_buffer* mb = &((PRFilePrivate *)secret)->writebuf; | 464 struct memio_buffer* mb = &((PRFilePrivate *)secret)->writebuf; |
461 PR_ASSERT(mb->bufsize); | 465 PR_ASSERT(mb->bufsize); |
462 | 466 |
463 if (bytes_written > 0) { | 467 if (bytes_written > 0) { |
464 mb->head += bytes_written; | 468 mb->head += bytes_written; |
465 if (mb->head >= mb->bufsize) | 469 if (mb->head >= mb->bufsize) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); | 529 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); |
526 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); | 530 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); |
527 | 531 |
528 /* TODO: add more cases */ | 532 /* TODO: add more cases */ |
529 | 533 |
530 printf("Test passed\n"); | 534 printf("Test passed\n"); |
531 exit(0); | 535 exit(0); |
532 } | 536 } |
533 | 537 |
534 #endif | 538 #endif |
OLD | NEW |