0b3f4a1190
There are currently no tests of the error handling, as it is hard to create consistent tests. I have done some manual tests locally: * Lowering the number of file descriptors available (ulimit -n) and hitting that limit * Running two dart programs communicating and terminating one (using Ctrl-C) * Running two dart programs communicating on two machines and pulling out the network cable. If there is an error we always call the onError callback and never the onClosed callback. On Windows there is the issue that both closing the connection correctly and terminating one end gives the same error (ERROR_NETNAME_DELETED) so both are reported as connection close. Pulling out the network cable gives a different (real) error on Windows though. On Mac OS it turned out the for kqueue EV_EOF is also used to indicate errors with the error code set in the fflags field. EV_ERROR is only reported if there is an internal error in kevent processing (see http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/kqueue.2.html). R=ager@google.com BUG= TEST= Review URL: https://chromiumcodereview.appspot.com//9720045 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@5709 260f80e4-7a28-3924-810f-c04153c831b5
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef BIN_UTILS_H_
|
|
#define BIN_UTILS_H_
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "include/dart_api.h"
|
|
#include "platform/globals.h"
|
|
|
|
class OSError {
|
|
public:
|
|
enum SubSystem {
|
|
kSystem,
|
|
kGetAddressInfo,
|
|
kUnknown = -1
|
|
};
|
|
|
|
OSError();
|
|
OSError(int code, const char* message, SubSystem sub_system) {
|
|
sub_system_ = sub_system;
|
|
code_ = code;
|
|
message_ = NULL; // SetMessage will free existing message.
|
|
SetMessage(message);
|
|
}
|
|
virtual ~OSError() { free(message_); }
|
|
|
|
SubSystem sub_system() { return sub_system_; }
|
|
int code() { return code_; }
|
|
char* message() { return message_; }
|
|
void SetCodeAndMessage(SubSystem sub_system, int code);
|
|
|
|
private:
|
|
void set_sub_system(SubSystem sub_system) { sub_system_ = sub_system; }
|
|
void set_code(int code) { code_ = code; }
|
|
void SetMessage(const char* message) {
|
|
free(message_);
|
|
if (message == NULL) {
|
|
message_ = NULL;
|
|
} else {
|
|
message_ = strdup(message);
|
|
}
|
|
}
|
|
|
|
SubSystem sub_system_;
|
|
int code_;
|
|
char* message_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(OSError);
|
|
};
|
|
|
|
#endif // BIN_UTILS_H_
|