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

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

Issue 12218035: Fix socket error reporting on Windows (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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/eventhandler_win.h ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "bin/eventhandler.h" 5 #include "bin/eventhandler.h"
6 6
7 #include <process.h> 7 #include <process.h>
8 #include <winsock2.h> 8 #include <winsock2.h>
9 #include <ws2tcpip.h> 9 #include <ws2tcpip.h>
10 #include <mswsock.h> 10 #include <mswsock.h>
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 buffer->GetBufferStart(), 254 buffer->GetBufferStart(),
255 buffer->GetBufferSize(), 255 buffer->GetBufferSize(),
256 NULL, 256 NULL,
257 buffer->GetCleanOverlapped()); 257 buffer->GetCleanOverlapped());
258 if (ok || GetLastError() == ERROR_IO_PENDING) { 258 if (ok || GetLastError() == ERROR_IO_PENDING) {
259 // Completing asynchronously. 259 // Completing asynchronously.
260 pending_read_ = buffer; 260 pending_read_ = buffer;
261 return true; 261 return true;
262 } 262 }
263 IOBuffer::DisposeBuffer(buffer); 263 IOBuffer::DisposeBuffer(buffer);
264 264 HandleIssueError();
265 if (GetLastError() == ERROR_BROKEN_PIPE) {
266 event_handler_->HandleClosed(this);
267 } else {
268 event_handler_->HandleError(this);
269 }
270 return false; 265 return false;
271 } else { 266 } else {
272 // Completing asynchronously through thread. 267 // Completing asynchronously through thread.
273 pending_read_ = buffer; 268 pending_read_ = buffer;
274 uint32_t tid; 269 uint32_t tid;
275 uintptr_t thread_handle = 270 uintptr_t thread_handle =
276 _beginthreadex(NULL, 32 * 1024, ReadFileThread, this, 0, &tid); 271 _beginthreadex(NULL, 32 * 1024, ReadFileThread, this, 0, &tid);
277 if (thread_handle == -1) { 272 if (thread_handle == -1) {
278 FATAL("Failed to start read file thread"); 273 FATAL("Failed to start read file thread");
279 } 274 }
(...skipping 14 matching lines...) Expand all
294 buffer->GetBufferStart(), 289 buffer->GetBufferStart(),
295 buffer->GetBufferSize(), 290 buffer->GetBufferSize(),
296 NULL, 291 NULL,
297 buffer->GetCleanOverlapped()); 292 buffer->GetCleanOverlapped());
298 if (ok || GetLastError() == ERROR_IO_PENDING) { 293 if (ok || GetLastError() == ERROR_IO_PENDING) {
299 // Completing asynchronously. 294 // Completing asynchronously.
300 pending_write_ = buffer; 295 pending_write_ = buffer;
301 return true; 296 return true;
302 } 297 }
303 IOBuffer::DisposeBuffer(buffer); 298 IOBuffer::DisposeBuffer(buffer);
299 HandleIssueError();
300 return false;
301 }
304 302
305 if (GetLastError() == ERROR_BROKEN_PIPE) { 303
304 void Handle::HandleIssueError() {
305 DWORD error = GetLastError();
306 if (error == ERROR_BROKEN_PIPE) {
306 event_handler_->HandleClosed(this); 307 event_handler_->HandleClosed(this);
307 } else { 308 } else {
308 event_handler_->HandleError(this); 309 event_handler_->HandleError(this);
309 } 310 }
310 return false; 311 SetLastError(error);
311 } 312 }
312 313
313 314
314 void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) { 315 void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) {
315 ScopedLock lock(this); 316 ScopedLock lock(this);
316 event_handler_ = event_handler; 317 event_handler_ = event_handler;
317 if (SupportsOverlappedIO() && completion_port_ == INVALID_HANDLE_VALUE) { 318 if (SupportsOverlappedIO() && completion_port_ == INVALID_HANDLE_VALUE) {
318 CreateCompletionPort(event_handler_->completion_port()); 319 CreateCompletionPort(event_handler_->completion_port());
319 } 320 }
320 } 321 }
321 322
322 323
323 bool FileHandle::IsClosed() { 324 bool FileHandle::IsClosed() {
324 return false; 325 return false;
325 } 326 }
326 327
327 328
328 void FileHandle::AfterClose() { 329 void FileHandle::AfterClose() {
329 } 330 }
330 331
331 332
333 void SocketHandle::HandleIssueError() {
334 int error = WSAGetLastError();
335 if (error == WSAECONNRESET) {
336 event_handler_->HandleClosed(this);
337 } else {
338 event_handler_->HandleError(this);
339 }
340 WSASetLastError(error);
341 }
342
343
332 bool ListenSocket::LoadAcceptEx() { 344 bool ListenSocket::LoadAcceptEx() {
333 // Load the AcceptEx function into memory using WSAIoctl. 345 // Load the AcceptEx function into memory using WSAIoctl.
334 // The WSAIoctl function is an extension of the ioctlsocket() 346 // The WSAIoctl function is an extension of the ioctlsocket()
335 // function that can use overlapped I/O. The function's 3rd 347 // function that can use overlapped I/O. The function's 3rd
336 // through 6th parameters are input and output buffers where 348 // through 6th parameters are input and output buffers where
337 // we pass the pointer to our AcceptEx function. This is used 349 // we pass the pointer to our AcceptEx function. This is used
338 // so that we can call the AcceptEx function directly, rather 350 // so that we can call the AcceptEx function directly, rather
339 // than refer to the Mswsock.lib library. 351 // than refer to the Mswsock.lib library.
340 GUID guid_accept_ex = WSAID_ACCEPTEX; 352 GUID guid_accept_ex = WSAID_ACCEPTEX;
341 DWORD bytes; 353 DWORD bytes;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 NULL, 569 NULL,
558 &flags, 570 &flags,
559 buffer->GetCleanOverlapped(), 571 buffer->GetCleanOverlapped(),
560 NULL); 572 NULL);
561 if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) { 573 if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) {
562 pending_read_ = buffer; 574 pending_read_ = buffer;
563 return true; 575 return true;
564 } 576 }
565 IOBuffer::DisposeBuffer(buffer); 577 IOBuffer::DisposeBuffer(buffer);
566 pending_read_ = NULL; 578 pending_read_ = NULL;
567 579 HandleIssueError();
568 if (WSAGetLastError() == WSAECONNRESET) {
569 event_handler_->HandleClosed(this);
570 } else {
571 event_handler_->HandleError(this);
572 }
573 return false; 580 return false;
574 } 581 }
575 582
576 583
577 bool ClientSocket::IssueWrite() { 584 bool ClientSocket::IssueWrite() {
578 ScopedLock lock(this); 585 ScopedLock lock(this);
579 ASSERT(completion_port_ != INVALID_HANDLE_VALUE); 586 ASSERT(completion_port_ != INVALID_HANDLE_VALUE);
580 ASSERT(pending_write_ != NULL); 587 ASSERT(pending_write_ != NULL);
581 ASSERT(pending_write_->operation() == IOBuffer::kWrite); 588 ASSERT(pending_write_->operation() == IOBuffer::kWrite);
582 589
583 int rc = WSASend(socket(), 590 int rc = WSASend(socket(),
584 pending_write_->GetWASBUF(), 591 pending_write_->GetWASBUF(),
585 1, 592 1,
586 NULL, 593 NULL,
587 0, 594 0,
588 pending_write_->GetCleanOverlapped(), 595 pending_write_->GetCleanOverlapped(),
589 NULL); 596 NULL);
590 if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) { 597 if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) {
591 return true; 598 return true;
592 } 599 }
593 IOBuffer::DisposeBuffer(pending_write_); 600 IOBuffer::DisposeBuffer(pending_write_);
594 pending_write_ = NULL; 601 pending_write_ = NULL;
595 602 HandleIssueError();
596 if (WSAGetLastError() == WSAECONNRESET) {
597 event_handler_->HandleClosed(this);
598 } else {
599 event_handler_->HandleError(this);
600 }
601 return false; 603 return false;
602 } 604 }
603 605
604 606
605 void ClientSocket::EnsureInitialized( 607 void ClientSocket::EnsureInitialized(
606 EventHandlerImplementation* event_handler) { 608 EventHandlerImplementation* event_handler) {
607 ScopedLock lock(this); 609 ScopedLock lock(this);
608 if (completion_port_ == INVALID_HANDLE_VALUE) { 610 if (completion_port_ == INVALID_HANDLE_VALUE) {
609 ASSERT(event_handler_ == NULL); 611 ASSERT(event_handler_ == NULL);
610 event_handler_ = event_handler; 612 event_handler_ = event_handler;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 // Initialize Winsock32 940 // Initialize Winsock32
939 if (!Socket::Initialize()) { 941 if (!Socket::Initialize()) {
940 FATAL("Failed to initialized Windows sockets"); 942 FATAL("Failed to initialized Windows sockets");
941 } 943 }
942 } 944 }
943 945
944 946
945 void EventHandlerImplementation::Shutdown() { 947 void EventHandlerImplementation::Shutdown() {
946 SendData(kShutdownId, 0, 0); 948 SendData(kShutdownId, 0, 0);
947 } 949 }
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698