| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 the V8 project 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 V8_PLATFORM_SOCKET_H_ | |
| 6 #define V8_PLATFORM_SOCKET_H_ | |
| 7 | |
| 8 #include "globals.h" | |
| 9 #if V8_OS_WIN | |
| 10 #include "win32-headers.h" | |
| 11 #endif | |
| 12 | |
| 13 namespace v8 { | |
| 14 namespace internal { | |
| 15 | |
| 16 // ---------------------------------------------------------------------------- | |
| 17 // Socket | |
| 18 // | |
| 19 | |
| 20 class Socket V8_FINAL { | |
| 21 public: | |
| 22 Socket(); | |
| 23 ~Socket() { Shutdown(); } | |
| 24 | |
| 25 // Server initialization. | |
| 26 bool Bind(int port) V8_WARN_UNUSED_RESULT; | |
| 27 bool Listen(int backlog) V8_WARN_UNUSED_RESULT; | |
| 28 Socket* Accept() V8_WARN_UNUSED_RESULT; | |
| 29 | |
| 30 // Client initialization. | |
| 31 bool Connect(const char* host, const char* port) V8_WARN_UNUSED_RESULT; | |
| 32 | |
| 33 // Shutdown socket for both read and write. This causes blocking Send and | |
| 34 // Receive calls to exit. After |Shutdown()| the Socket object cannot be | |
| 35 // used for any communication. | |
| 36 bool Shutdown(); | |
| 37 | |
| 38 // Data Transimission | |
| 39 // Return 0 on failure. | |
| 40 int Send(const char* buffer, int length) V8_WARN_UNUSED_RESULT; | |
| 41 int Receive(char* buffer, int length) V8_WARN_UNUSED_RESULT; | |
| 42 | |
| 43 // Set the value of the SO_REUSEADDR socket option. | |
| 44 bool SetReuseAddress(bool reuse_address); | |
| 45 | |
| 46 V8_INLINE bool IsValid() const { | |
| 47 return native_handle_ != kInvalidNativeHandle; | |
| 48 } | |
| 49 | |
| 50 static int GetLastError(); | |
| 51 | |
| 52 // The implementation-defined native handle type. | |
| 53 #if V8_OS_POSIX | |
| 54 typedef int NativeHandle; | |
| 55 static const NativeHandle kInvalidNativeHandle = -1; | |
| 56 #elif V8_OS_WIN | |
| 57 typedef SOCKET NativeHandle; | |
| 58 static const NativeHandle kInvalidNativeHandle = INVALID_SOCKET; | |
| 59 #endif | |
| 60 | |
| 61 NativeHandle& native_handle() { | |
| 62 return native_handle_; | |
| 63 } | |
| 64 const NativeHandle& native_handle() const { | |
| 65 return native_handle_; | |
| 66 } | |
| 67 | |
| 68 private: | |
| 69 explicit Socket(NativeHandle native_handle) : native_handle_(native_handle) {} | |
| 70 | |
| 71 NativeHandle native_handle_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(Socket); | |
| 74 }; | |
| 75 | |
| 76 } } // namespace v8::internal | |
| 77 | |
| 78 #endif // V8_PLATFORM_SOCKET_H_ | |
| OLD | NEW |