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 | #ifndef RUNTIME_BIN_SYNC_SOCKET_H_ |
6 | #define RUNTIME_BIN_SYNC_SOCKET_H_ |
7 | |
8 | #include "bin/socket_base.h" |
9 | #include "platform/globals.h" |
10 | |
11 | namespace dart { |
12 | namespace bin { |
13 | |
14 | class SynchronousSocket { |
15 | public: |
16 | explicit SynchronousSocket(intptr_t fd) : fd_(fd) {} |
17 | ~SynchronousSocket() { ASSERT(fd_ == kClosedFd); } |
18 | |
19 | intptr_t fd() const { return fd_; } |
20 | void SetClosedFd() { fd_ = kClosedFd; } |
21 | |
22 | static bool Initialize(); |
23 | |
24 | static intptr_t CreateConnect(const RawAddr& addr); |
25 | |
26 | static Dart_Handle SetSocketIdNativeField(Dart_Handle handle, |
27 | SynchronousSocket* socket); |
28 | static Dart_Handle GetSocketIdNativeField(Dart_Handle socket_obj, |
29 | SynchronousSocket** socket); |
30 | |
31 | static intptr_t Available(intptr_t fd); |
32 | static intptr_t GetPort(intptr_t fd); |
33 | static SocketAddress* GetRemotePeer(intptr_t fd, intptr_t* port); |
34 | static intptr_t Read(intptr_t fd, void* buffer, intptr_t num_bytes); |
35 | static intptr_t Write(intptr_t fd, const void* buffer, intptr_t num_bytes); |
36 | |
37 | static void ShutdownRead(intptr_t fd); |
38 | static void ShutdownWrite(intptr_t fd); |
39 | static void Close(intptr_t fd); |
40 | |
41 | private: |
42 | static const int kClosedFd = -1; |
43 | |
44 | intptr_t fd_; |
45 | |
46 | DISALLOW_COPY_AND_ASSIGN(SynchronousSocket); |
47 | }; |
48 | |
49 | } // namespace bin |
50 | } // namespace dart |
51 | |
52 | #endif // RUNTIME_BIN_SYNC_SOCKET_H_ |
53 |