31 #include <sys/types.h>
32 #include <sys/socket.h>
34 #include <netinet/in.h>
53 static void InitializeWinsock() {
55 int result = WSAStartup(MAKEWORD(1, 0), &wsa_data);
65 CallOnce(&initialize_winsock, &InitializeWinsock);
69 native_handle_ = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
73 bool Socket::Bind(
int port) {
76 if (!IsValid())
return false;
77 struct sockaddr_in sin;
78 memset(&sin, 0,
sizeof(sin));
79 sin.sin_family = AF_INET;
80 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
81 sin.sin_port = htons(static_cast<uint16_t>(port));
83 native_handle_, reinterpret_cast<struct sockaddr*>(&sin),
sizeof(sin));
88 bool Socket::Listen(
int backlog) {
89 if (!IsValid())
return false;
90 int result = ::listen(native_handle_, backlog);
95 Socket* Socket::Accept() {
96 if (!IsValid())
return NULL;
98 NativeHandle native_handle = ::accept(native_handle_,
NULL,
NULL);
99 if (native_handle == kInvalidNativeHandle) {
101 if (errno == EINTR)
continue;
105 return new Socket(native_handle);
110 bool Socket::Connect(
const char* host,
const char* port) {
113 if (!IsValid())
return false;
117 struct addrinfo hint;
118 memset(&hint, 0,
sizeof(hint));
119 hint.ai_family = AF_INET;
120 hint.ai_socktype = SOCK_STREAM;
121 hint.ai_protocol = IPPROTO_TCP;
122 int result = ::getaddrinfo(host, port, &hint, &info);
128 for (
struct addrinfo* ai = info; ai !=
NULL; ai = ai->ai_next) {
132 native_handle_, ai->ai_addr, static_cast<int>(ai->ai_addrlen));
138 if (errno == EINTR)
continue;
148 bool Socket::Shutdown() {
149 if (!IsValid())
return false;
152 int result = ::shutdown(native_handle_, SHUT_RDWR);
153 ::close(native_handle_);
155 int result = ::shutdown(native_handle_, SD_BOTH);
156 ::closesocket(native_handle_);
158 native_handle_ = kInvalidNativeHandle;
163 int Socket::Send(
const char* buffer,
int length) {
165 if (!IsValid())
return 0;
167 while (offset < length) {
168 int result = ::send(native_handle_, buffer + offset, length - offset, 0);
171 }
else if (result > 0) {
172 ASSERT(result <= length - offset);
176 if (errno == EINTR)
continue;
185 int Socket::Receive(
char* buffer,
int length) {
186 if (!IsValid())
return 0;
187 if (length <= 0)
return 0;
190 int result = ::recv(native_handle_, buffer, length, 0);
193 if (errno == EINTR)
continue;
202 bool Socket::SetReuseAddress(
bool reuse_address) {
203 if (!IsValid())
return 0;
204 int v = reuse_address ? 1 : 0;
205 int result = ::setsockopt(native_handle_, SOL_SOCKET, SO_REUSEADDR,
206 reinterpret_cast<char*>(&v),
sizeof(v));
212 int Socket::GetLastError() {
217 CallOnce(&initialize_winsock, &InitializeWinsock);
220 return ::WSAGetLastError();
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
#define CHECK_EQ(expected, value)
V8_DECLARE_ONCE(initialize_gc_once)
void CallOnce(OnceType *once, NoArgFunction init_func)
#define ASSERT(condition)
#define ASSERT_GE(v1, v2)
#define ASSERT_LT(v1, v2)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
#define ASSERT_NE(v1, v2)