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

Side by Side Diff: src/trusted/debug_stub/transport_common.cc

Issue 206493005: Provide chrome the option of learning the debug stub port chosen by nacl. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: review fixes Created 6 years, 8 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
« no previous file with comments | « src/trusted/debug_stub/transport.h ('k') | src/trusted/service_runtime/sel_ldr.h » ('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 (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <string> 12 #include <string>
13 13
14 #include "native_client/src/include/nacl_scoped_ptr.h" 14 #include "native_client/src/include/nacl_scoped_ptr.h"
15 #include "native_client/src/include/portability_sockets.h" 15 #include "native_client/src/include/portability_sockets.h"
16 #include "native_client/src/shared/platform/nacl_log.h" 16 #include "native_client/src/shared/platform/nacl_log.h"
17 #include "native_client/src/trusted/debug_stub/platform.h" 17 #include "native_client/src/trusted/debug_stub/platform.h"
18 #include "native_client/src/trusted/debug_stub/transport.h" 18 #include "native_client/src/trusted/debug_stub/transport.h"
19 #include "native_client/src/trusted/debug_stub/util.h" 19 #include "native_client/src/trusted/debug_stub/util.h"
20 #include "native_client/src/trusted/service_runtime/sel_ldr.h" 20 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
21 21
22 using gdb_rsp::stringvec; 22 using gdb_rsp::stringvec;
23 using gdb_rsp::StringSplit; 23 using gdb_rsp::StringSplit;
24 24
25 #if NACL_WINDOWS
26 typedef int socklen_t;
27 #endif
28
25 namespace port { 29 namespace port {
26 30
27 typedef int socklen_t;
28
29 class Transport : public ITransport { 31 class Transport : public ITransport {
30 public: 32 public:
31 Transport() 33 Transport()
32 : buf_(new char[kBufSize]), 34 : buf_(new char[kBufSize]),
33 pos_(0), 35 pos_(0),
34 size_(0) { 36 size_(0) {
35 handle_ = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 37 handle_ = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
36 #if NACL_WINDOWS 38 #if NACL_WINDOWS
37 CreateSocketEvent(); 39 CreateSocketEvent();
38 #endif 40 #endif
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 if (setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, 418 if (setsockopt(socket, IPPROTO_TCP, TCP_NODELAY,
417 reinterpret_cast<char *>(&nodelay), 419 reinterpret_cast<char *>(&nodelay),
418 sizeof(nodelay))) { 420 sizeof(nodelay))) {
419 NaClLog(LOG_WARNING, "Failed to set TCP_NODELAY option.\n"); 421 NaClLog(LOG_WARNING, "Failed to set TCP_NODELAY option.\n");
420 } 422 }
421 return new Transport(socket); 423 return new Transport(socket);
422 } 424 }
423 return NULL; 425 return NULL;
424 } 426 }
425 427
428 uint16_t SocketBinding::GetBoundPort() {
429 struct sockaddr_in saddr;
430 struct sockaddr *psaddr = reinterpret_cast<struct sockaddr *>(&saddr);
431 // Clearing sockaddr_in first appears to be necessary on Mac OS X.
432 memset(&saddr, 0, sizeof(saddr));
433 socklen_t addrlen = static_cast<socklen_t>(sizeof(saddr));
434 if (::getsockname(socket_handle_, psaddr, &addrlen)) {
435 NaClLog(LOG_ERROR, "Failed to retrieve bound address.\n");
436 return 0;
437 }
438 return ntohs(saddr.sin_port);
439 }
440
426 } // namespace port 441 } // namespace port
OLDNEW
« no previous file with comments | « src/trusted/debug_stub/transport.h ('k') | src/trusted/service_runtime/sel_ldr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698