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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/base.gyp ('k') | base/sync_socket_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sync_socket.h
===================================================================
--- base/sync_socket.h (revision 0)
+++ base/sync_socket.h (revision 0)
@@ -0,0 +1,66 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_SYNC_SOCKET_H_
+#define BASE_SYNC_SOCKET_H_
+
+// A socket abstraction used for sending and receiving plain
+// data. Because they are blocking, they can be used to perform
+// rudimentary cross-process synchronization with low latency.
+
+#include "base/basictypes.h"
+#if defined(OS_WIN)
+#include <windows.h>
+#endif
+#include <sys/types.h>
+
+
Paweł Hajdan Jr. 2009/11/24 06:44:23 nit: Unnecessary empty line.
sehr (please use chromium) 2009/11/24 16:13:18 Done.
+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.
+class SyncSocket {
+ public:
+#if defined(OS_WIN)
+ typedef HANDLE Handle;
+#else
+ typedef int Handle;
+#endif
+
+ // Creates a SyncSocket from a Handle. Used in transport.
+ explicit SyncSocket(Handle handle) : handle_(handle) { }
+ ~SyncSocket() { Close(); }
+
+ // Creates an unnamed pair of connected sockets.
+ // pair is a pointer to an array of two SyncSockets in which connected socket
+ // descriptors are returned. Returns true on success, false on failure.
+ static bool CreatePair(SyncSocket* pair[2]);
+
+ // Closes the SyncSocket. Returns true on success, false on failure.
+ bool Close();
+
+ // Sends the message to the remote peer of the SyncSocket.
+ // Note it is not safe to send messages from the same socket handle by
+ // multiple threads simultaneously.
+ // buffer is a pointer to the data to send.
+ // length is the length of the data to send (must be non-zero).
+ // Returns the number of bytes sent, or 0 upon failure.
+ size_t Send(const void* buffer, size_t length);
+
+ // Receives a message from an SyncSocket.
+ // buffer is a pointer to the buffer to receive data.
+ // length is the number of bytes of data to receive (must be non-zero).
+ // Returns the number of bytes received, or 0 upon failure.
+ size_t Receive(void* buffer, size_t length);
+
+ // Extracts the contained handle. Used for transferring between
+ // processes.
+ Handle handle() const { return handle_; }
+
+ private:
+ Handle handle_;
+
+ DISALLOW_COPY_AND_ASSIGN(SyncSocket);
+};
+
+} // namespace base
+
+#endif // BASE_SYNC_SOCKET_H_
Property changes on: base\sync_socket.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« 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