OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_SYNC_SOCKET_H_ | 5 #ifndef BASE_SYNC_SOCKET_H_ |
6 #define BASE_SYNC_SOCKET_H_ | 6 #define BASE_SYNC_SOCKET_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 // A socket abstraction used for sending and receiving plain | 9 // A socket abstraction used for sending and receiving plain |
10 // data. Because they are blocking, they can be used to perform | 10 // data. Because they are blocking, they can be used to perform |
11 // rudimentary cross-process synchronization with low latency. | 11 // rudimentary cross-process synchronization with low latency. |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
15 #include <windows.h> | 15 #include <windows.h> |
16 #endif | 16 #endif |
17 #include <sys/types.h> | 17 #include <sys/types.h> |
18 | 18 |
19 #include "base/base_export.h" | 19 #include "base/base_export.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 | 22 |
23 class BASE_EXPORT SyncSocket { | 23 class BASE_EXPORT SyncSocket { |
24 public: | 24 public: |
25 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
26 typedef HANDLE Handle; | 26 typedef HANDLE Handle; |
27 #else | 27 #else |
28 typedef int Handle; | 28 typedef int Handle; |
29 #endif | 29 #endif |
| 30 static const Handle kInvalidHandle; |
30 | 31 |
31 // Creates a SyncSocket from a Handle. Used in transport. | 32 // Creates a SyncSocket from a Handle. Used in transport. |
32 explicit SyncSocket(Handle handle) : handle_(handle) { } | 33 explicit SyncSocket(Handle handle) : handle_(handle) { } |
33 ~SyncSocket() { Close(); } | 34 ~SyncSocket() { Close(); } |
34 | 35 |
35 // Creates an unnamed pair of connected sockets. | 36 // Creates an unnamed pair of connected sockets. |
36 // pair is a pointer to an array of two SyncSockets in which connected socket | 37 // pair is a pointer to an array of two SyncSockets in which connected socket |
37 // descriptors are returned. Returns true on success, false on failure. | 38 // descriptors are returned. Returns true on success, false on failure. |
38 static bool CreatePair(SyncSocket* pair[2]); | 39 static bool CreatePair(SyncSocket* pair[2]); |
39 | 40 |
(...skipping 26 matching lines...) Expand all Loading... |
66 | 67 |
67 private: | 68 private: |
68 Handle handle_; | 69 Handle handle_; |
69 | 70 |
70 DISALLOW_COPY_AND_ASSIGN(SyncSocket); | 71 DISALLOW_COPY_AND_ASSIGN(SyncSocket); |
71 }; | 72 }; |
72 | 73 |
73 } // namespace base | 74 } // namespace base |
74 | 75 |
75 #endif // BASE_SYNC_SOCKET_H_ | 76 #endif // BASE_SYNC_SOCKET_H_ |
OLD | NEW |