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

Unified Diff: runtime/bin/utils_win.cc

Issue 9720045: Extend dart:io error handling to all socket functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 8 years, 9 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 | « runtime/bin/utils_macos.cc ('k') | tests/standalone/src/io/SocketStreamCloseTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/utils_win.cc
diff --git a/runtime/bin/utils_win.cc b/runtime/bin/utils_win.cc
index a3813f4b437b274d207b376e97904799ea8ff2fa..0dba5b5f7af60d343302de0ca3c8961c561d5fef 100644
--- a/runtime/bin/utils_win.cc
+++ b/runtime/bin/utils_win.cc
@@ -6,26 +6,42 @@
#include "bin/utils.h"
-OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) {
- set_code(GetLastError());
-
- static const int kMaxMessageLength = 256;
- char message[kMaxMessageLength];
+static void FormatMessageIntoBuffer(DWORD code,
+ char* buffer,
+ int buffer_length) {
DWORD message_size =
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
- code_,
+ code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- message,
- kMaxMessageLength,
+ buffer,
+ buffer_length,
NULL);
if (message_size == 0) {
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
fprintf(stderr, "FormatMessage failed %d\n", GetLastError());
}
- snprintf(message, kMaxMessageLength, "OS Error %d", code_);
+ snprintf(buffer, buffer_length, "OS Error %d", code);
}
- message[kMaxMessageLength - 1] = '\0';
+ buffer[buffer_length - 1] = '\0';
+}
+
+
+OSError::OSError() : sub_system_(kSystem), code_(0), message_(NULL) {
+ set_code(GetLastError());
+ static const int kMaxMessageLength = 256;
+ char message[kMaxMessageLength];
+ FormatMessageIntoBuffer(code_, message, kMaxMessageLength);
+ SetMessage(message);
+}
+
+void OSError::SetCodeAndMessage(SubSystem sub_system, int code) {
+ set_sub_system(sub_system);
+ set_code(code);
+
+ static const int kMaxMessageLength = 256;
+ char message[kMaxMessageLength];
+ FormatMessageIntoBuffer(code_, message, kMaxMessageLength);
SetMessage(message);
}
« no previous file with comments | « runtime/bin/utils_macos.cc ('k') | tests/standalone/src/io/SocketStreamCloseTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698