mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
Fuchsia sockets:
- Enable FDUtils::AvailableBytes. - Disable Socket::SetNoDelay. - Implement Socket::GetRemotePeer same as Linux. - Implement Socket::ParseAddress same as Linux. R=asiva@google.com Review URL: https://codereview.chromium.org/2522923002 .
This commit is contained in:
parent
366e727048
commit
b83fb06741
|
@ -71,8 +71,6 @@ bool FDUtils::IsBlocking(intptr_t fd, bool* is_blocking) {
|
|||
|
||||
|
||||
intptr_t FDUtils::AvailableBytes(intptr_t fd) {
|
||||
// TODO(MG-364): Enable this code when it is supported.
|
||||
#if 0
|
||||
int available; // ioctl for FIONREAD expects an 'int*' argument.
|
||||
int result = NO_RETRY_EXPECTED(ioctl(fd, FIONREAD, &available));
|
||||
if (result < 0) {
|
||||
|
@ -80,9 +78,6 @@ intptr_t FDUtils::AvailableBytes(intptr_t fd) {
|
|||
}
|
||||
ASSERT(available >= 0);
|
||||
return static_cast<intptr_t>(available);
|
||||
#endif
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -242,9 +242,14 @@ intptr_t Socket::GetPort(intptr_t fd) {
|
|||
|
||||
|
||||
SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) {
|
||||
LOG_ERR("Socket::GetRemotePeer is unimplemented\n");
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
ASSERT(fd >= 0);
|
||||
RawAddr raw;
|
||||
socklen_t size = sizeof(raw);
|
||||
if (NO_RETRY_EXPECTED(getpeername(fd, &raw.addr, &size))) {
|
||||
return NULL;
|
||||
}
|
||||
*port = SocketAddress::GetAddrPort(raw);
|
||||
return new SocketAddress(&raw.addr);
|
||||
}
|
||||
|
||||
|
||||
|
@ -324,9 +329,15 @@ bool Socket::ReverseLookup(const RawAddr& addr,
|
|||
|
||||
|
||||
bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) {
|
||||
LOG_ERR("Socket::ParseAddress is unimplemented\n");
|
||||
UNIMPLEMENTED();
|
||||
return false;
|
||||
int result;
|
||||
if (type == SocketAddress::TYPE_IPV4) {
|
||||
result = NO_RETRY_EXPECTED(inet_pton(AF_INET, address, &addr->in.sin_addr));
|
||||
} else {
|
||||
ASSERT(type == SocketAddress::TYPE_IPV6);
|
||||
result =
|
||||
NO_RETRY_EXPECTED(inet_pton(AF_INET6, address, &addr->in6.sin6_addr));
|
||||
}
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -478,10 +489,15 @@ bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
|
|||
|
||||
|
||||
bool Socket::SetNoDelay(intptr_t fd, bool enabled) {
|
||||
// TODO(US-94): Enable.
|
||||
#if 0
|
||||
int on = enabled ? 1 : 0;
|
||||
return NO_RETRY_EXPECTED(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
|
||||
reinterpret_cast<char*>(&on),
|
||||
sizeof(on))) == 0;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,20 @@
|
|||
import "dart:async";
|
||||
import "dart:io";
|
||||
|
||||
testAddressParse() async {
|
||||
print(new InternetAddress("1.0.2.3").rawAddress);
|
||||
print(new InternetAddress("1.0.2.3").type);
|
||||
|
||||
print(new InternetAddress("::1").rawAddress);
|
||||
print(new InternetAddress("::1").type);
|
||||
|
||||
try {
|
||||
print(new InternetAddress("localhost"));
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
testSimpleBind() async {
|
||||
var s = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0);
|
||||
print("port = ${s.port}");
|
||||
|
@ -20,6 +34,13 @@ testSimpleConnect() async {
|
|||
});
|
||||
var socket = await RawSocket.connect("127.0.0.1", server.port);
|
||||
print("socket port = ${socket.port}");
|
||||
if (socket.remoteAddress.address != "127.0.0.1" ||
|
||||
socket.remoteAddress.type != InternetAddressType.IP_V4) {
|
||||
throw "Bad remote address ${socket.remoteAddress}";
|
||||
}
|
||||
if (socket.remotePort is! int) {
|
||||
throw "Bad remote port ${socket.remotePort}";
|
||||
}
|
||||
await server.close();
|
||||
await socket.close();
|
||||
}
|
||||
|
@ -197,6 +218,10 @@ Future testGoogleUrl(SecurityContext context, String outcome) async {
|
|||
main() async {
|
||||
print("Hello, Fuchsia!");
|
||||
|
||||
print("testAddressParse");
|
||||
await testAddressParse();
|
||||
print("testAddressParse done");
|
||||
|
||||
print("testSimpleBind");
|
||||
await testSimpleBind();
|
||||
print("testSimpleBind done");
|
||||
|
@ -205,13 +230,14 @@ main() async {
|
|||
await testSimpleConnect();
|
||||
print("testSimpleConnect done");
|
||||
|
||||
// TODO(US-81): Enable.
|
||||
// print("testSimpleReadWrite");
|
||||
// await testSimpleReadWrite(dropReads: false);
|
||||
// print("testSimpleReadWrite done");
|
||||
|
||||
// print("testGoogleUrl");
|
||||
// await testGoogleUrl(null, 'pass');
|
||||
// print("testGoogleUrl done");
|
||||
print("testGoogleUrl");
|
||||
await testGoogleUrl(null, 'pass');
|
||||
print("testGoogleUrl done");
|
||||
|
||||
print("Goodbyte, Fuchsia!");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue