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

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

Issue 109803002: Profiler Take 2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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) 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
11 #include <string.h> // NOLINT 11 #include <string.h> // NOLINT
12 #include <sys/stat.h> // NOLINT 12 #include <sys/stat.h> // NOLINT
13 #include <unistd.h> // NOLINT 13 #include <unistd.h> // NOLINT
14 #include <netinet/tcp.h> // NOLINT 14 #include <netinet/tcp.h> // NOLINT
15 15
16 #include "bin/fdutils.h" 16 #include "bin/fdutils.h"
17 #include "bin/file.h" 17 #include "bin/file.h"
18 #include "bin/log.h" 18 #include "bin/log.h"
19 #include "bin/signal_blocker.h"
19 #include "bin/socket.h" 20 #include "bin/socket.h"
20 21
21 22
22 namespace dart { 23 namespace dart {
23 namespace bin { 24 namespace bin {
24 25
25 SocketAddress::SocketAddress(struct sockaddr* sa) { 26 SocketAddress::SocketAddress(struct sockaddr* sa) {
26 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN); 27 ASSERT(INET6_ADDRSTRLEN >= INET_ADDRSTRLEN);
27 if (!Socket::FormatNumericAddress( 28 if (!Socket::FormatNumericAddress(
28 reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) { 29 reinterpret_cast<RawAddr*>(sa), as_string_, INET6_ADDRSTRLEN)) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 98 }
98 99
99 100
100 intptr_t Socket::Available(intptr_t fd) { 101 intptr_t Socket::Available(intptr_t fd) {
101 return FDUtils::AvailableBytes(fd); 102 return FDUtils::AvailableBytes(fd);
102 } 103 }
103 104
104 105
105 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { 106 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
106 ASSERT(fd >= 0); 107 ASSERT(fd >= 0);
108 // Block profile interrupts while making I/O call.
109 ThreadSignalBlocker tsb(SIGPROF);
107 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); 110 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
108 ASSERT(EAGAIN == EWOULDBLOCK); 111 ASSERT(EAGAIN == EWOULDBLOCK);
109 if (read_bytes == -1 && errno == EWOULDBLOCK) { 112 if (read_bytes == -1 && errno == EWOULDBLOCK) {
110 // If the read would block we need to retry and therefore return 0 113 // If the read would block we need to retry and therefore return 0
111 // as the number of bytes written. 114 // as the number of bytes written.
112 read_bytes = 0; 115 read_bytes = 0;
113 } 116 }
114 return read_bytes; 117 return read_bytes;
115 } 118 }
116 119
117 120
118 int Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes, 121 int Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes,
119 RawAddr* addr) { 122 RawAddr* addr) {
120 ASSERT(fd >= 0); 123 ASSERT(fd >= 0);
121 socklen_t addr_len = sizeof(addr->ss); 124 socklen_t addr_len = sizeof(addr->ss);
125 // Block profile interrupts while making I/O call.
126 ThreadSignalBlocker tsb(SIGPROF);
122 ssize_t read_bytes = 127 ssize_t read_bytes =
123 TEMP_FAILURE_RETRY( 128 TEMP_FAILURE_RETRY(
124 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); 129 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len));
125 if (read_bytes == -1 && errno == EWOULDBLOCK) { 130 if (read_bytes == -1 && errno == EWOULDBLOCK) {
126 // If the read would block we need to retry and therefore return 0 131 // If the read would block we need to retry and therefore return 0
127 // as the number of bytes written. 132 // as the number of bytes written.
128 read_bytes = 0; 133 read_bytes = 0;
129 } 134 }
130 return read_bytes; 135 return read_bytes;
131 } 136 }
132 137
133 138
134 int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { 139 int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
135 ASSERT(fd >= 0); 140 ASSERT(fd >= 0);
141 // Block profile interrupts while making I/O call.
142 ThreadSignalBlocker tsb(SIGPROF);
136 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); 143 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes));
137 ASSERT(EAGAIN == EWOULDBLOCK); 144 ASSERT(EAGAIN == EWOULDBLOCK);
138 if (written_bytes == -1 && errno == EWOULDBLOCK) { 145 if (written_bytes == -1 && errno == EWOULDBLOCK) {
139 // If the would block we need to retry and therefore return 0 as 146 // If the would block we need to retry and therefore return 0 as
140 // the number of bytes written. 147 // the number of bytes written.
141 written_bytes = 0; 148 written_bytes = 0;
142 } 149 }
143 return written_bytes; 150 return written_bytes;
144 } 151 }
145 152
146 153
147 int Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes, 154 int Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes,
148 RawAddr addr) { 155 RawAddr addr) {
149 ASSERT(fd >= 0); 156 ASSERT(fd >= 0);
157 // Block profile interrupts while making I/O call.
158 ThreadSignalBlocker tsb(SIGPROF);
150 ssize_t written_bytes = 159 ssize_t written_bytes =
151 TEMP_FAILURE_RETRY( 160 TEMP_FAILURE_RETRY(
152 sendto(fd, buffer, num_bytes, 0, 161 sendto(fd, buffer, num_bytes, 0,
153 &addr.addr, SocketAddress::GetAddrLength(&addr))); 162 &addr.addr, SocketAddress::GetAddrLength(&addr)));
154 ASSERT(EAGAIN == EWOULDBLOCK); 163 ASSERT(EAGAIN == EWOULDBLOCK);
155 if (written_bytes == -1 && errno == EWOULDBLOCK) { 164 if (written_bytes == -1 && errno == EWOULDBLOCK) {
156 // If the would block we need to retry and therefore return 0 as 165 // If the would block we need to retry and therefore return 0 as
157 // the number of bytes written. 166 // the number of bytes written.
158 written_bytes = 0; 167 written_bytes = 0;
159 } 168 }
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 mreq.gr_interface = interfaceIndex; 580 mreq.gr_interface = interfaceIndex;
572 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); 581 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr));
573 return TEMP_FAILURE_RETRY(setsockopt( 582 return TEMP_FAILURE_RETRY(setsockopt(
574 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; 583 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0;
575 } 584 }
576 585
577 } // namespace bin 586 } // namespace bin
578 } // namespace dart 587 } // namespace dart
579 588
580 #endif // defined(TARGET_OS_ANDROID) 589 #endif // defined(TARGET_OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698