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

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

Issue 2814773004: Various fixes for sync socket implementation. (Closed)
Patch Set: Various fixes for sync socket implementation. 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/sync_socket_fuchsia.cc ('k') | runtime/bin/sync_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
(Empty)
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 #if !defined(DART_IO_DISABLED)
6
7 #include "platform/globals.h"
8 #if defined(HOST_OS_LINUX)
9
10 #include "bin/sync_socket.h"
11
12 #include <errno.h> // NOLINT
13
14 #include "bin/fdutils.h"
15 #include "platform/signal_blocker.h"
16
17 namespace dart {
18 namespace bin {
19
20 SynchronousSocket::SynchronousSocket(intptr_t fd) : fd_(fd) {}
21
22
23 void SynchronousSocket::SetClosedFd() {
24 fd_ = kClosedFd;
25 }
26
27
28 bool SynchronousSocket::Initialize() {
29 // Nothing to do on Linux.
30 return true;
31 }
32
33
34 static intptr_t Create(const RawAddr& addr) {
35 intptr_t fd;
36 intptr_t type = SOCK_STREAM | SOCK_CLOEXEC;
37 fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, type, 0));
38 if (fd < 0) {
39 return -1;
40 }
41 return fd;
42 }
43
44
45 static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
46 intptr_t result = TEMP_FAILURE_RETRY(
47 connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr)));
48 if (result == 0) {
49 return fd;
50 }
51 ASSERT(errno != EINPROGRESS);
52 FDUtils::FDUtils::SaveErrorAndClose(fd);
53 return -1;
54 }
55
56
57 intptr_t SynchronousSocket::CreateConnect(const RawAddr& addr) {
58 intptr_t fd = Create(addr);
59 if (fd < 0) {
60 return fd;
61 }
62 return Connect(fd, addr);
63 }
64
65
66 void SynchronousSocket::ShutdownRead(intptr_t fd) {
67 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_RD));
68 }
69
70
71 void SynchronousSocket::ShutdownWrite(intptr_t fd) {
72 VOID_NO_RETRY_EXPECTED(shutdown(fd, SHUT_WR));
73 }
74
75 } // namespace bin
76 } // namespace dart
77
78 #endif // defined(HOST_OS_LINUX)
79
80 #endif // !defined(DART_IO_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/sync_socket_fuchsia.cc ('k') | runtime/bin/sync_socket_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698