Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: net/base/nss_memio.c

Issue 11633021: When using NSS, only schedule transport socket reads when the transport buffer is empty. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 struct memio_buffer readbuf; 48 struct memio_buffer readbuf;
49 49
50 /* write requests are satisfied from this buffer */ 50 /* write requests are satisfied from this buffer */
51 struct memio_buffer writebuf; 51 struct memio_buffer writebuf;
52 52
53 /* SSL needs to know socket peer's name */ 53 /* SSL needs to know socket peer's name */
54 PRNetAddr peername; 54 PRNetAddr peername;
55 55
56 /* if set, empty I/O returns EOF instead of EWOULDBLOCK */ 56 /* if set, empty I/O returns EOF instead of EWOULDBLOCK */
57 int eof; 57 int eof;
58
59 /* if set, the number of bytes requested from readbuf that were not
60 * fulfilled (due to readbuf being empty) */
61 int read_requested;
58 }; 62 };
59 63
60 /*--------------- private memio_buffer functions ---------------------*/ 64 /*--------------- private memio_buffer functions ---------------------*/
61 65
62 /* Forward declarations. */ 66 /* Forward declarations. */
63 67
64 /* Allocate a memio_buffer of given size. */ 68 /* Allocate a memio_buffer of given size. */
65 static void memio_buffer_new(struct memio_buffer *mb, int size); 69 static void memio_buffer_new(struct memio_buffer *mb, int size);
66 70
67 /* Deallocate a memio_buffer allocated by memio_buffer_new. */ 71 /* Deallocate a memio_buffer allocated by memio_buffer_new. */
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 if (flags) { 220 if (flags) {
217 PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0); 221 PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
218 return -1; 222 return -1;
219 } 223 }
220 224
221 secret = fd->secret; 225 secret = fd->secret;
222 mb = &secret->readbuf; 226 mb = &secret->readbuf;
223 PR_ASSERT(mb->bufsize); 227 PR_ASSERT(mb->bufsize);
224 rv = memio_buffer_get(mb, buf, len); 228 rv = memio_buffer_get(mb, buf, len);
225 if (rv == 0 && !secret->eof) { 229 if (rv == 0 && !secret->eof) {
230 secret->read_requested = len;
226 if (mb->last_err) 231 if (mb->last_err)
227 PR_SetError(mb->last_err, 0); 232 PR_SetError(mb->last_err, 0);
228 else 233 else
229 PR_SetError(PR_WOULD_BLOCK_ERROR, 0); 234 PR_SetError(PR_WOULD_BLOCK_ERROR, 0);
wtc 2012/12/20 02:41:22 Perhaps only this code path (when a read request o
230 return -1; 235 return -1;
236 } else {
wtc 2012/12/20 02:41:22 Don't add "else" here. Just do return -1
237 secret->read_requested = 0;
231 } 238 }
232 239
233 return rv; 240 return rv;
234 } 241 }
235 242
236 static int PR_CALLBACK memio_Read(PRFileDesc *fd, void *buf, PRInt32 len) 243 static int PR_CALLBACK memio_Read(PRFileDesc *fd, void *buf, PRInt32 len)
237 { 244 {
238 /* pull bytes from buffer */ 245 /* pull bytes from buffer */
239 return memio_Recv(fd, buf, len, 0, PR_INTERVAL_NO_TIMEOUT); 246 return memio_Recv(fd, buf, len, 0, PR_INTERVAL_NO_TIMEOUT);
240 } 247 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 secret->peername = *peername; 382 secret->peername = *peername;
376 } 383 }
377 384
378 memio_Private *memio_GetSecret(PRFileDesc *fd) 385 memio_Private *memio_GetSecret(PRFileDesc *fd)
379 { 386 {
380 PRFileDesc *memiofd = PR_GetIdentitiesLayer(fd, memio_identity); 387 PRFileDesc *memiofd = PR_GetIdentitiesLayer(fd, memio_identity);
381 struct PRFilePrivate *secret = memiofd->secret; 388 struct PRFilePrivate *secret = memiofd->secret;
382 return (memio_Private *)secret; 389 return (memio_Private *)secret;
383 } 390 }
384 391
392 int memio_GetReadRequest(memio_Private *secret)
393 {
394 return ((PRFilePrivate *)secret)->read_requested;
395 }
396
385 int memio_GetReadParams(memio_Private *secret, char **buf) 397 int memio_GetReadParams(memio_Private *secret, char **buf)
386 { 398 {
387 struct memio_buffer* mb = &((PRFilePrivate *)secret)->readbuf; 399 struct memio_buffer* mb = &((PRFilePrivate *)secret)->readbuf;
388 PR_ASSERT(mb->bufsize); 400 PR_ASSERT(mb->bufsize);
389 401
390 *buf = &mb->buf[mb->tail]; 402 *buf = &mb->buf[mb->tail];
391 return memio_buffer_unused_contiguous(mb); 403 return memio_buffer_unused_contiguous(mb);
392 } 404 }
393 405
394 void memio_PutReadResult(memio_Private *secret, int bytes_read) 406 void memio_PutReadResult(memio_Private *secret, int bytes_read)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0); 503 CHECKEQ(memio_buffer_unused_contiguous(&mb), 0);
492 CHECKEQ(memio_buffer_used_contiguous(&mb), 1); 504 CHECKEQ(memio_buffer_used_contiguous(&mb), 1);
493 505
494 /* TODO: add more cases */ 506 /* TODO: add more cases */
495 507
496 printf("Test passed\n"); 508 printf("Test passed\n");
497 exit(0); 509 exit(0);
498 } 510 }
499 511
500 #endif 512 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698