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

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

Issue 312343002: - Fix truncation in Socket calls. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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
« no previous file with comments | « runtime/bin/socket.h ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 return Socket::Connect(fd, addr, port); 95 return Socket::Connect(fd, addr, port);
96 } 96 }
97 97
98 98
99 intptr_t Socket::Available(intptr_t fd) { 99 intptr_t Socket::Available(intptr_t fd) {
100 return FDUtils::AvailableBytes(fd); 100 return FDUtils::AvailableBytes(fd);
101 } 101 }
102 102
103 103
104 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { 104 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
105 ASSERT(fd >= 0); 105 ASSERT(fd >= 0);
106 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); 106 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
107 ASSERT(EAGAIN == EWOULDBLOCK); 107 ASSERT(EAGAIN == EWOULDBLOCK);
108 if (read_bytes == -1 && errno == EWOULDBLOCK) { 108 if (read_bytes == -1 && errno == EWOULDBLOCK) {
109 // If the read would block we need to retry and therefore return 0 109 // If the read would block we need to retry and therefore return 0
110 // as the number of bytes written. 110 // as the number of bytes written.
111 read_bytes = 0; 111 read_bytes = 0;
112 } 112 }
113 return read_bytes; 113 return read_bytes;
114 } 114 }
115 115
116 116
117 int Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes, 117 intptr_t Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes,
118 RawAddr* addr) { 118 RawAddr* addr) {
119 ASSERT(fd >= 0); 119 ASSERT(fd >= 0);
120 socklen_t addr_len = sizeof(addr->ss); 120 socklen_t addr_len = sizeof(addr->ss);
121 ssize_t read_bytes = TEMP_FAILURE_RETRY( 121 ssize_t read_bytes = TEMP_FAILURE_RETRY(
122 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); 122 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len));
123 if (read_bytes == -1 && errno == EWOULDBLOCK) { 123 if (read_bytes == -1 && errno == EWOULDBLOCK) {
124 // If the read would block we need to retry and therefore return 0 124 // If the read would block we need to retry and therefore return 0
125 // as the number of bytes written. 125 // as the number of bytes written.
126 read_bytes = 0; 126 read_bytes = 0;
127 } 127 }
128 return read_bytes; 128 return read_bytes;
129 } 129 }
130 130
131 131
132 int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { 132 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
133 ASSERT(fd >= 0); 133 ASSERT(fd >= 0);
134 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); 134 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes));
135 ASSERT(EAGAIN == EWOULDBLOCK); 135 ASSERT(EAGAIN == EWOULDBLOCK);
136 if (written_bytes == -1 && errno == EWOULDBLOCK) { 136 if (written_bytes == -1 && errno == EWOULDBLOCK) {
137 // If the would block we need to retry and therefore return 0 as 137 // If the would block we need to retry and therefore return 0 as
138 // the number of bytes written. 138 // the number of bytes written.
139 written_bytes = 0; 139 written_bytes = 0;
140 } 140 }
141 return written_bytes; 141 return written_bytes;
142 } 142 }
143 143
144 144
145 int Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes, 145 intptr_t Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes,
146 RawAddr addr) { 146 RawAddr addr) {
147 ASSERT(fd >= 0); 147 ASSERT(fd >= 0);
148 ssize_t written_bytes = TEMP_FAILURE_RETRY( 148 ssize_t written_bytes = TEMP_FAILURE_RETRY(
149 sendto(fd, buffer, num_bytes, 0, 149 sendto(fd, buffer, num_bytes, 0,
150 &addr.addr, SocketAddress::GetAddrLength(&addr))); 150 &addr.addr, SocketAddress::GetAddrLength(&addr)));
151 ASSERT(EAGAIN == EWOULDBLOCK); 151 ASSERT(EAGAIN == EWOULDBLOCK);
152 if (written_bytes == -1 && errno == EWOULDBLOCK) { 152 if (written_bytes == -1 && errno == EWOULDBLOCK) {
153 // If the would block we need to retry and therefore return 0 as 153 // If the would block we need to retry and therefore return 0 as
154 // the number of bytes written. 154 // the number of bytes written.
155 written_bytes = 0; 155 written_bytes = 0;
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 mreq.gr_interface = interfaceIndex; 561 mreq.gr_interface = interfaceIndex;
562 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); 562 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr));
563 return NO_RETRY_EXPECTED(setsockopt( 563 return NO_RETRY_EXPECTED(setsockopt(
564 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; 564 fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0;
565 } 565 }
566 566
567 } // namespace bin 567 } // namespace bin
568 } // namespace dart 568 } // namespace dart
569 569
570 #endif // defined(TARGET_OS_ANDROID) 570 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/bin/socket.h ('k') | runtime/bin/socket_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698