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

Side by Side Diff: runtime/bin/socket_linux.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_android.cc ('k') | runtime/bin/socket_macos.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_LINUX) 6 #if defined(TARGET_OS_LINUX)
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 return Socket::Connect(fd, addr, port); 88 return Socket::Connect(fd, addr, port);
89 } 89 }
90 90
91 91
92 intptr_t Socket::Available(intptr_t fd) { 92 intptr_t Socket::Available(intptr_t fd) {
93 return FDUtils::AvailableBytes(fd); 93 return FDUtils::AvailableBytes(fd);
94 } 94 }
95 95
96 96
97 int Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { 97 intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
98 ASSERT(fd >= 0); 98 ASSERT(fd >= 0);
99 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); 99 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
100 ASSERT(EAGAIN == EWOULDBLOCK); 100 ASSERT(EAGAIN == EWOULDBLOCK);
101 if (read_bytes == -1 && errno == EWOULDBLOCK) { 101 if (read_bytes == -1 && errno == EWOULDBLOCK) {
102 // If the read would block we need to retry and therefore return 0 102 // If the read would block we need to retry and therefore return 0
103 // as the number of bytes written. 103 // as the number of bytes written.
104 read_bytes = 0; 104 read_bytes = 0;
105 } 105 }
106 return read_bytes; 106 return read_bytes;
107 } 107 }
108 108
109 109
110 int Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes, 110 intptr_t Socket::RecvFrom(intptr_t fd, void* buffer, intptr_t num_bytes,
111 RawAddr* addr) { 111 RawAddr* addr) {
112 ASSERT(fd >= 0); 112 ASSERT(fd >= 0);
113 socklen_t addr_len = sizeof(addr->ss); 113 socklen_t addr_len = sizeof(addr->ss);
114 ssize_t read_bytes = TEMP_FAILURE_RETRY( 114 ssize_t read_bytes = TEMP_FAILURE_RETRY(
115 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); 115 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len));
116 if (read_bytes == -1 && errno == EWOULDBLOCK) { 116 if (read_bytes == -1 && errno == EWOULDBLOCK) {
117 // If the read would block we need to retry and therefore return 0 117 // If the read would block we need to retry and therefore return 0
118 // as the number of bytes written. 118 // as the number of bytes written.
119 read_bytes = 0; 119 read_bytes = 0;
120 } 120 }
121 return read_bytes; 121 return read_bytes;
122 } 122 }
123 123
124 124
125 int Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) { 125 intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
126 ASSERT(fd >= 0); 126 ASSERT(fd >= 0);
127 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); 127 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes));
128 ASSERT(EAGAIN == EWOULDBLOCK); 128 ASSERT(EAGAIN == EWOULDBLOCK);
129 if (written_bytes == -1 && errno == EWOULDBLOCK) { 129 if (written_bytes == -1 && errno == EWOULDBLOCK) {
130 // If the would block we need to retry and therefore return 0 as 130 // If the would block we need to retry and therefore return 0 as
131 // the number of bytes written. 131 // the number of bytes written.
132 written_bytes = 0; 132 written_bytes = 0;
133 } 133 }
134 return written_bytes; 134 return written_bytes;
135 } 135 }
136 136
137 137
138 int Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes, 138 intptr_t Socket::SendTo(intptr_t fd, const void* buffer, intptr_t num_bytes,
139 RawAddr addr) { 139 RawAddr addr) {
140 ASSERT(fd >= 0); 140 ASSERT(fd >= 0);
141 ssize_t written_bytes = TEMP_FAILURE_RETRY( 141 ssize_t written_bytes = TEMP_FAILURE_RETRY(
142 sendto(fd, buffer, num_bytes, 0, 142 sendto(fd, buffer, num_bytes, 0,
143 &addr.addr, SocketAddress::GetAddrLength(&addr))); 143 &addr.addr, SocketAddress::GetAddrLength(&addr)));
144 ASSERT(EAGAIN == EWOULDBLOCK); 144 ASSERT(EAGAIN == EWOULDBLOCK);
145 if (written_bytes == -1 && errno == EWOULDBLOCK) { 145 if (written_bytes == -1 && errno == EWOULDBLOCK) {
146 // 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
147 // the number of bytes written. 147 // the number of bytes written.
148 written_bytes = 0; 148 written_bytes = 0;
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 mreq.gr_interface = interfaceIndex; 560 mreq.gr_interface = interfaceIndex;
561 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr)); 561 memmove(&mreq.gr_group, &addr->ss, SocketAddress::GetAddrLength(addr));
562 return NO_RETRY_EXPECTED( 562 return NO_RETRY_EXPECTED(
563 setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0; 563 setsockopt(fd, proto, MCAST_LEAVE_GROUP, &mreq, sizeof(mreq))) == 0;
564 } 564 }
565 565
566 } // namespace bin 566 } // namespace bin
567 } // namespace dart 567 } // namespace dart
568 568
569 #endif // defined(TARGET_OS_LINUX) 569 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/socket_android.cc ('k') | runtime/bin/socket_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698