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

Unified Diff: src/platform/socket.h

Issue 151603004: A64: Synchronize with r16587. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform/mutex.cc ('k') | src/platform/socket.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/socket.h
diff --git a/src/platform/semaphore.h b/src/platform/socket.h
similarity index 50%
copy from src/platform/semaphore.h
copy to src/platform/socket.h
index 221c7a337526c275b536ecc51901d1762b8c0f67..6710692c544734cf882de92e13702686aed4e9e1 100644
--- a/src/platform/semaphore.h
+++ b/src/platform/socket.h
@@ -25,59 +25,60 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef V8_PLATFORM_SEMAPHORE_H_
-#define V8_PLATFORM_SEMAPHORE_H_
+#ifndef V8_PLATFORM_SOCKET_H_
+#define V8_PLATFORM_SOCKET_H_
-#include "lazy-instance.h"
+#include "globals.h"
#if V8_OS_WIN
#include "win32-headers.h"
#endif
-#if V8_OS_MACOSX
-#include <mach/semaphore.h> // NOLINT
-#elif V8_OS_POSIX
-#include <semaphore.h> // NOLINT
-#endif
-
namespace v8 {
namespace internal {
-// Forward declarations.
-class TimeDelta;
-
// ----------------------------------------------------------------------------
-// Semaphore
+// Socket
//
-// A semaphore object is a synchronization object that maintains a count. The
-// count is decremented each time a thread completes a wait for the semaphore
-// object and incremented each time a thread signals the semaphore. When the
-// count reaches zero, threads waiting for the semaphore blocks until the
-// count becomes non-zero.
-class Semaphore V8_FINAL {
+class Socket V8_FINAL {
public:
- explicit Semaphore(int count);
- ~Semaphore();
-
- // Increments the semaphore counter.
- void Signal();
-
- // Suspends the calling thread until the semaphore counter is non zero
- // and then decrements the semaphore counter.
- void Wait();
-
- // Suspends the calling thread until the counter is non zero or the timeout
- // time has passed. If timeout happens the return value is false and the
- // counter is unchanged. Otherwise the semaphore counter is decremented and
- // true is returned.
- bool WaitFor(const TimeDelta& rel_time) V8_WARN_UNUSED_RESULT;
-
-#if V8_OS_MACOSX
- typedef semaphore_t NativeHandle;
-#elif V8_OS_POSIX
- typedef sem_t NativeHandle;
+ Socket();
+ ~Socket() { Shutdown(); }
+
+ // Server initialization.
+ bool Bind(int port) V8_WARN_UNUSED_RESULT;
+ bool Listen(int backlog) V8_WARN_UNUSED_RESULT;
+ Socket* Accept() V8_WARN_UNUSED_RESULT;
+
+ // Client initialization.
+ bool Connect(const char* host, const char* port) V8_WARN_UNUSED_RESULT;
+
+ // Shutdown socket for both read and write. This causes blocking Send and
+ // Receive calls to exit. After |Shutdown()| the Socket object cannot be
+ // used for any communication.
+ bool Shutdown();
+
+ // Data Transimission
+ // Return 0 on failure.
+ int Send(const char* buffer, int length) V8_WARN_UNUSED_RESULT;
+ int Receive(char* buffer, int length) V8_WARN_UNUSED_RESULT;
+
+ // Set the value of the SO_REUSEADDR socket option.
+ bool SetReuseAddress(bool reuse_address);
+
+ V8_INLINE(bool IsValid()) const V8_WARN_UNUSED_RESULT {
+ return native_handle_ != kInvalidNativeHandle;
+ }
+
+ static int GetLastError() V8_WARN_UNUSED_RESULT;
+
+ // The implementation-defined native handle type.
+#if V8_OS_POSIX
+ typedef int NativeHandle;
+ static const NativeHandle kInvalidNativeHandle = -1;
#elif V8_OS_WIN
- typedef HANDLE NativeHandle;
+ typedef SOCKET NativeHandle;
+ static const NativeHandle kInvalidNativeHandle = INVALID_SOCKET;
#endif
NativeHandle& native_handle() V8_WARN_UNUSED_RESULT {
@@ -88,39 +89,13 @@ class Semaphore V8_FINAL {
}
private:
- NativeHandle native_handle_;
-
- DISALLOW_COPY_AND_ASSIGN(Semaphore);
-};
+ explicit Socket(NativeHandle native_handle) : native_handle_(native_handle) {}
+ NativeHandle native_handle_;
-// POD Semaphore initialized lazily (i.e. the first time Pointer() is called).
-// Usage:
-// // The following semaphore starts at 0.
-// static LazySemaphore<0>::type my_semaphore = LAZY_SEMAPHORE_INITIALIZER;
-//
-// void my_function() {
-// // Do something with my_semaphore.Pointer().
-// }
-//
-
-template <int N>
-struct CreateSemaphoreTrait {
- static Semaphore* Create() {
- return new Semaphore(N);
- }
-};
-
-template <int N>
-struct LazySemaphore {
- typedef typename LazyDynamicInstance<
- Semaphore,
- CreateSemaphoreTrait<N>,
- ThreadSafeInitOnceTrait>::type type;
+ DISALLOW_COPY_AND_ASSIGN(Socket);
};
-#define LAZY_SEMAPHORE_INITIALIZER LAZY_DYNAMIC_INSTANCE_INITIALIZER
-
} } // namespace v8::internal
-#endif // V8_PLATFORM_SEMAPHORE_H_
+#endif // V8_PLATFORM_SOCKET_H_
« no previous file with comments | « src/platform/mutex.cc ('k') | src/platform/socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698