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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc

Issue 23456045: [NaCl SDK] nacl_io: Add initial support for getsockopt (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 4
5 #include "nacl_io/kernel_proxy.h" 5 #include "nacl_io/kernel_proxy.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <limits.h> 10 #include <limits.h>
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 } 1007 }
1008 } 1008 }
1009 } 1009 }
1010 } 1010 }
1011 } 1011 }
1012 1012
1013 return event_cnt; 1013 return event_cnt;
1014 } 1014 }
1015 1015
1016 1016
1017
1018 // Socket Functions 1017 // Socket Functions
1019 int KernelProxy::accept(int fd, struct sockaddr* addr, socklen_t* len) { 1018 int KernelProxy::accept(int fd, struct sockaddr* addr, socklen_t* len) {
1020 if (NULL == addr || NULL == len) { 1019 if (NULL == addr || NULL == len) {
1021 errno = EFAULT; 1020 errno = EFAULT;
1022 return -1; 1021 return -1;
1023 } 1022 }
1024 1023
1025 ScopedKernelHandle handle; 1024 ScopedKernelHandle handle;
1026 if (AcquireSocketHandle(fd, &handle) == -1) 1025 if (AcquireSocketHandle(fd, &handle) == -1)
1027 return -1; 1026 return -1;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 Error err = handle->socket_node()->GetSockName(addr, len); 1103 Error err = handle->socket_node()->GetSockName(addr, len);
1105 if (err != 0) { 1104 if (err != 0) {
1106 errno = err; 1105 errno = err;
1107 return -1; 1106 return -1;
1108 } 1107 }
1109 1108
1110 return 0; 1109 return 0;
1111 } 1110 }
1112 1111
1113 int KernelProxy::getsockopt(int fd, 1112 int KernelProxy::getsockopt(int fd,
1114 int lvl, 1113 int lvl,
1115 int optname, 1114 int optname,
1116 void* optval, 1115 void* optval,
1117 socklen_t* len) { 1116 socklen_t* len) {
1118 if (NULL == optval || NULL == len) { 1117 if (NULL == optval || NULL == len) {
1119 errno = EFAULT; 1118 errno = EFAULT;
1120 return -1; 1119 return -1;
1121 } 1120 }
1122 1121
1123 ScopedKernelHandle handle; 1122 ScopedKernelHandle handle;
1124 if (AcquireSocketHandle(fd, &handle) == -1) 1123 if (AcquireSocketHandle(fd, &handle) == -1)
1125 return -1; 1124 return -1;
1126 1125
1127 errno = EINVAL; 1126 Error err = handle->socket_node()->GetSockOpt(lvl, optname, optval, len);
1128 return -1; 1127 if (err != 0) {
1128 errno = err;
1129 return -1;
1130 }
1131
1132 return 0;
1129 } 1133 }
1130 1134
1131 int KernelProxy::listen(int fd, int backlog) { 1135 int KernelProxy::listen(int fd, int backlog) {
1132 ScopedKernelHandle handle; 1136 ScopedKernelHandle handle;
1133 if (AcquireSocketHandle(fd, &handle) == -1) 1137 if (AcquireSocketHandle(fd, &handle) == -1)
1134 return -1; 1138 return -1;
1135 1139
1136 errno = EOPNOTSUPP; 1140 errno = EOPNOTSUPP;
1137 return -1; 1141 return -1;
1138 } 1142 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 socklen_t len) { 1286 socklen_t len) {
1283 if (NULL == optval) { 1287 if (NULL == optval) {
1284 errno = EFAULT; 1288 errno = EFAULT;
1285 return -1; 1289 return -1;
1286 } 1290 }
1287 1291
1288 ScopedKernelHandle handle; 1292 ScopedKernelHandle handle;
1289 if (AcquireSocketHandle(fd, &handle) == -1) 1293 if (AcquireSocketHandle(fd, &handle) == -1)
1290 return -1; 1294 return -1;
1291 1295
1292 errno = EINVAL; 1296 Error err = handle->socket_node()->SetSockOpt(lvl, optname, optval, len);
1293 return -1; 1297 if (err != 0) {
1298 errno = err;
1299 return -1;
1300 }
1301
1302 return 0;
1294 } 1303 }
1295 1304
1296 int KernelProxy::shutdown(int fd, int how) { 1305 int KernelProxy::shutdown(int fd, int how) {
1297 ScopedKernelHandle handle; 1306 ScopedKernelHandle handle;
1298 if (AcquireSocketHandle(fd, &handle) == -1) 1307 if (AcquireSocketHandle(fd, &handle) == -1)
1299 return -1; 1308 return -1;
1300 1309
1301 Error err = handle->socket_node()->Shutdown(how); 1310 Error err = handle->socket_node()->Shutdown(how);
1302 if (err != 0) { 1311 if (err != 0) {
1303 errno = err; 1312 errno = err;
(...skipping 18 matching lines...) Expand all
1322 case SOCK_STREAM: 1331 case SOCK_STREAM:
1323 sock = new MountNodeTCP(stream_mount_.get()); 1332 sock = new MountNodeTCP(stream_mount_.get());
1324 break; 1333 break;
1325 1334
1326 default: 1335 default:
1327 errno = EPROTONOSUPPORT; 1336 errno = EPROTONOSUPPORT;
1328 return -1; 1337 return -1;
1329 } 1338 }
1330 1339
1331 ScopedMountNode node(sock); 1340 ScopedMountNode node(sock);
1332 if (sock->Init(S_IREAD | S_IWRITE) == 0) { 1341 Error rtn = sock->Init(S_IREAD | S_IWRITE);
1333 ScopedKernelHandle handle(new KernelHandle(stream_mount_, node)); 1342 if (rtn != 0) {
1334 return AllocateFD(handle); 1343 errno = rtn;
1344 return -1;
1335 } 1345 }
1336 1346
1337 // If we failed to init, assume we don't have access. 1347 ScopedKernelHandle handle(new KernelHandle(stream_mount_, node));
1338 return EACCES; 1348 return AllocateFD(handle);
1339 } 1349 }
1340 1350
1341 int KernelProxy::socketpair(int domain, int type, int protocol, int* sv) { 1351 int KernelProxy::socketpair(int domain, int type, int protocol, int* sv) {
1342 if (NULL == sv) { 1352 if (NULL == sv) {
1343 errno = EFAULT; 1353 errno = EFAULT;
1344 return -1; 1354 return -1;
1345 } 1355 }
1346 1356
1347 // Catch-22: We don't support AF_UNIX, but any other AF doesn't support 1357 // Catch-22: We don't support AF_UNIX, but any other AF doesn't support
1348 // socket pairs. Thus, this function always fails. 1358 // socket pairs. Thus, this function always fails.
(...skipping 24 matching lines...) Expand all
1373 errno = ENOTSOCK; 1383 errno = ENOTSOCK;
1374 return -1; 1384 return -1;
1375 } 1385 }
1376 1386
1377 return 0; 1387 return 0;
1378 } 1388 }
1379 1389
1380 #endif // PROVIDES_SOCKET_API 1390 #endif // PROVIDES_SOCKET_API
1381 1391
1382 } // namespace_nacl_io 1392 } // namespace_nacl_io
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698