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

Side by Side Diff: tests/srpc/cat.c

Issue 5622003: Restructure the structs/unions involved in SRPC argument passing. This will... (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 10 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
« no previous file with comments | « tests/ruby/main.c ('k') | tests/srpc/srpc_bidir.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2008 The Native Client Authors. All rights reserved. 2 * Copyright 2008 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can 3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file. 4 * be found in the LICENSE file.
5 */ 5 */
6 6
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <nacl/nacl_srpc.h> 10 #include <nacl/nacl_srpc.h>
(...skipping 24 matching lines...) Expand all
35 if (-1 != fstat(fd, &stb)) { 35 if (-1 != fstat(fd, &stb)) {
36 #define P(fmt, field) \ 36 #define P(fmt, field) \
37 do { printf(#field " = " fmt "\n", (int) stb.field); } while (0) 37 do { printf(#field " = " fmt "\n", (int) stb.field); } while (0)
38 38
39 P("0x%04x", st_mode); 39 P("0x%04x", st_mode);
40 P("0x%x", st_nlink); 40 P("0x%x", st_nlink);
41 P("0x%x", st_size); 41 P("0x%x", st_size);
42 P("%d", st_size); 42 P("%d", st_size);
43 #undef P 43 #undef P
44 } 44 }
45 bufsize = out_args[0]->u.caval.count; 45 bufsize = out_args[0]->u.count;
46 printf("read loop, up to %d chars\n", bufsize); 46 printf("read loop, up to %d chars\n", bufsize);
47 if ((stb.st_mode & S_IFMT) == S_IFSHM) { 47 if ((stb.st_mode & S_IFMT) == S_IFSHM) {
48 /* Chrome integration returns a shared memory descriptor for this now. */ 48 /* Chrome integration returns a shared memory descriptor for this now. */
49 char *file_map; 49 char *file_map;
50 printf("mmapping\n"); 50 printf("mmapping\n");
51 file_map = (char *) mmap(NULL, stb.st_size, PROT_READ, MAP_SHARED, fd, 0); 51 file_map = (char *) mmap(NULL, stb.st_size, PROT_READ, MAP_SHARED, fd, 0);
52 if (MAP_FAILED == file_map) { 52 if (MAP_FAILED == file_map) {
53 printf("map failed"); 53 printf("map failed");
54 done->Run(done); 54 done->Run(done);
55 return; 55 return;
56 } 56 }
57 for (nchar = 0; nchar < bufsize - 1; ++nchar) { 57 for (nchar = 0; nchar < bufsize - 1; ++nchar) {
58 ch = file_map[nchar]; 58 ch = file_map[nchar];
59 out_args[0]->u.caval.carr[nchar] = ch; 59 out_args[0]->arrays.carr[nchar] = ch;
60 putchar(ch); 60 putchar(ch);
61 } 61 }
62 out_args[0]->u.caval.carr[nchar] = '\0'; 62 out_args[0]->arrays.carr[nchar] = '\0';
63 printf("EOF\n"); 63 printf("EOF\n");
64 } else { 64 } else {
65 FILE *iob = fdopen(fd, "r"); 65 FILE *iob = fdopen(fd, "r");
66 printf("fdopening\n"); 66 printf("fdopening\n");
67 if (NULL == iob) { 67 if (NULL == iob) {
68 printf("fdopen failed"); 68 printf("fdopen failed");
69 done->Run(done); 69 done->Run(done);
70 return; 70 return;
71 } 71 }
72 for (nchar = 0; EOF != (ch = getc(iob)) && nchar < bufsize-1; ++nchar) { 72 for (nchar = 0; EOF != (ch = getc(iob)) && nchar < bufsize-1; ++nchar) {
73 out_args[0]->u.caval.carr[nchar] = ch; 73 out_args[0]->arrays.carr[nchar] = ch;
74 putchar(ch); 74 putchar(ch);
75 } 75 }
76 out_args[0]->u.caval.carr[nchar] = '\0'; 76 out_args[0]->arrays.carr[nchar] = '\0';
77 printf("EOF\n"); 77 printf("EOF\n");
78 fclose(iob); 78 fclose(iob);
79 } 79 }
80 printf("got %d bytes\n", nchar); 80 printf("got %d bytes\n", nchar);
81 printf("out param: %.*s\n", nchar, out_args[0]->u.caval.carr); 81 printf("out param: %.*s\n", nchar, out_args[0]->arrays.carr);
82 rpc->result = NACL_SRPC_RESULT_OK; 82 rpc->result = NACL_SRPC_RESULT_OK;
83 done->Run(done); 83 done->Run(done);
84 } 84 }
85 85
86 const struct NaClSrpcHandlerDesc srpc_methods[] = { 86 const struct NaClSrpcHandlerDesc srpc_methods[] = {
87 { "cat:h:C", Cat }, 87 { "cat:h:C", Cat },
88 { NULL, NULL }, 88 { NULL, NULL },
89 }; 89 };
90 90
91 int main() { 91 int main() {
92 if (!NaClSrpcModuleInit()) { 92 if (!NaClSrpcModuleInit()) {
93 return 1; 93 return 1;
94 } 94 }
95 if (!NaClSrpcAcceptClientConnection(srpc_methods)) { 95 if (!NaClSrpcAcceptClientConnection(srpc_methods)) {
96 return 1; 96 return 1;
97 } 97 }
98 NaClSrpcModuleFini(); 98 NaClSrpcModuleFini();
99 return 0; 99 return 0;
100 } 100 }
OLDNEW
« no previous file with comments | « tests/ruby/main.c ('k') | tests/srpc/srpc_bidir.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698