| Index: dart/runtime/bin/net/nss_memio.cc
|
| ===================================================================
|
| --- dart/runtime/bin/net/nss_memio.cc (revision 34162)
|
| +++ dart/runtime/bin/net/nss_memio.cc (working copy)
|
| @@ -3,6 +3,15 @@
|
| // found in the LICENSE file.
|
| // Written in NSPR style to also be suitable for adding to the NSS demo suite
|
|
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +// This file is a modified copy of Chromium's src/net/base/nss_memio.c.
|
| +// char* has been changed to uint8_t* everywhere, and C++ casts are used.
|
| +// Revision 257452 (this should agree with "nss_rev" in DEPS).
|
| +
|
| +
|
| /* memio is a simple NSPR I/O layer that lets you decouple NSS from
|
| * the real network. It's rather like openssl's memory bio,
|
| * and is useful when your app absolutely, positively doesn't
|
| @@ -55,6 +64,10 @@
|
|
|
| /* if set, empty I/O returns EOF instead of EWOULDBLOCK */
|
| int eof;
|
| +
|
| + /* if set, the number of bytes requested from readbuf that were not
|
| + * fulfilled (due to readbuf being empty) */
|
| + int read_requested;
|
| };
|
|
|
| /*--------------- private memio_buffer functions ---------------------*/
|
| @@ -94,6 +107,7 @@
|
| static void memio_buffer_destroy(struct memio_buffer *mb) {
|
| free(mb->buf);
|
| mb->buf = NULL;
|
| + mb->bufsize = 0;
|
| mb->head = 0;
|
| mb->tail = 0;
|
| }
|
| @@ -218,13 +232,24 @@
|
| PR_ASSERT(mb->bufsize);
|
| rv = memio_buffer_get(mb, buf, len);
|
| if (rv == 0 && !secret->eof) {
|
| + secret->read_requested = len;
|
| + /* If there is no more data in the buffer, report any pending errors
|
| + * that were previously observed. Note that both the readbuf and the
|
| + * writebuf are checked for errors, since the application may have
|
| + * encountered a socket error while writing that would otherwise not
|
| + * be reported until the application attempted to write again - which
|
| + * it may never do.
|
| + */
|
| if (mb->last_err)
|
| PR_SetError(mb->last_err, 0);
|
| + else if (secret->writebuf.last_err)
|
| + PR_SetError(secret->writebuf.last_err, 0);
|
| else
|
| PR_SetError(PR_WOULD_BLOCK_ERROR, 0);
|
| return -1;
|
| }
|
|
|
| + secret->read_requested = 0;
|
| return rv;
|
| }
|
|
|
| @@ -246,6 +271,11 @@
|
| mb = &secret->writebuf;
|
| PR_ASSERT(mb->bufsize);
|
|
|
| + /* Note that the read error state is not reported, because it cannot be
|
| + * reported until all buffered data has been read. If there is an error
|
| + * with the next layer, attempting to call Send again will report the
|
| + * error appropriately.
|
| + */
|
| if (mb->last_err) {
|
| PR_SetError(mb->last_err, 0);
|
| return -1;
|
| @@ -345,7 +375,7 @@
|
|
|
| /*--------------- public memio functions -----------------------*/
|
|
|
| -PRFileDesc *memio_CreateIOLayer(int bufsize) {
|
| +PRFileDesc *memio_CreateIOLayer(int readbufsize, int writebufsize) {
|
| PRFileDesc *fd;
|
| struct PRFilePrivate *secret;
|
| static PRCallOnceType once;
|
| @@ -356,8 +386,8 @@
|
| secret = static_cast<PRFilePrivate*>(malloc(sizeof(struct PRFilePrivate)));
|
| memset(secret, 0, sizeof(*secret));
|
|
|
| - memio_buffer_new(&secret->readbuf, bufsize);
|
| - memio_buffer_new(&secret->writebuf, bufsize);
|
| + memio_buffer_new(&secret->readbuf, readbufsize);
|
| + memio_buffer_new(&secret->writebuf, writebufsize);
|
| fd->secret = secret;
|
| return fd;
|
| }
|
| @@ -370,9 +400,14 @@
|
|
|
| memio_Private* memio_GetSecret(PRFileDesc* fd) {
|
| PRFileDesc* memiofd = PR_GetIdentitiesLayer(fd, memio_identity);
|
| - return reinterpret_cast<memio_Private*>(memiofd->secret);
|
| + struct PRFilePrivate *secret = memiofd->secret;
|
| + return reinterpret_cast<memio_Private*>(secret);
|
| }
|
|
|
| +int memio_GetReadRequest(memio_Private *secret) {
|
| + return reinterpret_cast<PRFilePrivate*>(secret)->read_requested;
|
| +}
|
| +
|
| int memio_GetReadParams(memio_Private* secret, uint8_t** buf) {
|
| struct memio_buffer* mb =
|
| &(reinterpret_cast<PRFilePrivate*>(secret)->readbuf);
|
| @@ -382,6 +417,14 @@
|
| return memio_buffer_unused_contiguous(mb);
|
| }
|
|
|
| +int memio_GetReadableBufferSize(memio_Private *secret) {
|
| + struct memio_buffer* mb =
|
| + &(reinterpret_cast<PRFilePrivate*>(secret)->readbuf);
|
| + PR_ASSERT(mb->bufsize);
|
| +
|
| + return memio_buffer_used_contiguous(mb);
|
| +}
|
| +
|
| void memio_PutReadResult(memio_Private *secret, int bytes_read) {
|
| struct memio_buffer* mb =
|
| &(reinterpret_cast<PRFilePrivate*>(secret)->readbuf);
|
|
|