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

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

Issue 2830273002: [dart:io][windows] Implements RawSynchronousSocket (Closed)
Patch Set: Fix Linux build Created 3 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
« no previous file with comments | « runtime/bin/socket_base_linux.cc ('k') | runtime/bin/socket_base_win.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 #if !defined(DART_IO_DISABLED) 5 #if !defined(DART_IO_DISABLED)
6 6
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #if defined(HOST_OS_MACOS) 8 #if defined(HOST_OS_MACOS)
9 9
10 #include "bin/socket_base.h" 10 #include "bin/socket_base.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL || 57 return error_number == EADDRINUSE || error_number == EADDRNOTAVAIL ||
58 error_number == EINVAL; 58 error_number == EINVAL;
59 } 59 }
60 60
61 61
62 intptr_t SocketBase::Available(intptr_t fd) { 62 intptr_t SocketBase::Available(intptr_t fd) {
63 return FDUtils::AvailableBytes(fd); 63 return FDUtils::AvailableBytes(fd);
64 } 64 }
65 65
66 66
67 intptr_t SocketBase::Read(intptr_t fd, void* buffer, intptr_t num_bytes) { 67 intptr_t SocketBase::Read(intptr_t fd,
68 void* buffer,
69 intptr_t num_bytes,
70 SocketOpKind sync) {
68 ASSERT(fd >= 0); 71 ASSERT(fd >= 0);
69 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes)); 72 ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
70 ASSERT(EAGAIN == EWOULDBLOCK); 73 ASSERT(EAGAIN == EWOULDBLOCK);
71 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { 74 if ((sync == kAsync) && (read_bytes == -1) && (errno == EWOULDBLOCK)) {
72 // If the read would block we need to retry and therefore return 0 75 // If the read would block we need to retry and therefore return 0
73 // as the number of bytes written. 76 // as the number of bytes written.
74 read_bytes = 0; 77 read_bytes = 0;
75 } 78 }
76 return read_bytes; 79 return read_bytes;
77 } 80 }
78 81
79 82
80 intptr_t SocketBase::RecvFrom(intptr_t fd, 83 intptr_t SocketBase::RecvFrom(intptr_t fd,
81 void* buffer, 84 void* buffer,
82 intptr_t num_bytes, 85 intptr_t num_bytes,
83 RawAddr* addr) { 86 RawAddr* addr,
87 SocketOpKind sync) {
84 ASSERT(fd >= 0); 88 ASSERT(fd >= 0);
85 socklen_t addr_len = sizeof(addr->ss); 89 socklen_t addr_len = sizeof(addr->ss);
86 ssize_t read_bytes = TEMP_FAILURE_RETRY( 90 ssize_t read_bytes = TEMP_FAILURE_RETRY(
87 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len)); 91 recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len));
88 if ((read_bytes == -1) && (errno == EWOULDBLOCK)) { 92 if ((sync == kAsync) && (read_bytes == -1) && (errno == EWOULDBLOCK)) {
89 // If the read would block we need to retry and therefore return 0 93 // If the read would block we need to retry and therefore return 0
90 // as the number of bytes written. 94 // as the number of bytes written.
91 read_bytes = 0; 95 read_bytes = 0;
92 } 96 }
93 return read_bytes; 97 return read_bytes;
94 } 98 }
95 99
96 100
97 intptr_t SocketBase::Write(intptr_t fd, 101 intptr_t SocketBase::Write(intptr_t fd,
98 const void* buffer, 102 const void* buffer,
99 intptr_t num_bytes) { 103 intptr_t num_bytes,
104 SocketOpKind sync) {
100 ASSERT(fd >= 0); 105 ASSERT(fd >= 0);
101 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes)); 106 ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes));
102 ASSERT(EAGAIN == EWOULDBLOCK); 107 ASSERT(EAGAIN == EWOULDBLOCK);
103 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { 108 if ((sync == kAsync) && (written_bytes == -1) && (errno == EWOULDBLOCK)) {
104 // If the would block we need to retry and therefore return 0 as 109 // If the would block we need to retry and therefore return 0 as
105 // the number of bytes written. 110 // the number of bytes written.
106 written_bytes = 0; 111 written_bytes = 0;
107 } 112 }
108 return written_bytes; 113 return written_bytes;
109 } 114 }
110 115
111 116
112 intptr_t SocketBase::SendTo(intptr_t fd, 117 intptr_t SocketBase::SendTo(intptr_t fd,
113 const void* buffer, 118 const void* buffer,
114 intptr_t num_bytes, 119 intptr_t num_bytes,
115 const RawAddr& addr) { 120 const RawAddr& addr,
121 SocketOpKind sync) {
116 ASSERT(fd >= 0); 122 ASSERT(fd >= 0);
117 ssize_t written_bytes = 123 ssize_t written_bytes =
118 TEMP_FAILURE_RETRY(sendto(fd, buffer, num_bytes, 0, &addr.addr, 124 TEMP_FAILURE_RETRY(sendto(fd, buffer, num_bytes, 0, &addr.addr,
119 SocketAddress::GetAddrLength(addr))); 125 SocketAddress::GetAddrLength(addr)));
120 ASSERT(EAGAIN == EWOULDBLOCK); 126 ASSERT(EAGAIN == EWOULDBLOCK);
121 if ((written_bytes == -1) && (errno == EWOULDBLOCK)) { 127 if ((sync == kAsync) && (written_bytes == -1) && (errno == EWOULDBLOCK)) {
122 // If the would block we need to retry and therefore return 0 as 128 // If the would block we need to retry and therefore return 0 as
123 // the number of bytes written. 129 // the number of bytes written.
124 written_bytes = 0; 130 written_bytes = 0;
125 } 131 }
126 return written_bytes; 132 return written_bytes;
127 } 133 }
128 134
129 135
130 intptr_t SocketBase::GetPort(intptr_t fd) { 136 intptr_t SocketBase::GetPort(intptr_t fd) {
131 ASSERT(fd >= 0); 137 ASSERT(fd >= 0);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 int interfaceIndex) { 461 int interfaceIndex) {
456 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false); 462 return JoinOrLeaveMulticast(fd, addr, interface, interfaceIndex, false);
457 } 463 }
458 464
459 } // namespace bin 465 } // namespace bin
460 } // namespace dart 466 } // namespace dart
461 467
462 #endif // defined(HOST_OS_MACOS) 468 #endif // defined(HOST_OS_MACOS)
463 469
464 #endif // !defined(DART_IO_DISABLED) 470 #endif // !defined(DART_IO_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/socket_base_linux.cc ('k') | runtime/bin/socket_base_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698