Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
sync_socket_linux.cc
Go to the documentation of this file.
1// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5#include "platform/globals.h"
6#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
7
8#include "bin/sync_socket.h"
9
10#include <errno.h> // NOLINT
11
12#include "bin/fdutils.h"
13#include "bin/socket_base.h"
15
16namespace dart {
17namespace bin {
18
20 // Nothing to do on Linux.
21 return true;
22}
23
24static intptr_t Create(const RawAddr& addr) {
25 intptr_t fd;
26 intptr_t type = SOCK_STREAM | SOCK_CLOEXEC;
27 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, type, 0));
28 if (fd < 0) {
29 return -1;
30 }
31 return fd;
32}
33
34static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
35 intptr_t result = TEMP_FAILURE_RETRY(
36 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr)));
37 if (result == 0) {
38 return fd;
39 }
40 ASSERT(errno != EINPROGRESS);
42 return -1;
43}
44
45intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) {
46 intptr_t fd = Create(addr);
47 if (fd < 0) {
48 return fd;
49 }
50 return Connect(fd, addr);
51}
52
53intptr_t SynchronousSocket::Available(intptr_t fd) {
55}
56
57intptr_t SynchronousSocket::GetPort(intptr_t fd) {
58 return SocketBase::GetPort(fd);
59}
60
61SocketAddress* SynchronousSocket::GetRemotePeer(intptr_t fd, intptr_t* port) {
62 return SocketBase::GetRemotePeer(fd, port);
63}
64
65intptr_t SynchronousSocket::Read(intptr_t fd,
66 void* buffer,
67 intptr_t num_bytes) {
68 return SocketBase::Read(fd, buffer, num_bytes, SocketBase::kSync);
69}
70
71intptr_t SynchronousSocket::Write(intptr_t fd,
72 const void* buffer,
73 intptr_t num_bytes) {
74 return SocketBase::Write(fd, buffer, num_bytes, SocketBase::kSync);
75}
76
77void SynchronousSocket::ShutdownRead(intptr_t fd) {
78 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD));
79}
80
81void SynchronousSocket::ShutdownWrite(intptr_t fd) {
82 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR));
83}
84
85void SynchronousSocket::Close(intptr_t fd) {
86 return SocketBase::Close(fd);
87}
88
89} // namespace bin
90} // namespace dart
91
92#endif // defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
static sk_sp< Effect > Create()
static void SaveErrorAndClose(intptr_t fd)
static intptr_t GetAddrLength(const RawAddr &addr, bool unnamed_unix_socket=false)
static SocketAddress * GetRemotePeer(intptr_t fd, intptr_t *port)
static intptr_t Available(intptr_t fd)
static void Close(intptr_t fd)
static intptr_t Read(intptr_t fd, void *buffer, intptr_t num_bytes, SocketOpKind sync)
static intptr_t Write(intptr_t fd, const void *buffer, intptr_t num_bytes, SocketOpKind sync)
static intptr_t GetPort(intptr_t fd)
static SocketAddress * GetRemotePeer(intptr_t fd, intptr_t *port)
static intptr_t Available(intptr_t fd)
static intptr_t CreateConnect(const RawAddr &addr)
static void ShutdownRead(intptr_t fd)
static void Close(intptr_t fd)
static intptr_t Read(intptr_t fd, void *buffer, intptr_t num_bytes)
static intptr_t Write(intptr_t fd, const void *buffer, intptr_t num_bytes)
static intptr_t GetPort(intptr_t fd)
static void ShutdownWrite(intptr_t fd)
#define ASSERT(E)
static const uint8_t buffer[]
GAsyncResult * result
#define NO_RETRY_EXPECTED(expression)
#define VOID_NO_RETRY_EXPECTED(expression)
#define TEMP_FAILURE_RETRY(expression)