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

Side by Side Diff: runtime/bin/socket_android.cc

Issue 15966002: Add support for loading scripts from http (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include <errno.h> // NOLINT 8 #include <errno.h> // NOLINT
9 #include <stdio.h> // NOLINT 9 #include <stdio.h> // NOLINT
10 #include <stdlib.h> // NOLINT 10 #include <stdlib.h> // NOLINT
(...skipping 22 matching lines...) Expand all
33 addrinfo->ai_addrlen); 33 addrinfo->ai_addrlen);
34 } 34 }
35 35
36 36
37 bool Socket::Initialize() { 37 bool Socket::Initialize() {
38 // Nothing to do on Android. 38 // Nothing to do on Android.
39 return true; 39 return true;
40 } 40 }
41 41
42 42
43 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) { 43 intptr_t Socket::Create(RawAddr addr) {
44 intptr_t fd; 44 intptr_t fd;
45 45
46 fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0)); 46 fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0));
47 if (fd < 0) { 47 if (fd < 0) {
48 Log::PrintErr("Error CreateConnect: %s\n", strerror(errno)); 48 Log::PrintErr("Error Create: %s\n", strerror(errno));
49 return -1; 49 return -1;
50 } 50 }
51 51
52 FDUtils::SetCloseOnExec(fd); 52 FDUtils::SetCloseOnExec(fd);
53 Socket::SetNonBlocking(fd); 53 return fd;
54 }
54 55
56
57 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) {
55 SocketAddress::SetAddrPort(&addr, port); 58 SocketAddress::SetAddrPort(&addr, port);
56 intptr_t result = TEMP_FAILURE_RETRY( 59 intptr_t result = TEMP_FAILURE_RETRY(
57 connect(fd, 60 connect(fd,
58 &addr.addr, 61 &addr.addr,
59 SocketAddress::GetAddrLength(addr))); 62 SocketAddress::GetAddrLength(addr)));
60 if (result == 0 || errno == EINPROGRESS) { 63 if (result == 0 || errno == EINPROGRESS) {
61 return fd; 64 return fd;
62 } 65 }
63 TEMP_FAILURE_RETRY(close(fd)); 66 VOID_TEMP_FAILURE_RETRY(close(fd));
64 return -1; 67 return -1;
65 } 68 }
66 69
67 70
71 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) {
72 intptr_t fd = Socket::Create(addr);
73 if (fd < 0) {
74 return fd;
75 }
76
77 Socket::SetNonBlocking(fd);
78
79 return Socket::Connect(fd, addr, port);
80 }
81
82
68 intptr_t Socket::Available(intptr_t fd) { 83 intptr_t Socket::Available(intptr_t fd) {
69 return FDUtils::AvailableBytes(fd); 84 return FDUtils::AvailableBytes(fd);
70 } 85 }
71 86
72 87
73 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { 88 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
74 ASSERT(fd >= 0); 89 ASSERT(fd >= 0);
75 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); 90 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
76 ASSERT(EAGAIN == EWOULDBLOCK); 91 ASSERT(EAGAIN == EWOULDBLOCK);
77 if (read_bytes == -1 && errno == EWOULDBLOCK) { 92 if (read_bytes == -1 && errno == EWOULDBLOCK) {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 SOL_TCP, 306 SOL_TCP,
292 TCP_NODELAY, 307 TCP_NODELAY,
293 reinterpret_cast<char *>(&on), 308 reinterpret_cast<char *>(&on),
294 sizeof(on))) == 0; 309 sizeof(on))) == 0;
295 } 310 }
296 311
297 } // namespace bin 312 } // namespace bin
298 } // namespace dart 313 } // namespace dart
299 314
300 #endif // defined(TARGET_OS_ANDROID) 315 #endif // defined(TARGET_OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698