Chromium Code Reviews| 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 } | 223 } |
| 224 | 224 |
| 225 secret = fd->secret; | 225 secret = fd->secret; |
| 226 mb = &secret->readbuf; | 226 mb = &secret->readbuf; |
| 227 PR_ASSERT(mb->bufsize); | 227 PR_ASSERT(mb->bufsize); |
| 228 rv = memio_buffer_get(mb, buf, len); | 228 rv = memio_buffer_get(mb, buf, len); |
| 229 if (rv == 0 && !secret->eof) { | 229 if (rv == 0 && !secret->eof) { |
| 230 secret->read_requested = len; | 230 secret->read_requested = len; |
| 231 if (mb->last_err) | 231 if (mb->last_err) |
| 232 PR_SetError(mb->last_err, 0); | 232 PR_SetError(mb->last_err, 0); |
| 233 else if (secret->writebuf.last_err) | |
| 234 PR_SetError(secret->writebuf.last_err, 0); | |
| 233 else | 235 else |
| 234 PR_SetError(PR_WOULD_BLOCK_ERROR, 0); | 236 PR_SetError(PR_WOULD_BLOCK_ERROR, 0); |
| 235 return -1; | 237 return -1; |
| 236 } | 238 } |
| 237 | 239 |
| 238 secret->read_requested = 0; | 240 secret->read_requested = 0; |
| 239 return rv; | 241 return rv; |
| 240 } | 242 } |
| 241 | 243 |
| 242 static int PR_CALLBACK memio_Read(PRFileDesc *fd, void *buf, PRInt32 len) | 244 static int PR_CALLBACK memio_Read(PRFileDesc *fd, void *buf, PRInt32 len) |
| 243 { | 245 { |
| 244 /* pull bytes from buffer */ | 246 /* pull bytes from buffer */ |
| 245 return memio_Recv(fd, buf, len, 0, PR_INTERVAL_NO_TIMEOUT); | 247 return memio_Recv(fd, buf, len, 0, PR_INTERVAL_NO_TIMEOUT); |
| 246 } | 248 } |
| 247 | 249 |
| 248 static int PR_CALLBACK memio_Send(PRFileDesc *fd, const void *buf, PRInt32 len, | 250 static int PR_CALLBACK memio_Send(PRFileDesc *fd, const void *buf, PRInt32 len, |
| 249 PRIntn flags, PRIntervalTime timeout) | 251 PRIntn flags, PRIntervalTime timeout) |
| 250 { | 252 { |
| 251 struct PRFilePrivate *secret; | 253 struct PRFilePrivate *secret; |
| 252 struct memio_buffer *mb; | 254 struct memio_buffer *mb; |
| 253 int rv; | 255 int rv; |
| 254 | 256 |
| 255 secret = fd->secret; | 257 secret = fd->secret; |
| 256 mb = &secret->writebuf; | 258 mb = &secret->writebuf; |
| 257 PR_ASSERT(mb->bufsize); | 259 PR_ASSERT(mb->bufsize); |
| 258 | 260 |
| 259 if (mb->last_err) { | 261 if (mb->last_err) { |
| 260 PR_SetError(mb->last_err, 0); | 262 PR_SetError(mb->last_err, 0); |
| 261 return -1; | 263 return -1; |
| 262 } | 264 } |
|
wtc
2013/06/14 21:45:07
Should we also check secret->readbuf.last_err here
| |
| 263 rv = memio_buffer_put(mb, buf, len); | 265 rv = memio_buffer_put(mb, buf, len); |
| 264 if (rv == 0) { | 266 if (rv == 0) { |
| 265 PR_SetError(PR_WOULD_BLOCK_ERROR, 0); | 267 PR_SetError(PR_WOULD_BLOCK_ERROR, 0); |
| 266 return -1; | 268 return -1; |
| 267 } | 269 } |
| 268 return rv; | 270 return rv; |
| 269 } | 271 } |
| 270 | 272 |
| 271 static int PR_CALLBACK memio_Write(PRFileDesc *fd, const void *buf, PRInt32 len) | 273 static int PR_CALLBACK memio_Write(PRFileDesc *fd, const void *buf, PRInt32 len) |
| 272 { | 274 { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); | 512 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); |
| 511 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); | 513 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); |
| 512 | 514 |
| 513 /* TODO: add more cases */ | 515 /* TODO: add more cases */ |
| 514 | 516 |
| 515 printf("Test passed\n"); | 517 printf("Test passed\n"); |
| 516 exit(0); | 518 exit(0); |
| 517 } | 519 } |
| 518 | 520 |
| 519 #endif | 521 #endif |
| OLD | NEW |