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

Side by Side Diff: runtime/bin/socket_win.cc

Issue 15966002: Add support for loading scripts from http (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/eventhandler.h" 9 #include "bin/eventhandler.h"
10 #include "bin/file.h" 10 #include "bin/file.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 NULL, 106 NULL,
107 host, 107 host,
108 &len); 108 &len);
109 if (err != 0) { 109 if (err != 0) {
110 Log::PrintErr("Error WSAAddressToString: %d\n", WSAGetLastError()); 110 Log::PrintErr("Error WSAAddressToString: %d\n", WSAGetLastError());
111 return false; 111 return false;
112 } 112 }
113 return true; 113 return true;
114 } 114 }
115 115
116 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) { 116
117 intptr_t Socket::Create(RawAddr addr) {
117 SOCKET s = socket(addr.ss.ss_family, SOCK_STREAM, 0); 118 SOCKET s = socket(addr.ss.ss_family, SOCK_STREAM, 0);
118 if (s == INVALID_SOCKET) { 119 if (s == INVALID_SOCKET) {
119 return -1; 120 return -1;
120 } 121 }
121 122
122 linger l; 123 linger l;
123 l.l_onoff = 1; 124 l.l_onoff = 1;
124 l.l_linger = 10; 125 l.l_linger = 10;
125 int status = setsockopt(s, 126 int status = setsockopt(s,
126 SOL_SOCKET, 127 SOL_SOCKET,
127 SO_LINGER, 128 SO_LINGER,
128 reinterpret_cast<char*>(&l), 129 reinterpret_cast<char*>(&l),
129 sizeof(l)); 130 sizeof(l));
130 if (status != NO_ERROR) { 131 if (status != NO_ERROR) {
131 FATAL("Failed setting SO_LINGER on socket"); 132 FATAL("Failed setting SO_LINGER on socket");
132 } 133 }
133 134
135 ClientSocket* client_socket = new ClientSocket(s);
136 return reinterpret_cast<intptr_t>(client_socket);
137 }
138
139
140 intptr_t Socket::Connect(intptr_t fd, RawAddr addr, const intptr_t port) {
141 ASSERT(reinterpret_cast<Handle*>(fd)->is_socket());
142 SocketHandle* handle = reinterpret_cast<SocketHandle*>(fd);
143 SOCKET s = handle->socket();
134 SocketAddress::SetAddrPort(&addr, port); 144 SocketAddress::SetAddrPort(&addr, port);
135 status = connect( 145 status = connect(
136 s, 146 s,
137 &addr.addr, 147 &addr.addr,
138 SocketAddress::GetAddrLength(addr)); 148 SocketAddress::GetAddrLength(addr));
139 if (status == SOCKET_ERROR) { 149 if (status == SOCKET_ERROR) {
140 DWORD rc = WSAGetLastError(); 150 DWORD rc = WSAGetLastError();
141 closesocket(s); 151 handle->close();
142 SetLastError(rc); 152 SetLastError(rc);
143 return -1; 153 return -1;
144 } 154 }
145 155 return fd;
146 ClientSocket* client_socket = new ClientSocket(s);
147 return reinterpret_cast<intptr_t>(client_socket);
148 } 156 }
149 157
150 158
159 intptr_t Socket::CreateConnect(RawAddr addr, const intptr_t port) {
160 intptr_t fd = Socket::Create(addr);
161 if (fd < 0) {
162 return fd;
163 }
164
165 return Socket::Connect(fd, addr, port);
166 }
167
168
151 void Socket::GetError(intptr_t fd, OSError* os_error) { 169 void Socket::GetError(intptr_t fd, OSError* os_error) {
152 Handle* handle = reinterpret_cast<Handle*>(fd); 170 Handle* handle = reinterpret_cast<Handle*>(fd);
153 os_error->SetCodeAndMessage(OSError::kSystem, handle->last_error()); 171 os_error->SetCodeAndMessage(OSError::kSystem, handle->last_error());
154 } 172 }
155 173
156 174
157 int Socket::GetType(intptr_t fd) { 175 int Socket::GetType(intptr_t fd) {
158 Handle* handle = reinterpret_cast<Handle*>(fd); 176 Handle* handle = reinterpret_cast<Handle*>(fd);
159 switch (GetFileType(handle->handle())) { 177 switch (GetFileType(handle->handle())) {
160 case FILE_TYPE_CHAR: return File::kTerminal; 178 case FILE_TYPE_CHAR: return File::kTerminal;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 IPPROTO_TCP, 346 IPPROTO_TCP,
329 TCP_NODELAY, 347 TCP_NODELAY,
330 reinterpret_cast<char *>(&on), 348 reinterpret_cast<char *>(&on),
331 sizeof(on)) == 0; 349 sizeof(on)) == 0;
332 } 350 }
333 351
334 } // namespace bin 352 } // namespace bin
335 } // namespace dart 353 } // namespace dart
336 354
337 #endif // defined(TARGET_OS_WINDOWS) 355 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698