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

Side by Side Diff: base/sync_socket.h

Issue 418004: This adds the first version of SyncSocket to base, along with a trivial unitt... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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 | Annotate | Revision Log
« no previous file with comments | « base/base.gyp ('k') | base/sync_socket_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_SYNC_SOCKET_H_
6 #define BASE_SYNC_SOCKET_H_
7
8 // A socket abstraction used for sending and receiving plain
9 // data. Because they are blocking, they can be used to perform
10 // rudimentary cross-process synchronization with low latency.
11
12 #include "base/basictypes.h"
13 #if defined(OS_WIN)
14 #include <windows.h>
15 #endif
16 #include <sys/types.h>
17
18
Paweł Hajdan Jr. 2009/11/24 06:44:23 nit: Unnecessary empty line.
sehr (please use chromium) 2009/11/24 16:13:18 Done.
19 namespace base {
Paweł Hajdan Jr. 2009/11/24 06:44:23 nit: But there should be one empty line below.
sehr (please use chromium) 2009/11/24 16:13:18 Done.
20 class SyncSocket {
21 public:
22 #if defined(OS_WIN)
23 typedef HANDLE Handle;
24 #else
25 typedef int Handle;
26 #endif
27
28 // Creates a SyncSocket from a Handle. Used in transport.
29 explicit SyncSocket(Handle handle) : handle_(handle) { }
30 ~SyncSocket() { Close(); }
31
32 // Creates an unnamed pair of connected sockets.
33 // pair is a pointer to an array of two SyncSockets in which connected socket
34 // descriptors are returned. Returns true on success, false on failure.
35 static bool CreatePair(SyncSocket* pair[2]);
36
37 // Closes the SyncSocket. Returns true on success, false on failure.
38 bool Close();
39
40 // Sends the message to the remote peer of the SyncSocket.
41 // Note it is not safe to send messages from the same socket handle by
42 // multiple threads simultaneously.
43 // buffer is a pointer to the data to send.
44 // length is the length of the data to send (must be non-zero).
45 // Returns the number of bytes sent, or 0 upon failure.
46 size_t Send(const void* buffer, size_t length);
47
48 // Receives a message from an SyncSocket.
49 // buffer is a pointer to the buffer to receive data.
50 // length is the number of bytes of data to receive (must be non-zero).
51 // Returns the number of bytes received, or 0 upon failure.
52 size_t Receive(void* buffer, size_t length);
53
54 // Extracts the contained handle. Used for transferring between
55 // processes.
56 Handle handle() const { return handle_; }
57
58 private:
59 Handle handle_;
60
61 DISALLOW_COPY_AND_ASSIGN(SyncSocket);
62 };
63
64 } // namespace base
65
66 #endif // BASE_SYNC_SOCKET_H_
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/sync_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698