Cleanup in //runtime/bin
R=iposva@google.com Review URL: https://codereview.chromium.org/1800863002 .
This commit is contained in:
@@ -38,10 +38,9 @@ static void LoadPatchFiles(Dart_Handle library,
|
||||
|
||||
// Prepend the patch library URI to form a unique script URI for the patch.
|
||||
intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]);
|
||||
char* patch_filename = reinterpret_cast<char*>(malloc(len + 1));
|
||||
char* patch_filename = DartUtils::ScopedCString(len + 1);
|
||||
snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]);
|
||||
Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename);
|
||||
free(patch_filename);
|
||||
|
||||
DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src));
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name,
|
||||
int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries);
|
||||
for (int i = 0; i < num_entries; i++) {
|
||||
struct NativeEntries* entry = &(BuiltinEntries[i]);
|
||||
if (!strcmp(function_name, entry->name_) &&
|
||||
if ((strcmp(function_name, entry->name_) == 0) &&
|
||||
(entry->argument_count_ == argument_count)) {
|
||||
return reinterpret_cast<Dart_NativeFunction>(entry->function_);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name,
|
||||
int num_entries = sizeof(BuiltinEntries) / sizeof(struct NativeEntries);
|
||||
for (int i = 0; i < num_entries; i++) {
|
||||
struct NativeEntries* entry = &(BuiltinEntries[i]);
|
||||
if (!strcmp(function_name, entry->name_) &&
|
||||
if ((strcmp(function_name, entry->name_) == 0) &&
|
||||
(entry->argument_count_ == argument_count)) {
|
||||
return reinterpret_cast<Dart_NativeFunction>(entry->function_);
|
||||
}
|
||||
@@ -88,7 +88,9 @@ void FUNCTION_NAME(Builtin_PrintString)(Dart_NativeArguments args) {
|
||||
uint8_t* chars = NULL;
|
||||
Dart_Handle str = Dart_GetNativeArgument(args, 0);
|
||||
Dart_Handle result = Dart_StringToUTF8(str, &chars, &length);
|
||||
if (Dart_IsError(result)) Dart_PropagateError(result);
|
||||
if (Dart_IsError(result)) {
|
||||
Dart_PropagateError(result);
|
||||
}
|
||||
|
||||
// Uses fwrite to support printing NUL bytes.
|
||||
intptr_t res = fwrite(chars, 1, length, stdout);
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/io_natives.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
#include "bin/crypto.h"
|
||||
#include "bin/fdutils.h"
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
namespace dart {
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
#include "bin/crypto.h"
|
||||
#include "bin/fdutils.h"
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
namespace dart {
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
#include "bin/crypto.h"
|
||||
#include "bin/fdutils.h"
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
namespace dart {
|
||||
|
||||
+12
-11
@@ -8,7 +8,6 @@
|
||||
#include "include/dart_api.h"
|
||||
#include "platform/assert.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -28,7 +27,7 @@ void FUNCTION_NAME(Directory_SetCurrent)(Dart_NativeArguments args) {
|
||||
if (argc == 1) {
|
||||
path = Dart_GetNativeArgument(args, 0);
|
||||
}
|
||||
if (argc != 1 || !Dart_IsString(path)) {
|
||||
if ((argc != 1) || !Dart_IsString(path)) {
|
||||
Dart_SetReturnValue(args, DartUtils::NewDartArgumentError(NULL));
|
||||
} else {
|
||||
if (Directory::SetCurrent(DartUtils::GetStringValue(path))) {
|
||||
@@ -66,8 +65,7 @@ void FUNCTION_NAME(Directory_Create)(Dart_NativeArguments args) {
|
||||
}
|
||||
|
||||
|
||||
void FUNCTION_NAME(Directory_SystemTemp)(
|
||||
Dart_NativeArguments args) {
|
||||
void FUNCTION_NAME(Directory_SystemTemp)(Dart_NativeArguments args) {
|
||||
const char* result = Directory::SystemTemp();
|
||||
Dart_SetReturnValue(args, DartUtils::NewString(result));
|
||||
}
|
||||
@@ -127,7 +125,9 @@ void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) {
|
||||
Dart_Null(),
|
||||
0,
|
||||
NULL);
|
||||
if (Dart_IsError(results)) Dart_PropagateError(results);
|
||||
if (Dart_IsError(results)) {
|
||||
Dart_PropagateError(results);
|
||||
}
|
||||
SyncDirectoryListing sync_listing(results,
|
||||
DartUtils::GetStringValue(path),
|
||||
DartUtils::GetBooleanValue(recursive),
|
||||
@@ -138,7 +138,7 @@ void FUNCTION_NAME(Directory_List)(Dart_NativeArguments args) {
|
||||
|
||||
|
||||
CObject* Directory::CreateRequest(const CObjectArray& request) {
|
||||
if (request.Length() == 1 && request[0]->IsString()) {
|
||||
if ((request.Length() == 1) && request[0]->IsString()) {
|
||||
CObjectString path(request[0]);
|
||||
if (Directory::Create(path.CString())) {
|
||||
return CObject::True();
|
||||
@@ -151,7 +151,8 @@ CObject* Directory::CreateRequest(const CObjectArray& request) {
|
||||
|
||||
|
||||
CObject* Directory::DeleteRequest(const CObjectArray& request) {
|
||||
if (request.Length() == 2 && request[0]->IsString() && request[1]->IsBool()) {
|
||||
if ((request.Length() == 2) &&
|
||||
request[0]->IsString() && request[1]->IsBool()) {
|
||||
CObjectString path(request[0]);
|
||||
CObjectBool recursive(request[1]);
|
||||
if (Directory::Delete(path.CString(), recursive.Value())) {
|
||||
@@ -167,7 +168,7 @@ CObject* Directory::DeleteRequest(const CObjectArray& request) {
|
||||
CObject* Directory::ExistsRequest(const CObjectArray& request) {
|
||||
static const int kExists = 1;
|
||||
static const int kDoesNotExist = 0;
|
||||
if (request.Length() == 1 && request[0]->IsString()) {
|
||||
if ((request.Length() == 1) && request[0]->IsString()) {
|
||||
CObjectString path(request[0]);
|
||||
Directory::ExistsResult result = Directory::Exists(path.CString());
|
||||
if (result == Directory::EXISTS) {
|
||||
@@ -183,7 +184,7 @@ CObject* Directory::ExistsRequest(const CObjectArray& request) {
|
||||
|
||||
|
||||
CObject* Directory::CreateTempRequest(const CObjectArray& request) {
|
||||
if (request.Length() == 1 && request[0]->IsString()) {
|
||||
if ((request.Length() == 1) && request[0]->IsString()) {
|
||||
CObjectString path(request[0]);
|
||||
const char* result = Directory::CreateTemp(path.CString());
|
||||
if (result != NULL) {
|
||||
@@ -209,7 +210,7 @@ static CObject* CreateIllegalArgumentError() {
|
||||
|
||||
|
||||
CObject* Directory::ListStartRequest(const CObjectArray& request) {
|
||||
if (request.Length() == 3 &&
|
||||
if ((request.Length() == 3) &&
|
||||
request[0]->IsString() &&
|
||||
request[1]->IsBool() &&
|
||||
request[2]->IsBool()) {
|
||||
@@ -273,7 +274,7 @@ CObject* Directory::ListStopRequest(const CObjectArray& request) {
|
||||
|
||||
|
||||
CObject* Directory::RenameRequest(const CObjectArray& request) {
|
||||
if (request.Length() == 2 &&
|
||||
if ((request.Length() == 2) &&
|
||||
request[0]->IsString() &&
|
||||
request[1]->IsString()) {
|
||||
CObjectString path(request[0]);
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "bin/thread.h"
|
||||
#include "platform/globals.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -366,9 +366,8 @@ Directory::ExistsResult Directory::Exists(const char* dir_name) {
|
||||
char* Directory::CurrentNoScope() {
|
||||
// Android's getcwd adheres closely to the POSIX standard. It won't
|
||||
// allocate memory. We need to make our own copy.
|
||||
|
||||
char buffer[PATH_MAX];
|
||||
if (NULL == getcwd(buffer, PATH_MAX)) {
|
||||
if (getcwd(buffer, PATH_MAX) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -377,15 +376,17 @@ char* Directory::CurrentNoScope() {
|
||||
|
||||
|
||||
const char* Directory::Current() {
|
||||
char* result = DartUtils::ScopedCString(PATH_MAX);
|
||||
ASSERT(result != NULL);
|
||||
return getcwd(result, PATH_MAX);
|
||||
char buffer[PATH_MAX];
|
||||
if (getcwd(buffer, PATH_MAX) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return DartUtils::ScopedCopyCString(buffer);
|
||||
}
|
||||
|
||||
|
||||
bool Directory::SetCurrent(const char* path) {
|
||||
int result = NO_RETRY_EXPECTED(chdir(path));
|
||||
return result == 0;
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -366,11 +366,7 @@ Directory::ExistsResult Directory::Exists(const char* dir_name) {
|
||||
|
||||
|
||||
char* Directory::CurrentNoScope() {
|
||||
char buffer[PATH_MAX];
|
||||
if (getcwd(buffer, PATH_MAX) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return strdup(buffer);
|
||||
return getcwd(NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -384,7 +380,7 @@ const char* Directory::Current() {
|
||||
|
||||
|
||||
bool Directory::SetCurrent(const char* path) {
|
||||
return NO_RETRY_EXPECTED(chdir(path)) == 0;
|
||||
return (NO_RETRY_EXPECTED(chdir(path)) == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -469,7 +465,7 @@ bool Directory::Rename(const char* path, const char* new_path) {
|
||||
if (exists != EXISTS) {
|
||||
return false;
|
||||
}
|
||||
return NO_RETRY_EXPECTED(rename(path, new_path)) == 0;
|
||||
return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0);
|
||||
}
|
||||
|
||||
} // namespace bin
|
||||
|
||||
@@ -369,15 +369,17 @@ char* Directory::CurrentNoScope() {
|
||||
|
||||
|
||||
const char* Directory::Current() {
|
||||
char* result = DartUtils::ScopedCString(PATH_MAX);
|
||||
ASSERT(result != NULL);
|
||||
return getcwd(result, PATH_MAX);
|
||||
char buffer[PATH_MAX];
|
||||
if (getcwd(buffer, PATH_MAX) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return DartUtils::ScopedCopyCString(buffer);
|
||||
}
|
||||
|
||||
|
||||
bool Directory::SetCurrent(const char* path) {
|
||||
int result = NO_RETRY_EXPECTED(chdir(path));
|
||||
return result == 0;
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ bool ShouldCaptureStdout();
|
||||
// Should Stderr events be captured?
|
||||
bool ShouldCaptureStderr();
|
||||
|
||||
|
||||
} // namespace bin
|
||||
} // namespace dart
|
||||
|
||||
|
||||
@@ -10,11 +10,9 @@
|
||||
|
||||
#include "include/dart_api.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
void TimeoutQueue::UpdateTimeout(Dart_Port port, int64_t timeout) {
|
||||
// Find port if present.
|
||||
Timeout* last = NULL;
|
||||
@@ -47,8 +45,8 @@ void TimeoutQueue::UpdateTimeout(Dart_Port port, int64_t timeout) {
|
||||
next_timeout_ = NULL;
|
||||
current = timeouts_;
|
||||
while (current != NULL) {
|
||||
if (next_timeout_ == NULL ||
|
||||
current->timeout() < next_timeout_->timeout()) {
|
||||
if ((next_timeout_ == NULL) ||
|
||||
(current->timeout() < next_timeout_->timeout())) {
|
||||
next_timeout_ = current;
|
||||
}
|
||||
current = current->next();
|
||||
@@ -78,7 +76,9 @@ void EventHandler::NotifyShutdownDone() {
|
||||
|
||||
|
||||
void EventHandler::Stop() {
|
||||
if (event_handler == NULL) return;
|
||||
if (event_handler == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait until it has stopped.
|
||||
{
|
||||
@@ -101,7 +101,9 @@ void EventHandler::Stop() {
|
||||
|
||||
|
||||
EventHandlerImplementation* EventHandler::delegate() {
|
||||
if (event_handler == NULL) return NULL;
|
||||
if (event_handler == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return &event_handler->delegate_;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ class TimeoutQueue {
|
||||
private:
|
||||
Timeout* next_timeout_;
|
||||
Timeout* timeouts_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TimeoutQueue);
|
||||
};
|
||||
|
||||
|
||||
@@ -221,6 +223,8 @@ class CircularLinkedList {
|
||||
};
|
||||
|
||||
Entry* head_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CircularLinkedList);
|
||||
};
|
||||
|
||||
|
||||
@@ -268,6 +272,9 @@ class DescriptorInfoBase {
|
||||
|
||||
protected:
|
||||
intptr_t fd_;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoBase);
|
||||
};
|
||||
|
||||
|
||||
@@ -281,7 +288,7 @@ class DescriptorInfoSingleMixin : public DI {
|
||||
static const int kTokenCount = 16;
|
||||
|
||||
public:
|
||||
explicit DescriptorInfoSingleMixin(intptr_t fd, bool disable_tokens)
|
||||
DescriptorInfoSingleMixin(intptr_t fd, bool disable_tokens)
|
||||
: DI(fd), port_(0), tokens_(kTokenCount), mask_(0),
|
||||
disable_tokens_(disable_tokens) {}
|
||||
|
||||
@@ -356,6 +363,8 @@ class DescriptorInfoSingleMixin : public DI {
|
||||
int tokens_;
|
||||
intptr_t mask_;
|
||||
bool disable_tokens_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoSingleMixin);
|
||||
};
|
||||
|
||||
|
||||
@@ -400,7 +409,7 @@ class DescriptorInfoMultipleMixin : public DI {
|
||||
};
|
||||
|
||||
public:
|
||||
explicit DescriptorInfoMultipleMixin(intptr_t fd, bool disable_tokens)
|
||||
DescriptorInfoMultipleMixin(intptr_t fd, bool disable_tokens)
|
||||
: DI(fd), tokens_map_(&SamePortValue, kTokenCount),
|
||||
disable_tokens_(disable_tokens) {}
|
||||
|
||||
@@ -541,7 +550,7 @@ class DescriptorInfoMultipleMixin : public DI {
|
||||
pentry->token_count--;
|
||||
}
|
||||
|
||||
if (was_ready && pentry->token_count <= 0) {
|
||||
if (was_ready && (pentry->token_count <= 0)) {
|
||||
active_readers_.Remove(pentry);
|
||||
}
|
||||
}
|
||||
@@ -586,8 +595,9 @@ class DescriptorInfoMultipleMixin : public DI {
|
||||
HashMap tokens_map_;
|
||||
|
||||
bool disable_tokens_;
|
||||
};
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultipleMixin);
|
||||
};
|
||||
|
||||
} // namespace bin
|
||||
} // namespace dart
|
||||
@@ -610,6 +620,7 @@ namespace bin {
|
||||
|
||||
class EventHandler {
|
||||
public:
|
||||
EventHandler() {}
|
||||
void SendData(intptr_t id, Dart_Port dart_port, int64_t data) {
|
||||
delegate_.SendData(id, dart_port, data);
|
||||
}
|
||||
@@ -635,6 +646,8 @@ class EventHandler {
|
||||
private:
|
||||
friend class EventHandlerImplementation;
|
||||
EventHandlerImplementation delegate_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(EventHandler);
|
||||
};
|
||||
|
||||
} // namespace bin
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
#include "bin/eventhandler_android.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <pthread.h> // NOLINT
|
||||
#include <stdio.h> // NOLINT
|
||||
#include <string.h> // NOLINT
|
||||
#include <sys/epoll.h> // NOLINT
|
||||
#include <sys/stat.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/fdutils.h"
|
||||
@@ -27,17 +27,14 @@
|
||||
#include "platform/hashmap.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
|
||||
// Android doesn't define EPOLLRDHUP.
|
||||
#if !defined(EPOLLRDHUP)
|
||||
#define EPOLLRDHUP 0x2000
|
||||
#endif // !defined(EPOLLRDHUP)
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
intptr_t DescriptorInfo::GetPollEvents() {
|
||||
// Do not ask for EPOLLERR and EPOLLHUP explicitly as they are
|
||||
// triggered anyway.
|
||||
@@ -129,11 +126,11 @@ EventHandlerImplementation::~EventHandlerImplementation() {
|
||||
void EventHandlerImplementation::UpdateEpollInstance(intptr_t old_mask,
|
||||
DescriptorInfo *di) {
|
||||
intptr_t new_mask = di->Mask();
|
||||
if (old_mask != 0 && new_mask == 0) {
|
||||
if ((old_mask != 0) && (new_mask == 0)) {
|
||||
RemoveFromEpollInstance(epoll_fd_, di);
|
||||
} else if (old_mask == 0 && new_mask != 0) {
|
||||
} else if ((old_mask == 0) && (new_mask != 0)) {
|
||||
AddToEpollInstance(epoll_fd_, di);
|
||||
} else if (old_mask != 0 && new_mask != 0 && old_mask != new_mask) {
|
||||
} else if ((old_mask != 0) && (new_mask != 0) && (old_mask != new_mask)) {
|
||||
ASSERT(!di->IsListeningSocket());
|
||||
RemoveFromEpollInstance(epoll_fd_, di);
|
||||
AddToEpollInstance(epoll_fd_, di);
|
||||
@@ -264,15 +261,28 @@ void EventHandlerImplementation::HandleInterruptFd() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_POLL
|
||||
static void PrintEventMask(intptr_t fd, intptr_t events) {
|
||||
Log::Print("%d ", fd);
|
||||
if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN ");
|
||||
if ((events & EPOLLPRI) != 0) Log::Print("EPOLLPRI ");
|
||||
if ((events & EPOLLOUT) != 0) Log::Print("EPOLLOUT ");
|
||||
if ((events & EPOLLERR) != 0) Log::Print("EPOLLERR ");
|
||||
if ((events & EPOLLHUP) != 0) Log::Print("EPOLLHUP ");
|
||||
if ((events & EPOLLRDHUP) != 0) Log::Print("EPOLLRDHUP ");
|
||||
if ((events & EPOLLIN) != 0) {
|
||||
Log::Print("EPOLLIN ");
|
||||
}
|
||||
if ((events & EPOLLPRI) != 0) {
|
||||
Log::Print("EPOLLPRI ");
|
||||
}
|
||||
if ((events & EPOLLOUT) != 0) {
|
||||
Log::Print("EPOLLOUT ");
|
||||
}
|
||||
if ((events & EPOLLERR) != 0) {
|
||||
Log::Print("EPOLLERR ");
|
||||
}
|
||||
if ((events & EPOLLHUP) != 0) {
|
||||
Log::Print("EPOLLHUP ");
|
||||
}
|
||||
if ((events & EPOLLRDHUP) != 0) {
|
||||
Log::Print("EPOLLRDHUP ");
|
||||
}
|
||||
int all_events = EPOLLIN | EPOLLPRI | EPOLLOUT |
|
||||
EPOLLERR | EPOLLHUP | EPOLLRDHUP;
|
||||
if ((events & ~all_events) != 0) {
|
||||
@@ -284,19 +294,26 @@ static void PrintEventMask(intptr_t fd, intptr_t events) {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
intptr_t EventHandlerImplementation::GetPollEvents(intptr_t events,
|
||||
DescriptorInfo* di) {
|
||||
#ifdef DEBUG_POLL
|
||||
PrintEventMask(di->fd(), events);
|
||||
#endif
|
||||
if (events & EPOLLERR) {
|
||||
if ((events & EPOLLERR) != 0) {
|
||||
// Return error only if EPOLLIN is present.
|
||||
return (events & EPOLLIN) ? (1 << kErrorEvent) : 0;
|
||||
return ((events & EPOLLIN) != 0) ? (1 << kErrorEvent) : 0;
|
||||
}
|
||||
intptr_t event_mask = 0;
|
||||
if (events & EPOLLIN) event_mask |= (1 << kInEvent);
|
||||
if (events & EPOLLOUT) event_mask |= (1 << kOutEvent);
|
||||
if (events & (EPOLLHUP | EPOLLRDHUP)) event_mask |= (1 << kCloseEvent);
|
||||
if ((events & EPOLLIN) != 0) {
|
||||
event_mask |= (1 << kInEvent);
|
||||
}
|
||||
if ((events & EPOLLOUT) != 0) {
|
||||
event_mask |= (1 << kOutEvent);
|
||||
}
|
||||
if ((events & (EPOLLHUP | EPOLLRDHUP)) != 0) {
|
||||
event_mask |= (1 << kCloseEvent);
|
||||
}
|
||||
return event_mask;
|
||||
}
|
||||
|
||||
@@ -360,8 +377,10 @@ void EventHandlerImplementation::Poll(uword args) {
|
||||
|
||||
while (!handler_impl->shutdown_) {
|
||||
int64_t millis = handler_impl->GetTimeout();
|
||||
ASSERT(millis == kInfinityTimeout || millis >= 0);
|
||||
if (millis > kMaxInt32) millis = kMaxInt32;
|
||||
ASSERT((millis == kInfinityTimeout) || (millis >= 0));
|
||||
if (millis > kMaxInt32) {
|
||||
millis = kMaxInt32;
|
||||
}
|
||||
intptr_t result = TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(
|
||||
epoll_wait(handler_impl->epoll_fd_, events, kMaxEvents, millis));
|
||||
ASSERT(EAGAIN == EWOULDBLOCK);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "platform/hashmap.h"
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -34,6 +33,9 @@ class DescriptorInfo : public DescriptorInfoBase {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd_));
|
||||
fd_ = -1;
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfo);
|
||||
};
|
||||
|
||||
|
||||
@@ -43,6 +45,9 @@ class DescriptorInfoSingle
|
||||
explicit DescriptorInfoSingle(intptr_t fd)
|
||||
: DescriptorInfoSingleMixin(fd, false) {}
|
||||
virtual ~DescriptorInfoSingle() {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoSingle);
|
||||
};
|
||||
|
||||
|
||||
@@ -52,6 +57,9 @@ class DescriptorInfoMultiple
|
||||
explicit DescriptorInfoMultiple(intptr_t fd)
|
||||
: DescriptorInfoMultipleMixin(fd, false) {}
|
||||
virtual ~DescriptorInfoMultiple() {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple);
|
||||
};
|
||||
|
||||
|
||||
@@ -86,6 +94,8 @@ class EventHandlerImplementation {
|
||||
bool shutdown_;
|
||||
int interrupt_fds_[2];
|
||||
int epoll_fd_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation);
|
||||
};
|
||||
|
||||
} // namespace bin
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "bin/eventhandler_linux.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <pthread.h> // NOLINT
|
||||
#include <stdio.h> // NOLINT
|
||||
#include <string.h> // NOLINT
|
||||
@@ -16,7 +17,6 @@
|
||||
#include <sys/stat.h> // NOLINT
|
||||
#include <sys/timerfd.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/fdutils.h"
|
||||
@@ -26,11 +26,9 @@
|
||||
#include "bin/thread.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
intptr_t DescriptorInfo::GetPollEvents() {
|
||||
// Do not ask for EPOLLERR and EPOLLHUP explicitly as they are
|
||||
// triggered anyway.
|
||||
@@ -138,11 +136,11 @@ EventHandlerImplementation::~EventHandlerImplementation() {
|
||||
void EventHandlerImplementation::UpdateEpollInstance(intptr_t old_mask,
|
||||
DescriptorInfo *di) {
|
||||
intptr_t new_mask = di->Mask();
|
||||
if (old_mask != 0 && new_mask == 0) {
|
||||
if ((old_mask != 0) && (new_mask == 0)) {
|
||||
RemoveFromEpollInstance(epoll_fd_, di);
|
||||
} else if (old_mask == 0 && new_mask != 0) {
|
||||
} else if ((old_mask == 0) && (new_mask != 0)) {
|
||||
AddToEpollInstance(epoll_fd_, di);
|
||||
} else if (old_mask != 0 && new_mask != 0 && old_mask != new_mask) {
|
||||
} else if ((old_mask != 0) && (new_mask != 0) && (old_mask != new_mask)) {
|
||||
ASSERT(!di->IsListeningSocket());
|
||||
RemoveFromEpollInstance(epoll_fd_, di);
|
||||
AddToEpollInstance(epoll_fd_, di);
|
||||
@@ -156,8 +154,7 @@ DescriptorInfo* EventHandlerImplementation::GetDescriptorInfo(
|
||||
HashMap::Entry* entry = socket_map_.Lookup(
|
||||
GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd), true);
|
||||
ASSERT(entry != NULL);
|
||||
DescriptorInfo* di =
|
||||
reinterpret_cast<DescriptorInfo*>(entry->value);
|
||||
DescriptorInfo* di = reinterpret_cast<DescriptorInfo*>(entry->value);
|
||||
if (di == NULL) {
|
||||
// If there is no data in the hash map for this file descriptor a
|
||||
// new DescriptorInfo for the file descriptor is inserted.
|
||||
@@ -282,15 +279,28 @@ void EventHandlerImplementation::HandleInterruptFd() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_POLL
|
||||
static void PrintEventMask(intptr_t fd, intptr_t events) {
|
||||
Log::Print("%d ", fd);
|
||||
if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN ");
|
||||
if ((events & EPOLLPRI) != 0) Log::Print("EPOLLPRI ");
|
||||
if ((events & EPOLLOUT) != 0) Log::Print("EPOLLOUT ");
|
||||
if ((events & EPOLLERR) != 0) Log::Print("EPOLLERR ");
|
||||
if ((events & EPOLLHUP) != 0) Log::Print("EPOLLHUP ");
|
||||
if ((events & EPOLLRDHUP) != 0) Log::Print("EPOLLRDHUP ");
|
||||
if ((events & EPOLLIN) != 0) {
|
||||
Log::Print("EPOLLIN ");
|
||||
}
|
||||
if ((events & EPOLLPRI) != 0) {
|
||||
Log::Print("EPOLLPRI ");
|
||||
}
|
||||
if ((events & EPOLLOUT) != 0) {
|
||||
Log::Print("EPOLLOUT ");
|
||||
}
|
||||
if ((events & EPOLLERR) != 0) {
|
||||
Log::Print("EPOLLERR ");
|
||||
}
|
||||
if ((events & EPOLLHUP) != 0) {
|
||||
Log::Print("EPOLLHUP ");
|
||||
}
|
||||
if ((events & EPOLLRDHUP) != 0) {
|
||||
Log::Print("EPOLLRDHUP ");
|
||||
}
|
||||
int all_events = EPOLLIN | EPOLLPRI | EPOLLOUT |
|
||||
EPOLLERR | EPOLLHUP | EPOLLRDHUP;
|
||||
if ((events & ~all_events) != 0) {
|
||||
@@ -302,19 +312,26 @@ static void PrintEventMask(intptr_t fd, intptr_t events) {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
intptr_t EventHandlerImplementation::GetPollEvents(intptr_t events,
|
||||
DescriptorInfo* di) {
|
||||
#ifdef DEBUG_POLL
|
||||
PrintEventMask(di->fd(), events);
|
||||
#endif
|
||||
if (events & EPOLLERR) {
|
||||
if ((events & EPOLLERR) != 0) {
|
||||
// Return error only if EPOLLIN is present.
|
||||
return (events & EPOLLIN) ? (1 << kErrorEvent) : 0;
|
||||
return ((events & EPOLLIN) != 0) ? (1 << kErrorEvent) : 0;
|
||||
}
|
||||
intptr_t event_mask = 0;
|
||||
if (events & EPOLLIN) event_mask |= (1 << kInEvent);
|
||||
if (events & EPOLLOUT) event_mask |= (1 << kOutEvent);
|
||||
if (events & (EPOLLHUP | EPOLLRDHUP)) event_mask |= (1 << kCloseEvent);
|
||||
if ((events & EPOLLIN) != 0) {
|
||||
event_mask |= (1 << kInEvent);
|
||||
}
|
||||
if ((events & EPOLLOUT) != 0) {
|
||||
event_mask |= (1 << kOutEvent);
|
||||
}
|
||||
if ((events & (EPOLLHUP | EPOLLRDHUP)) != 0) {
|
||||
event_mask |= (1 << kCloseEvent);
|
||||
}
|
||||
return event_mask;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ class DescriptorInfo : public DescriptorInfoBase {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd_));
|
||||
fd_ = -1;
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfo);
|
||||
};
|
||||
|
||||
|
||||
@@ -42,6 +45,9 @@ class DescriptorInfoSingle
|
||||
explicit DescriptorInfoSingle(intptr_t fd)
|
||||
: DescriptorInfoSingleMixin(fd, false) {}
|
||||
virtual ~DescriptorInfoSingle() {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoSingle);
|
||||
};
|
||||
|
||||
|
||||
@@ -51,6 +57,9 @@ class DescriptorInfoMultiple
|
||||
explicit DescriptorInfoMultiple(intptr_t fd)
|
||||
: DescriptorInfoMultipleMixin(fd, false) {}
|
||||
virtual ~DescriptorInfoMultiple() {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple);
|
||||
};
|
||||
|
||||
|
||||
@@ -84,6 +93,8 @@ class EventHandlerImplementation {
|
||||
int interrupt_fds_[2];
|
||||
int epoll_fd_;
|
||||
int timer_fd_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation);
|
||||
};
|
||||
|
||||
} // namespace bin
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
#include "bin/eventhandler_macos.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <pthread.h> // NOLINT
|
||||
#include <stdio.h> // NOLINT
|
||||
#include <string.h> // NOLINT
|
||||
#include <sys/event.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/fdutils.h"
|
||||
@@ -26,11 +26,9 @@
|
||||
#include "platform/hashmap.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
bool DescriptorInfo::HasReadEvent() {
|
||||
return (Mask() & (1 << kInEvent)) != 0;
|
||||
}
|
||||
@@ -43,7 +41,9 @@ bool DescriptorInfo::HasWriteEvent() {
|
||||
|
||||
// Unregister the file descriptor for a SocketData structure with kqueue.
|
||||
static void RemoveFromKqueue(intptr_t kqueue_fd_, DescriptorInfo* di) {
|
||||
if (!di->tracked_by_kqueue()) return;
|
||||
if (!di->tracked_by_kqueue()) {
|
||||
return;
|
||||
}
|
||||
static const intptr_t kMaxChanges = 2;
|
||||
struct kevent events[kMaxChanges];
|
||||
EV_SET(events, di->fd(), EVFILT_READ, EV_DELETE, 0, 0, NULL);
|
||||
@@ -150,9 +150,9 @@ void EventHandlerImplementation::UpdateKQueueInstance(intptr_t old_mask,
|
||||
intptr_t new_mask = di->Mask();
|
||||
if (old_mask != 0 && new_mask == 0) {
|
||||
RemoveFromKqueue(kqueue_fd_, di);
|
||||
} else if (old_mask == 0 && new_mask != 0) {
|
||||
} else if ((old_mask == 0) && (new_mask != 0)) {
|
||||
AddToKqueue(kqueue_fd_, di);
|
||||
} else if (old_mask != 0 && new_mask != 0 && old_mask != new_mask) {
|
||||
} else if ((old_mask != 0) && (new_mask != 0) && (old_mask != new_mask)) {
|
||||
ASSERT(!di->IsListeningSocket());
|
||||
RemoveFromKqueue(kqueue_fd_, di);
|
||||
AddToKqueue(kqueue_fd_, di);
|
||||
@@ -281,22 +281,39 @@ void EventHandlerImplementation::HandleInterruptFd() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_KQUEUE
|
||||
static void PrintEventMask(intptr_t fd, struct kevent* event) {
|
||||
Log::Print("%d ", static_cast<int>(fd));
|
||||
|
||||
Log::Print("filter=0x%x:", event->filter);
|
||||
if (event->filter == EVFILT_READ) Log::Print("EVFILT_READ ");
|
||||
if (event->filter == EVFILT_WRITE) Log::Print("EVFILT_WRITE ");
|
||||
if (event->filter == EVFILT_READ) {
|
||||
Log::Print("EVFILT_READ ");
|
||||
}
|
||||
if (event->filter == EVFILT_WRITE) {
|
||||
Log::Print("EVFILT_WRITE ");
|
||||
}
|
||||
|
||||
Log::Print("flags: %x: ", event->flags);
|
||||
if ((event->flags & EV_EOF) != 0) Log::Print("EV_EOF ");
|
||||
if ((event->flags & EV_ERROR) != 0) Log::Print("EV_ERROR ");
|
||||
if ((event->flags & EV_CLEAR) != 0) Log::Print("EV_CLEAR ");
|
||||
if ((event->flags & EV_ADD) != 0) Log::Print("EV_ADD ");
|
||||
if ((event->flags & EV_DELETE) != 0) Log::Print("EV_DELETE ");
|
||||
if ((event->flags & EV_EOF) != 0) {
|
||||
Log::Print("EV_EOF ");
|
||||
}
|
||||
if ((event->flags & EV_ERROR) != 0) {
|
||||
Log::Print("EV_ERROR ");
|
||||
}
|
||||
if ((event->flags & EV_CLEAR) != 0) {
|
||||
Log::Print("EV_CLEAR ");
|
||||
}
|
||||
if ((event->flags & EV_ADD) != 0) {
|
||||
Log::Print("EV_ADD ");
|
||||
}
|
||||
if ((event->flags & EV_DELETE) != 0) {
|
||||
Log::Print("EV_DELETE ");
|
||||
}
|
||||
|
||||
Log::Print("- fflags: %d ", event->fflags);
|
||||
Log::Print("- data: %ld ", event->data);
|
||||
Log::Print("(available %d) ",
|
||||
static_cast<int>(FDUtils::AvailableBytes(fd)));
|
||||
Log::Print("(available %d) ", static_cast<int>(FDUtils::AvailableBytes(fd)));
|
||||
Log::Print("\n");
|
||||
}
|
||||
#endif
|
||||
@@ -319,7 +336,9 @@ intptr_t EventHandlerImplementation::GetEvents(struct kevent* event,
|
||||
event_mask |= (1 << kCloseEvent);
|
||||
}
|
||||
}
|
||||
if (event_mask == 0) event_mask |= (1 << kInEvent);
|
||||
if (event_mask == 0) {
|
||||
event_mask |= (1 << kInEvent);
|
||||
}
|
||||
} else {
|
||||
UNREACHABLE();
|
||||
}
|
||||
@@ -421,7 +440,9 @@ void EventHandlerImplementation::EventHandlerEntry(uword args) {
|
||||
while (!handler_impl->shutdown_) {
|
||||
int64_t millis = handler_impl->GetTimeout();
|
||||
ASSERT(millis == kInfinityTimeout || millis >= 0);
|
||||
if (millis > kMaxInt32) millis = kMaxInt32;
|
||||
if (millis > kMaxInt32) {
|
||||
millis = kMaxInt32;
|
||||
}
|
||||
// NULL pointer timespec for infinite timeout.
|
||||
ASSERT(kInfinityTimeout < 0);
|
||||
struct timespec* timeout = NULL;
|
||||
|
||||
@@ -47,6 +47,9 @@ class DescriptorInfo : public DescriptorInfoBase {
|
||||
|
||||
protected:
|
||||
bool tracked_by_kqueue_;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfo);
|
||||
};
|
||||
|
||||
|
||||
@@ -56,6 +59,9 @@ class DescriptorInfoSingle
|
||||
explicit DescriptorInfoSingle(intptr_t fd)
|
||||
: DescriptorInfoSingleMixin(fd, false) {}
|
||||
virtual ~DescriptorInfoSingle() {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoSingle);
|
||||
};
|
||||
|
||||
|
||||
@@ -65,6 +71,9 @@ class DescriptorInfoMultiple
|
||||
explicit DescriptorInfoMultiple(intptr_t fd)
|
||||
: DescriptorInfoMultipleMixin(fd, false) {}
|
||||
virtual ~DescriptorInfoMultiple() {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple);
|
||||
};
|
||||
|
||||
|
||||
@@ -99,6 +108,8 @@ class EventHandlerImplementation {
|
||||
bool shutdown_;
|
||||
int interrupt_fds_[2];
|
||||
int kqueue_fd_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation);
|
||||
};
|
||||
|
||||
} // namespace bin
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#include "bin/eventhandler.h"
|
||||
#include "bin/eventhandler_win.h"
|
||||
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <io.h> // NOLINT
|
||||
#include <mswsock.h> // NOLINT
|
||||
#include <winsock2.h> // NOLINT
|
||||
#include <ws2tcpip.h> // NOLINT
|
||||
#include <mswsock.h> // NOLINT
|
||||
#include <io.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/dartutils.h"
|
||||
@@ -140,10 +140,7 @@ bool Handle::CreateCompletionPort(HANDLE completion_port) {
|
||||
completion_port,
|
||||
reinterpret_cast<ULONG_PTR>(this),
|
||||
0);
|
||||
if (completion_port_ == NULL) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return (completion_port_ != NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -307,7 +304,7 @@ bool Handle::IssueRead() {
|
||||
buffer->GetBufferSize(),
|
||||
NULL,
|
||||
buffer->GetCleanOverlapped());
|
||||
if (ok || GetLastError() == ERROR_IO_PENDING) {
|
||||
if (ok || (GetLastError() == ERROR_IO_PENDING)) {
|
||||
// Completing asynchronously.
|
||||
pending_read_ = buffer;
|
||||
return true;
|
||||
@@ -347,7 +344,7 @@ bool Handle::IssueWrite() {
|
||||
buffer->GetBufferSize(),
|
||||
NULL,
|
||||
buffer->GetCleanOverlapped());
|
||||
if (ok || GetLastError() == ERROR_IO_PENDING) {
|
||||
if (ok || (GetLastError() == ERROR_IO_PENDING)) {
|
||||
// Completing asynchronously.
|
||||
pending_write_ = buffer;
|
||||
return true;
|
||||
@@ -394,7 +391,7 @@ void Handle::HandleIssueError() {
|
||||
void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) {
|
||||
MonitorLocker ml(monitor_);
|
||||
event_handler_ = event_handler;
|
||||
if (SupportsOverlappedIO() && completion_port_ == INVALID_HANDLE_VALUE) {
|
||||
if (SupportsOverlappedIO() && (completion_port_ == INVALID_HANDLE_VALUE)) {
|
||||
CreateCompletionPort(event_handler_->completion_port());
|
||||
}
|
||||
}
|
||||
@@ -416,14 +413,16 @@ void DirectoryWatchHandle::EnsureInitialized(
|
||||
|
||||
|
||||
bool DirectoryWatchHandle::IsClosed() {
|
||||
return IsClosing() && pending_read_ == NULL;
|
||||
return IsClosing() && (pending_read_ == NULL);
|
||||
}
|
||||
|
||||
|
||||
bool DirectoryWatchHandle::IssueRead() {
|
||||
// It may have been started before, as we start the directory-handler when
|
||||
// we create it.
|
||||
if (pending_read_ != NULL || data_ready_ != NULL) return true;
|
||||
if ((pending_read_ != NULL) || (data_ready_ != NULL)) {
|
||||
return true;
|
||||
}
|
||||
OverlappedBuffer* buffer = OverlappedBuffer::AllocateReadBuffer(kBufferSize);
|
||||
ASSERT(completion_port_ != INVALID_HANDLE_VALUE);
|
||||
BOOL ok = ReadDirectoryChangesW(handle_,
|
||||
@@ -434,7 +433,7 @@ bool DirectoryWatchHandle::IssueRead() {
|
||||
NULL,
|
||||
buffer->GetCleanOverlapped(),
|
||||
NULL);
|
||||
if (ok || GetLastError() == ERROR_IO_PENDING) {
|
||||
if (ok || (GetLastError() == ERROR_IO_PENDING)) {
|
||||
// Completing asynchronously.
|
||||
pending_read_ = buffer;
|
||||
return true;
|
||||
@@ -481,10 +480,7 @@ bool ListenSocket::LoadAcceptEx() {
|
||||
&bytes,
|
||||
NULL,
|
||||
NULL);
|
||||
if (status == SOCKET_ERROR) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return (status != SOCKET_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -603,7 +599,9 @@ ClientSocket* ListenSocket::Accept() {
|
||||
if (accepted_head_ != NULL) {
|
||||
result = accepted_head_;
|
||||
accepted_head_ = accepted_head_->next();
|
||||
if (accepted_head_ == NULL) accepted_tail_ = NULL;
|
||||
if (accepted_head_ == NULL) {
|
||||
accepted_tail_ = NULL;
|
||||
}
|
||||
result->set_next(NULL);
|
||||
accepted_count_--;
|
||||
}
|
||||
@@ -641,7 +639,9 @@ bool ListenSocket::IsClosed() {
|
||||
|
||||
intptr_t Handle::Available() {
|
||||
MonitorLocker ml(monitor_);
|
||||
if (data_ready_ == NULL) return 0;
|
||||
if (data_ready_ == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ASSERT(!data_ready_->IsEmpty());
|
||||
return data_ready_->GetRemainingLength();
|
||||
}
|
||||
@@ -649,13 +649,17 @@ intptr_t Handle::Available() {
|
||||
|
||||
intptr_t Handle::Read(void* buffer, intptr_t num_bytes) {
|
||||
MonitorLocker ml(monitor_);
|
||||
if (data_ready_ == NULL) return 0;
|
||||
if (data_ready_ == NULL) {
|
||||
return 0;
|
||||
}
|
||||
num_bytes = data_ready_->Read(
|
||||
buffer, Utils::Minimum<intptr_t>(num_bytes, INT_MAX));
|
||||
if (data_ready_->IsEmpty()) {
|
||||
OverlappedBuffer::DisposeBuffer(data_ready_);
|
||||
data_ready_ = NULL;
|
||||
if (!IsClosing() && !IsClosedRead()) IssueRead();
|
||||
if (!IsClosing() && !IsClosedRead()) {
|
||||
IssueRead();
|
||||
}
|
||||
}
|
||||
return num_bytes;
|
||||
}
|
||||
@@ -664,7 +668,9 @@ intptr_t Handle::Read(void* buffer, intptr_t num_bytes) {
|
||||
intptr_t Handle::RecvFrom(
|
||||
void* buffer, intptr_t num_bytes, struct sockaddr* sa, socklen_t sa_len) {
|
||||
MonitorLocker ml(monitor_);
|
||||
if (data_ready_ == NULL) return 0;
|
||||
if (data_ready_ == NULL) {
|
||||
return 0;
|
||||
}
|
||||
num_bytes = data_ready_->Read(
|
||||
buffer, Utils::Minimum<intptr_t>(num_bytes, INT_MAX));
|
||||
if (data_ready_->from()->sa_family == AF_INET) {
|
||||
@@ -679,21 +685,31 @@ intptr_t Handle::RecvFrom(
|
||||
// entirety to match how recvfrom works in a socket.
|
||||
OverlappedBuffer::DisposeBuffer(data_ready_);
|
||||
data_ready_ = NULL;
|
||||
if (!IsClosing() && !IsClosedRead()) IssueRecvFrom();
|
||||
if (!IsClosing() && !IsClosedRead()) {
|
||||
IssueRecvFrom();
|
||||
}
|
||||
return num_bytes;
|
||||
}
|
||||
|
||||
|
||||
intptr_t Handle::Write(const void* buffer, intptr_t num_bytes) {
|
||||
MonitorLocker ml(monitor_);
|
||||
if (pending_write_ != NULL) return 0;
|
||||
if (num_bytes > kBufferSize) num_bytes = kBufferSize;
|
||||
if (pending_write_ != NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (num_bytes > kBufferSize) {
|
||||
num_bytes = kBufferSize;
|
||||
}
|
||||
ASSERT(SupportsOverlappedIO());
|
||||
if (completion_port_ == INVALID_HANDLE_VALUE) return 0;
|
||||
if (completion_port_ == INVALID_HANDLE_VALUE) {
|
||||
return 0;
|
||||
}
|
||||
int truncated_bytes = Utils::Minimum<intptr_t>(num_bytes, INT_MAX);
|
||||
pending_write_ = OverlappedBuffer::AllocateWriteBuffer(truncated_bytes);
|
||||
pending_write_->Write(buffer, truncated_bytes);
|
||||
if (!IssueWrite()) return -1;
|
||||
if (!IssueWrite()) {
|
||||
return -1;
|
||||
}
|
||||
return truncated_bytes;
|
||||
}
|
||||
|
||||
@@ -703,13 +719,21 @@ intptr_t Handle::SendTo(const void* buffer,
|
||||
struct sockaddr* sa,
|
||||
socklen_t sa_len) {
|
||||
MonitorLocker ml(monitor_);
|
||||
if (pending_write_ != NULL) return 0;
|
||||
if (num_bytes > kBufferSize) num_bytes = kBufferSize;
|
||||
if (pending_write_ != NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (num_bytes > kBufferSize) {
|
||||
num_bytes = kBufferSize;
|
||||
}
|
||||
ASSERT(SupportsOverlappedIO());
|
||||
if (completion_port_ == INVALID_HANDLE_VALUE) return 0;
|
||||
if (completion_port_ == INVALID_HANDLE_VALUE) {
|
||||
return 0;
|
||||
}
|
||||
pending_write_ = OverlappedBuffer::AllocateSendToBuffer(num_bytes);
|
||||
pending_write_->Write(buffer, num_bytes);
|
||||
if (!IssueSendTo(sa, sa_len)) return -1;
|
||||
if (!IssueSendTo(sa, sa_len)) {
|
||||
return -1;
|
||||
}
|
||||
return num_bytes;
|
||||
}
|
||||
|
||||
@@ -765,15 +789,21 @@ void StdHandle::WriteSyncCompleteAsync() {
|
||||
|
||||
intptr_t StdHandle::Write(const void* buffer, intptr_t num_bytes) {
|
||||
MonitorLocker ml(monitor_);
|
||||
if (pending_write_ != NULL) return 0;
|
||||
if (num_bytes > kBufferSize) num_bytes = kBufferSize;
|
||||
if (pending_write_ != NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (num_bytes > kBufferSize) {
|
||||
num_bytes = kBufferSize;
|
||||
}
|
||||
// In the case of stdout and stderr, OverlappedIO is not supported.
|
||||
// Here we'll instead use a thread, to make it async.
|
||||
// This code is actually never exposed to the user, as stdout and stderr is
|
||||
// not available as a RawSocket, but only wrapped in a Socket.
|
||||
// Note that we return '0', unless a thread have already completed a write.
|
||||
if (thread_wrote_ > 0) {
|
||||
if (num_bytes > thread_wrote_) num_bytes = thread_wrote_;
|
||||
if (num_bytes > thread_wrote_) {
|
||||
num_bytes = thread_wrote_;
|
||||
}
|
||||
thread_wrote_ -= num_bytes;
|
||||
return num_bytes;
|
||||
}
|
||||
@@ -826,17 +856,18 @@ bool ClientSocket::LoadDisconnectEx() {
|
||||
&bytes,
|
||||
NULL,
|
||||
NULL);
|
||||
if (status == SOCKET_ERROR) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return (status != SOCKET_ERROR);
|
||||
}
|
||||
|
||||
|
||||
void ClientSocket::Shutdown(int how) {
|
||||
int rc = shutdown(socket(), how);
|
||||
if (how == SD_RECEIVE) MarkClosedRead();
|
||||
if (how == SD_SEND) MarkClosedWrite();
|
||||
if (how == SD_RECEIVE) {
|
||||
MarkClosedRead();
|
||||
}
|
||||
if (how == SD_SEND) {
|
||||
MarkClosedWrite();
|
||||
}
|
||||
if (how == SD_BOTH) {
|
||||
MarkClosedRead();
|
||||
MarkClosedWrite();
|
||||
@@ -870,7 +901,7 @@ bool ClientSocket::IssueRead() {
|
||||
&flags,
|
||||
buffer->GetCleanOverlapped(),
|
||||
NULL);
|
||||
if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) {
|
||||
if ((rc == NO_ERROR) || (WSAGetLastError() == WSA_IO_PENDING)) {
|
||||
pending_read_ = buffer;
|
||||
return true;
|
||||
}
|
||||
@@ -894,7 +925,7 @@ bool ClientSocket::IssueWrite() {
|
||||
0,
|
||||
pending_write_->GetCleanOverlapped(),
|
||||
NULL);
|
||||
if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) {
|
||||
if ((rc == NO_ERROR) || (WSAGetLastError() == WSA_IO_PENDING)) {
|
||||
return true;
|
||||
}
|
||||
OverlappedBuffer::DisposeBuffer(pending_write_);
|
||||
@@ -910,7 +941,7 @@ void ClientSocket::IssueDisconnect() {
|
||||
socket(), buffer->GetCleanOverlapped(), TF_REUSE_SOCKET, 0);
|
||||
// DisconnectEx works like other OverlappedIO APIs, where we can get either an
|
||||
// immediate success or delayed operation by WSA_IO_PENDING being set.
|
||||
if (ok || WSAGetLastError() != WSA_IO_PENDING) {
|
||||
if (ok || (WSAGetLastError() != WSA_IO_PENDING)) {
|
||||
DisconnectComplete(buffer);
|
||||
}
|
||||
NotifyAllDartPorts(1 << kDestroyedEvent);
|
||||
@@ -975,7 +1006,7 @@ bool DatagramSocket::IssueSendTo(struct sockaddr* sa, socklen_t sa_len) {
|
||||
sa_len,
|
||||
pending_write_->GetCleanOverlapped(),
|
||||
NULL);
|
||||
if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) {
|
||||
if ((rc == NO_ERROR) || (WSAGetLastError() == WSA_IO_PENDING)) {
|
||||
return true;
|
||||
}
|
||||
OverlappedBuffer::DisposeBuffer(pending_write_);
|
||||
@@ -1004,7 +1035,7 @@ bool DatagramSocket::IssueRecvFrom() {
|
||||
buffer->from_len_addr(),
|
||||
buffer->GetCleanOverlapped(),
|
||||
NULL);
|
||||
if (rc == NO_ERROR || WSAGetLastError() == WSA_IO_PENDING) {
|
||||
if ((rc == NO_ERROR) || (WSAGetLastError() == WSA_IO_PENDING)) {
|
||||
pending_read_ = buffer;
|
||||
return true;
|
||||
}
|
||||
@@ -1174,8 +1205,8 @@ void EventHandlerImplementation::TryDispatchingPendingAccepts(
|
||||
if (!listen_socket->IsClosing() && listen_socket->CanAccept()) {
|
||||
intptr_t event_mask = 1 << kInEvent;
|
||||
for (int i = 0;
|
||||
i < listen_socket->accepted_count() &&
|
||||
listen_socket->Mask() == event_mask;
|
||||
(i < listen_socket->accepted_count()) &&
|
||||
(listen_socket->Mask() == event_mask);
|
||||
i++) {
|
||||
Dart_Port port = listen_socket->NextNotifyDartPort(event_mask);
|
||||
DartUtils::PostInt32(port, event_mask);
|
||||
@@ -1280,7 +1311,9 @@ void EventHandlerImplementation::HandleConnect(
|
||||
|
||||
|
||||
void EventHandlerImplementation::HandleTimeout() {
|
||||
if (!timeout_queue_.HasTimeout()) return;
|
||||
if (!timeout_queue_.HasTimeout()) {
|
||||
return;
|
||||
}
|
||||
DartUtils::PostNull(timeout_queue_.CurrentPort());
|
||||
timeout_queue_.RemoveCurrent();
|
||||
}
|
||||
@@ -1389,7 +1422,9 @@ void EventHandlerImplementation::EventHandlerEntry(uword args) {
|
||||
OVERLAPPED* overlapped;
|
||||
int64_t millis = handler_impl->GetTimeout();
|
||||
ASSERT(millis == kInfinityTimeout || millis >= 0);
|
||||
if (millis > kMaxInt32) millis = kMaxInt32;
|
||||
if (millis > kMaxInt32) {
|
||||
millis = kMaxInt32;
|
||||
}
|
||||
ASSERT(sizeof(int32_t) == sizeof(DWORD));
|
||||
BOOL ok = GetQueuedCompletionStatus(handler_impl->completion_port(),
|
||||
&bytes,
|
||||
@@ -1397,7 +1432,7 @@ void EventHandlerImplementation::EventHandlerEntry(uword args) {
|
||||
&overlapped,
|
||||
static_cast<DWORD>(millis));
|
||||
|
||||
if (!ok && overlapped == NULL) {
|
||||
if (!ok && (overlapped == NULL)) {
|
||||
if (GetLastError() == ERROR_ABANDONED_WAIT_0) {
|
||||
// The completion port should never be closed.
|
||||
Log::Print("Completion port closed\n");
|
||||
@@ -1413,10 +1448,10 @@ void EventHandlerImplementation::EventHandlerEntry(uword args) {
|
||||
// ERROR_NETNAME_DELETED occurs when the client closes
|
||||
// the socket it is reading from.
|
||||
DWORD last_error = GetLastError();
|
||||
if (last_error == ERROR_CONNECTION_ABORTED ||
|
||||
last_error == ERROR_OPERATION_ABORTED ||
|
||||
last_error == ERROR_NETNAME_DELETED ||
|
||||
last_error == ERROR_BROKEN_PIPE) {
|
||||
if ((last_error == ERROR_CONNECTION_ABORTED) ||
|
||||
(last_error == ERROR_OPERATION_ABORTED) ||
|
||||
(last_error == ERROR_NETNAME_DELETED) ||
|
||||
(last_error == ERROR_BROKEN_PIPE)) {
|
||||
ASSERT(bytes == 0);
|
||||
handler_impl->HandleIOCompletion(bytes, key, overlapped);
|
||||
} else if (last_error == ERROR_MORE_DATA) {
|
||||
|
||||
@@ -9,14 +9,13 @@
|
||||
#error Do not include eventhandler_win.h directly; use eventhandler.h instead.
|
||||
#endif
|
||||
|
||||
#include <mswsock.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <mswsock.h>
|
||||
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/thread.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -28,7 +27,6 @@ class SocketHandle;
|
||||
class ClientSocket;
|
||||
class ListenSocket;
|
||||
|
||||
|
||||
// An OverlappedBuffer encapsulates the OVERLAPPED structure and the
|
||||
// associated data buffer. For accept it also contains the pre-created
|
||||
// socket for the client.
|
||||
@@ -149,6 +147,8 @@ class OverlappedBuffer {
|
||||
// object as the object is allocated larger than it's definition
|
||||
// indicate to extend this array.
|
||||
uint8_t buffer_data_[1];
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(OverlappedBuffer);
|
||||
};
|
||||
|
||||
|
||||
@@ -273,6 +273,8 @@ class Handle : public DescriptorInfoBase {
|
||||
void NotifyReadThreadFinished();
|
||||
|
||||
int flags_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Handle);
|
||||
};
|
||||
|
||||
|
||||
@@ -285,6 +287,9 @@ class FileHandle : public DescriptorInfoSingleMixin<Handle> {
|
||||
|
||||
virtual void EnsureInitialized(EventHandlerImplementation* event_handler);
|
||||
virtual bool IsClosed();
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(FileHandle);
|
||||
};
|
||||
|
||||
|
||||
@@ -310,6 +315,8 @@ class StdHandle : public FileHandle {
|
||||
intptr_t thread_wrote_;
|
||||
bool write_thread_exists_;
|
||||
bool write_thread_running_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(StdHandle);
|
||||
};
|
||||
|
||||
|
||||
@@ -332,6 +339,8 @@ class DirectoryWatchHandle : public DescriptorInfoSingleMixin<Handle> {
|
||||
private:
|
||||
int events_;
|
||||
bool recursive_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DirectoryWatchHandle);
|
||||
};
|
||||
|
||||
|
||||
@@ -348,6 +357,8 @@ class SocketHandle : public Handle {
|
||||
|
||||
private:
|
||||
const SOCKET socket_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SocketHandle);
|
||||
};
|
||||
|
||||
|
||||
@@ -403,6 +414,8 @@ class ListenSocket : public DescriptorInfoMultipleMixin<SocketHandle> {
|
||||
// The number of accepted connections which are waiting to be removed from
|
||||
// this queue and processed by dart isolates.
|
||||
int accepted_count_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ListenSocket);
|
||||
};
|
||||
|
||||
|
||||
@@ -460,6 +473,8 @@ class ClientSocket : public DescriptorInfoSingleMixin<SocketHandle> {
|
||||
ClientSocket* next_;
|
||||
bool connected_;
|
||||
bool closed_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ClientSocket);
|
||||
};
|
||||
|
||||
|
||||
@@ -482,8 +497,12 @@ class DatagramSocket : public DescriptorInfoSingleMixin<SocketHandle> {
|
||||
virtual void EnsureInitialized(EventHandlerImplementation* event_handler);
|
||||
virtual void DoClose();
|
||||
virtual bool IsClosed();
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DatagramSocket);
|
||||
};
|
||||
|
||||
|
||||
// Event handler.
|
||||
class EventHandlerImplementation {
|
||||
public:
|
||||
@@ -523,6 +542,8 @@ class EventHandlerImplementation {
|
||||
TimeoutQueue timeout_queue_; // Time for next timeout.
|
||||
bool shutdown_;
|
||||
HANDLE completion_port_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation);
|
||||
};
|
||||
|
||||
} // namespace bin
|
||||
|
||||
@@ -6,12 +6,11 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/file.h"
|
||||
#include "include/dart_api.h"
|
||||
#include "platform/assert.h"
|
||||
#include "platform/globals.h"
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/file.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
@@ -25,17 +24,15 @@ Dart_Handle Extensions::LoadExtension(const char* extension_directory,
|
||||
return Dart_NewApiError("Cannot load native extensions over http:");
|
||||
}
|
||||
const char* library_strings[] = { extension_directory, extension_file, NULL };
|
||||
char* library_file = Concatenate(library_strings);
|
||||
const char* library_file = Concatenate(library_strings);
|
||||
void* library_handle = LoadExtensionLibrary(library_file);
|
||||
free(library_file);
|
||||
if (library_handle == NULL) {
|
||||
return GetError();
|
||||
}
|
||||
|
||||
const char* strings[] = { extension_name, "_Init", NULL };
|
||||
char* init_function_name = Concatenate(strings);
|
||||
const char* init_function_name = Concatenate(strings);
|
||||
void* init_function = ResolveSymbol(library_handle, init_function_name);
|
||||
free(init_function_name);
|
||||
Dart_Handle result = GetError();
|
||||
if (Dart_IsError(result)) {
|
||||
return result;
|
||||
@@ -48,13 +45,13 @@ Dart_Handle Extensions::LoadExtension(const char* extension_directory,
|
||||
|
||||
|
||||
// Concatenates a NULL terminated array of strings.
|
||||
// The returned string must be freed.
|
||||
char* Extensions::Concatenate(const char** strings) {
|
||||
// The returned string is scope allocated.
|
||||
const char* Extensions::Concatenate(const char** strings) {
|
||||
int size = 1; // null termination.
|
||||
for (int i = 0; strings[i] != NULL; i++) {
|
||||
size += strlen(strings[i]);
|
||||
}
|
||||
char* result = reinterpret_cast<char*>(malloc(size));
|
||||
char* result = reinterpret_cast<char*>(Dart_ScopeAllocate(size));
|
||||
int index = 0;
|
||||
for (int i = 0; strings[i] != NULL; i++) {
|
||||
index += snprintf(result + index, size - index, "%s", strings[i]);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "include/dart_api.h"
|
||||
#include "platform/globals.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -28,8 +27,8 @@ class Extensions {
|
||||
private:
|
||||
static Dart_Handle GetError();
|
||||
|
||||
// The returned string must be freed.
|
||||
static char* Concatenate(const char** strings);
|
||||
// The returned string is scope allocated.
|
||||
static const char* Concatenate(const char** strings);
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(Extensions);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "bin/extensions.h"
|
||||
#include <dlfcn.h> // NOLINT
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "bin/extensions.h"
|
||||
#include <dlfcn.h> // NOLINT
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "bin/extensions.h"
|
||||
#include <dlfcn.h> // NOLINT
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "bin/utils.h"
|
||||
#include "bin/utils_win.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "bin/builtin.h"
|
||||
#include "platform/globals.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
#include "platform/globals.h"
|
||||
#if defined(TARGET_OS_ANDROID)
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <sys/ioctl.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -72,9 +72,7 @@ intptr_t FDUtils::AvailableBytes(intptr_t fd) {
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
ASSERT(available >= 0);
|
||||
#endif
|
||||
return static_cast<intptr_t>(available);
|
||||
}
|
||||
|
||||
@@ -98,7 +96,7 @@ ssize_t FDUtils::ReadFromBlocking(int fd, void* buffer, size_t count) {
|
||||
ASSERT(errno != EWOULDBLOCK);
|
||||
return -1;
|
||||
} else {
|
||||
ASSERT((bytes_read > 0));
|
||||
ASSERT(bytes_read > 0);
|
||||
remaining -= bytes_read;
|
||||
buffer_pos += bytes_read;
|
||||
}
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
#include "platform/globals.h"
|
||||
#if defined(TARGET_OS_LINUX)
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <sys/ioctl.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -72,9 +72,7 @@ intptr_t FDUtils::AvailableBytes(intptr_t fd) {
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
ASSERT(available >= 0);
|
||||
#endif
|
||||
return static_cast<intptr_t>(available);
|
||||
}
|
||||
|
||||
@@ -98,7 +96,7 @@ ssize_t FDUtils::ReadFromBlocking(int fd, void* buffer, size_t count) {
|
||||
ASSERT(errno != EWOULDBLOCK);
|
||||
return -1;
|
||||
} else {
|
||||
ASSERT((bytes_read > 0));
|
||||
ASSERT(bytes_read > 0);
|
||||
remaining -= bytes_read;
|
||||
buffer_pos += bytes_read;
|
||||
}
|
||||
|
||||
@@ -5,15 +5,14 @@
|
||||
#include "platform/globals.h"
|
||||
#if defined(TARGET_OS_MACOS)
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <sys/ioctl.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
|
||||
#include "platform/signal_blocker.h"
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <sys/ioctl.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
@@ -73,9 +72,7 @@ intptr_t FDUtils::AvailableBytes(intptr_t fd) {
|
||||
if (result < 0) {
|
||||
return result;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
ASSERT(available >= 0);
|
||||
#endif
|
||||
return static_cast<intptr_t>(available);
|
||||
}
|
||||
|
||||
@@ -99,7 +96,7 @@ ssize_t FDUtils::ReadFromBlocking(int fd, void* buffer, size_t count) {
|
||||
ASSERT(errno != EWOULDBLOCK);
|
||||
return -1;
|
||||
} else {
|
||||
ASSERT((bytes_read > 0));
|
||||
ASSERT(bytes_read > 0);
|
||||
remaining -= bytes_read;
|
||||
buffer_pos += bytes_read;
|
||||
}
|
||||
|
||||
+6
-2
@@ -565,7 +565,9 @@ void FUNCTION_NAME(File_ResolveSymbolicLinks)(Dart_NativeArguments args) {
|
||||
|
||||
void FUNCTION_NAME(File_OpenStdio)(Dart_NativeArguments args) {
|
||||
int64_t fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
|
||||
ASSERT(fd == STDIN_FILENO || fd == STDOUT_FILENO || fd == STDERR_FILENO);
|
||||
ASSERT((fd == STDIN_FILENO) ||
|
||||
(fd == STDOUT_FILENO) ||
|
||||
(fd == STDERR_FILENO));
|
||||
File* file = File::OpenStdio(static_cast<int>(fd));
|
||||
Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file)));
|
||||
}
|
||||
@@ -573,7 +575,9 @@ void FUNCTION_NAME(File_OpenStdio)(Dart_NativeArguments args) {
|
||||
|
||||
void FUNCTION_NAME(File_GetStdioHandleType)(Dart_NativeArguments args) {
|
||||
int64_t fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
|
||||
ASSERT(fd == STDIN_FILENO || fd == STDOUT_FILENO || fd == STDERR_FILENO);
|
||||
ASSERT((fd == STDIN_FILENO) ||
|
||||
(fd == STDOUT_FILENO) ||
|
||||
(fd == STDERR_FILENO));
|
||||
File::StdioHandleType type = File::GetStdioHandleType(static_cast<int>(fd));
|
||||
Dart_SetReturnValue(args, Dart_NewInteger(type));
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,9 +5,9 @@
|
||||
#ifndef BIN_FILE_H_
|
||||
#define BIN_FILE_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "bin/builtin.h"
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <libgen.h> // NOLINT
|
||||
#include <sys/sendfile.h> // NOLINT
|
||||
#include <sys/stat.h> // NOLINT
|
||||
#include <sys/types.h> // NOLINT
|
||||
#include <sys/sendfile.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <libgen.h> // NOLINT
|
||||
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/log.h"
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "platform/signal_blocker.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -114,7 +113,7 @@ bool File::Flush() {
|
||||
|
||||
bool File::Lock(File::LockType lock, int64_t start, int64_t end) {
|
||||
ASSERT(handle_->fd() >= 0);
|
||||
ASSERT(end == -1 || end > start);
|
||||
ASSERT((end == -1) || (end > start));
|
||||
struct flock fl;
|
||||
switch (lock) {
|
||||
case File::kLockUnlock:
|
||||
@@ -399,7 +398,7 @@ const char* File::LinkTarget(const char* pathname) {
|
||||
|
||||
|
||||
bool File::IsAbsolutePath(const char* pathname) {
|
||||
return (pathname != NULL && pathname[0] == '/');
|
||||
return ((pathname != NULL) && (pathname[0] == '/'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <libgen.h> // NOLINT
|
||||
#include <sys/sendfile.h> // NOLINT
|
||||
#include <sys/stat.h> // NOLINT
|
||||
#include <sys/types.h> // NOLINT
|
||||
#include <sys/sendfile.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <libgen.h> // NOLINT
|
||||
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/log.h"
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
#include "bin/file.h"
|
||||
|
||||
#include <copyfile.h> // NOLINT
|
||||
#include <errno.h> // NOLINT
|
||||
#include <fcntl.h> // NOLINT
|
||||
#include <copyfile.h> // NOLINT
|
||||
#include <sys/stat.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <libgen.h> // NOLINT
|
||||
#include <limits.h> // NOLINT
|
||||
#include <sys/stat.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/fdutils.h"
|
||||
|
||||
@@ -5,15 +5,14 @@
|
||||
#ifndef BIN_FILE_SYSTEM_WATCHER_H_
|
||||
#define BIN_FILE_SYSTEM_WATCHER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/dartutils.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -11,10 +11,8 @@
|
||||
#include <sys/inotify.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -46,10 +44,18 @@ intptr_t FileSystemWatcher::WatchPath(intptr_t id,
|
||||
int events,
|
||||
bool recursive) {
|
||||
int list_events = IN_DELETE_SELF | IN_MOVE_SELF;
|
||||
if (events & kCreate) list_events |= IN_CREATE;
|
||||
if (events & kModifyContent) list_events |= IN_CLOSE_WRITE | IN_ATTRIB;
|
||||
if (events & kDelete) list_events |= IN_DELETE;
|
||||
if (events & kMove) list_events |= IN_MOVE;
|
||||
if ((events & kCreate) != 0) {
|
||||
list_events |= IN_CREATE;
|
||||
}
|
||||
if ((events & kModifyContent) != 0) {
|
||||
list_events |= IN_CLOSE_WRITE | IN_ATTRIB;
|
||||
}
|
||||
if ((events & kDelete) != 0) {
|
||||
list_events |= IN_DELETE;
|
||||
}
|
||||
if ((events & kMove) != 0) {
|
||||
list_events |= IN_MOVE;
|
||||
}
|
||||
int path_id = NO_RETRY_EXPECTED(inotify_add_watch(id, path, list_events));
|
||||
if (path_id < 0) {
|
||||
return -1;
|
||||
@@ -69,6 +75,33 @@ intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) {
|
||||
}
|
||||
|
||||
|
||||
static int InotifyEventToMask(struct inotify_event* e) {
|
||||
int mask = 0;
|
||||
if ((e->mask & IN_CLOSE_WRITE) != 0) {
|
||||
mask |= FileSystemWatcher::kModifyContent;
|
||||
}
|
||||
if ((e->mask & IN_ATTRIB) != 0) {
|
||||
mask |= FileSystemWatcher::kModefyAttribute;
|
||||
}
|
||||
if ((e->mask & IN_CREATE) != 0) {
|
||||
mask |= FileSystemWatcher::kCreate;
|
||||
}
|
||||
if ((e->mask & IN_MOVE) != 0) {
|
||||
mask |= FileSystemWatcher::kMove;
|
||||
}
|
||||
if ((e->mask & IN_DELETE) != 0) {
|
||||
mask |= FileSystemWatcher::kDelete;
|
||||
}
|
||||
if ((e->mask & (IN_DELETE_SELF | IN_MOVE_SELF)) != 0) {
|
||||
mask |= FileSystemWatcher::kDeleteSelf;
|
||||
}
|
||||
if ((e->mask & IN_ISDIR) != 0) {
|
||||
mask |= FileSystemWatcher::kIsDir;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
||||
USE(path_id);
|
||||
const intptr_t kEventSize = sizeof(struct inotify_event);
|
||||
@@ -87,14 +120,7 @@ Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
||||
reinterpret_cast<struct inotify_event*>(buffer + offset);
|
||||
if ((e->mask & IN_IGNORED) == 0) {;
|
||||
Dart_Handle event = Dart_NewList(5);
|
||||
int mask = 0;
|
||||
if (e->mask & IN_CLOSE_WRITE) mask |= kModifyContent;
|
||||
if (e->mask & IN_ATTRIB) mask |= kModefyAttribute;
|
||||
if (e->mask & IN_CREATE) mask |= kCreate;
|
||||
if (e->mask & IN_MOVE) mask |= kMove;
|
||||
if (e->mask & IN_DELETE) mask |= kDelete;
|
||||
if (e->mask & (IN_DELETE_SELF | IN_MOVE_SELF)) mask |= kDeleteSelf;
|
||||
if (e->mask & IN_ISDIR) mask |= kIsDir;
|
||||
int mask = InotifyEventToMask(e);
|
||||
Dart_ListSetAt(event, 0, Dart_NewInteger(mask));
|
||||
Dart_ListSetAt(event, 1, Dart_NewInteger(e->cookie));
|
||||
if (e->len > 0) {
|
||||
|
||||
@@ -12,10 +12,8 @@
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
#include "bin/socket.h"
|
||||
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -26,7 +24,9 @@ bool FileSystemWatcher::IsSupported() {
|
||||
|
||||
intptr_t FileSystemWatcher::Init() {
|
||||
int id = NO_RETRY_EXPECTED(inotify_init1(IN_CLOEXEC));
|
||||
if (id < 0) return -1;
|
||||
if (id < 0) {
|
||||
return -1;
|
||||
}
|
||||
// Some systems dosn't support setting this as non-blocking. Since watching
|
||||
// internals are kept away from the user, we know it's possible to continue,
|
||||
// even if setting non-blocking fails.
|
||||
@@ -45,10 +45,18 @@ intptr_t FileSystemWatcher::WatchPath(intptr_t id,
|
||||
int events,
|
||||
bool recursive) {
|
||||
int list_events = IN_DELETE_SELF | IN_MOVE_SELF;
|
||||
if (events & kCreate) list_events |= IN_CREATE;
|
||||
if (events & kModifyContent) list_events |= IN_CLOSE_WRITE | IN_ATTRIB;
|
||||
if (events & kDelete) list_events |= IN_DELETE;
|
||||
if (events & kMove) list_events |= IN_MOVE;
|
||||
if ((events & kCreate) != 0) {
|
||||
list_events |= IN_CREATE;
|
||||
}
|
||||
if ((events & kModifyContent) != 0) {
|
||||
list_events |= IN_CLOSE_WRITE | IN_ATTRIB;
|
||||
}
|
||||
if ((events & kDelete) != 0) {
|
||||
list_events |= IN_DELETE;
|
||||
}
|
||||
if ((events & kMove) != 0) {
|
||||
list_events |= IN_MOVE;
|
||||
}
|
||||
int path_id = NO_RETRY_EXPECTED(inotify_add_watch(id, path, list_events));
|
||||
if (path_id < 0) {
|
||||
return -1;
|
||||
@@ -68,6 +76,33 @@ intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) {
|
||||
}
|
||||
|
||||
|
||||
static int InotifyEventToMask(struct inotify_event* e) {
|
||||
int mask = 0;
|
||||
if ((e->mask & IN_CLOSE_WRITE) != 0) {
|
||||
mask |= FileSystemWatcher::kModifyContent;
|
||||
}
|
||||
if ((e->mask & IN_ATTRIB) != 0) {
|
||||
mask |= FileSystemWatcher::kModefyAttribute;
|
||||
}
|
||||
if ((e->mask & IN_CREATE) != 0) {
|
||||
mask |= FileSystemWatcher::kCreate;
|
||||
}
|
||||
if ((e->mask & IN_MOVE) != 0) {
|
||||
mask |= FileSystemWatcher::kMove;
|
||||
}
|
||||
if ((e->mask & IN_DELETE) != 0) {
|
||||
mask |= FileSystemWatcher::kDelete;
|
||||
}
|
||||
if ((e->mask & (IN_DELETE_SELF | IN_MOVE_SELF)) != 0) {
|
||||
mask |= FileSystemWatcher::kDeleteSelf;
|
||||
}
|
||||
if ((e->mask & IN_ISDIR) != 0) {
|
||||
mask |= FileSystemWatcher::kIsDir;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
||||
USE(path_id);
|
||||
const intptr_t kEventSize = sizeof(struct inotify_event);
|
||||
@@ -86,14 +121,7 @@ Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
||||
reinterpret_cast<struct inotify_event*>(buffer + offset);
|
||||
if ((e->mask & IN_IGNORED) == 0) {;
|
||||
Dart_Handle event = Dart_NewList(5);
|
||||
int mask = 0;
|
||||
if (e->mask & IN_CLOSE_WRITE) mask |= kModifyContent;
|
||||
if (e->mask & IN_ATTRIB) mask |= kModefyAttribute;
|
||||
if (e->mask & IN_CREATE) mask |= kCreate;
|
||||
if (e->mask & IN_MOVE) mask |= kMove;
|
||||
if (e->mask & IN_DELETE) mask |= kDelete;
|
||||
if (e->mask & (IN_DELETE_SELF | IN_MOVE_SELF)) mask |= kDeleteSelf;
|
||||
if (e->mask & IN_ISDIR) mask |= kIsDir;
|
||||
int mask = InotifyEventToMask(e);
|
||||
Dart_ListSetAt(event, 0, Dart_NewInteger(mask));
|
||||
Dart_ListSetAt(event, 1, Dart_NewInteger(e->cookie));
|
||||
if (e->len > 0) {
|
||||
|
||||
@@ -19,10 +19,8 @@
|
||||
#include "bin/file.h"
|
||||
#include "bin/socket.h"
|
||||
#include "bin/thread.h"
|
||||
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
|
||||
#ifndef MAC_OS_X_VERSION_10_7
|
||||
enum {
|
||||
kFSEventStreamCreateFlagFileEvents = 0x00000010
|
||||
@@ -42,7 +40,6 @@ enum {
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -55,6 +52,7 @@ union FSEvent {
|
||||
uint8_t bytes[PATH_MAX + 8];
|
||||
};
|
||||
|
||||
|
||||
class FSEventsWatcher {
|
||||
public:
|
||||
class Node {
|
||||
@@ -180,6 +178,8 @@ class FSEventsWatcher {
|
||||
int write_fd_;
|
||||
bool recursive_;
|
||||
FSEventStreamRef ref_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Node);
|
||||
};
|
||||
|
||||
|
||||
@@ -287,15 +287,21 @@ class FSEventsWatcher {
|
||||
Thread::GetCurrentThreadId()));
|
||||
// `ready` is set on same thread as this callback is invoked, so we don't
|
||||
// need to lock here.
|
||||
if (!node->ready()) return;
|
||||
if (!node->ready()) {
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < num_events; i++) {
|
||||
char *path = reinterpret_cast<char**>(event_paths)[i];
|
||||
FSEvent event;
|
||||
event.data.exists = File::GetType(path, false) != File::kDoesNotExist;
|
||||
path += node->base_path_length();
|
||||
// If path is longer the base, skip next character ('/').
|
||||
if (path[0] != '\0') path += 1;
|
||||
if (!node->recursive() && strstr(path, "/") != NULL) continue;
|
||||
if (path[0] != '\0') {
|
||||
path += 1;
|
||||
}
|
||||
if (!node->recursive() && (strstr(path, "/") != NULL)) {
|
||||
continue;
|
||||
}
|
||||
event.data.flags = event_flags[i];
|
||||
memmove(event.data.path, path, strlen(path) + 1);
|
||||
write(node->write_fd(), event.bytes, sizeof(event));
|
||||
@@ -305,6 +311,8 @@ class FSEventsWatcher {
|
||||
Monitor monitor_;
|
||||
CFRunLoopRef run_loop_;
|
||||
ThreadId threadId_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FSEventsWatcher);
|
||||
};
|
||||
|
||||
|
||||
@@ -348,7 +356,9 @@ Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
||||
intptr_t fd = GetSocketId(id, path_id);
|
||||
intptr_t avail = FDUtils::AvailableBytes(fd);
|
||||
int count = avail / sizeof(FSEvent);
|
||||
if (count <= 0) return Dart_NewList(0);
|
||||
if (count <= 0) {
|
||||
return Dart_NewList(0);
|
||||
}
|
||||
Dart_Handle events = Dart_NewList(count);
|
||||
FSEvent e;
|
||||
for (int i = 0; i < count; i++) {
|
||||
@@ -360,7 +370,7 @@ Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
||||
Dart_Handle event = Dart_NewList(5);
|
||||
int flags = e.data.flags;
|
||||
int mask = 0;
|
||||
if (flags & kFSEventStreamEventFlagItemRenamed) {
|
||||
if ((flags & kFSEventStreamEventFlagItemRenamed) != 0) {
|
||||
if (path_len == 0) {
|
||||
// The moved path is the path being watched.
|
||||
mask |= kDeleteSelf;
|
||||
@@ -368,11 +378,19 @@ Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
||||
mask |= e.data.exists ? kCreate : kDelete;
|
||||
}
|
||||
}
|
||||
if (flags & kFSEventStreamEventFlagItemModified) mask |= kModifyContent;
|
||||
if (flags & kFSEventStreamEventFlagItemXattrMod) mask |= kModefyAttribute;
|
||||
if (flags & kFSEventStreamEventFlagItemCreated) mask |= kCreate;
|
||||
if (flags & kFSEventStreamEventFlagItemIsDir) mask |= kIsDir;
|
||||
if (flags & kFSEventStreamEventFlagItemRemoved) {
|
||||
if ((flags & kFSEventStreamEventFlagItemModified) != 0) {
|
||||
mask |= kModifyContent;
|
||||
}
|
||||
if ((flags & kFSEventStreamEventFlagItemXattrMod) != 0) {
|
||||
mask |= kModefyAttribute;
|
||||
}
|
||||
if ((flags & kFSEventStreamEventFlagItemCreated) != 0) {
|
||||
mask |= kCreate;
|
||||
}
|
||||
if ((flags & kFSEventStreamEventFlagItemIsDir) != 0) {
|
||||
mask |= kIsDir;
|
||||
}
|
||||
if ((flags & kFSEventStreamEventFlagItemRemoved) != 0) {
|
||||
if (path_len == 0) {
|
||||
// The removed path is the path being watched.
|
||||
mask |= kDeleteSelf;
|
||||
@@ -404,24 +422,30 @@ Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
||||
return DartUtils::NewDartOSError();
|
||||
}
|
||||
|
||||
|
||||
intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
bool FileSystemWatcher::IsSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) {
|
||||
}
|
||||
|
||||
|
||||
intptr_t FileSystemWatcher::Init() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void FileSystemWatcher::Close(intptr_t id) {
|
||||
}
|
||||
|
||||
|
||||
intptr_t FileSystemWatcher::WatchPath(intptr_t id,
|
||||
const char* path,
|
||||
int events,
|
||||
@@ -433,5 +457,4 @@ intptr_t FileSystemWatcher::WatchPath(intptr_t id,
|
||||
} // namespace dart
|
||||
|
||||
#endif // !TARGET_OS_IOS
|
||||
|
||||
#endif // defined(TARGET_OS_MACOS)
|
||||
|
||||
@@ -6,16 +6,15 @@
|
||||
#if defined(TARGET_OS_WINDOWS)
|
||||
|
||||
#include "bin/file_system_watcher.h"
|
||||
#include "bin/eventhandler.h"
|
||||
|
||||
#include <WinIoCtl.h> // NOLINT
|
||||
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/eventhandler.h"
|
||||
#include "bin/log.h"
|
||||
#include "bin/utils.h"
|
||||
#include "bin/utils_win.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -55,11 +54,13 @@ intptr_t FileSystemWatcher::WatchPath(intptr_t id,
|
||||
}
|
||||
|
||||
int list_events = 0;
|
||||
if (events & (kCreate | kMove | kDelete)) {
|
||||
if ((events & (kCreate | kMove | kDelete)) != 0) {
|
||||
list_events |= FILE_NOTIFY_CHANGE_FILE_NAME |
|
||||
FILE_NOTIFY_CHANGE_DIR_NAME;
|
||||
}
|
||||
if (events & kModifyContent) list_events |= FILE_NOTIFY_CHANGE_LAST_WRITE;
|
||||
if ((events & kModifyContent) != 0) {
|
||||
list_events |= FILE_NOTIFY_CHANGE_LAST_WRITE;
|
||||
}
|
||||
|
||||
DirectoryWatchHandle* handle =
|
||||
new DirectoryWatchHandle(dir, list_events, recursive);
|
||||
@@ -102,11 +103,21 @@ Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
||||
|
||||
Dart_Handle event = Dart_NewList(5);
|
||||
int mask = 0;
|
||||
if (e->Action == FILE_ACTION_ADDED) mask |= kCreate;
|
||||
if (e->Action == FILE_ACTION_REMOVED) mask |= kDelete;
|
||||
if (e->Action == FILE_ACTION_MODIFIED) mask |= kModifyContent;
|
||||
if (e->Action == FILE_ACTION_RENAMED_OLD_NAME) mask |= kMove;
|
||||
if (e->Action == FILE_ACTION_RENAMED_NEW_NAME) mask |= kMove;
|
||||
if (e->Action == FILE_ACTION_ADDED) {
|
||||
mask |= kCreate;
|
||||
}
|
||||
if (e->Action == FILE_ACTION_REMOVED) {
|
||||
mask |= kDelete;
|
||||
}
|
||||
if (e->Action == FILE_ACTION_MODIFIED) {
|
||||
mask |= kModifyContent;
|
||||
}
|
||||
if (e->Action == FILE_ACTION_RENAMED_OLD_NAME) {
|
||||
mask |= kMove;
|
||||
}
|
||||
if (e->Action == FILE_ACTION_RENAMED_NEW_NAME) {
|
||||
mask |= kMove;
|
||||
}
|
||||
Dart_ListSetAt(event, 0, Dart_NewInteger(mask));
|
||||
// Move events come in pairs. Just 'enable' by default.
|
||||
Dart_ListSetAt(event, 1, Dart_NewInteger(1));
|
||||
@@ -116,7 +127,9 @@ Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
||||
Dart_ListSetAt(event, 4, Dart_NewInteger(path_id));
|
||||
Dart_ListSetAt(events, i, event);
|
||||
i++;
|
||||
if (e->NextEntryOffset == 0) break;
|
||||
if (e->NextEntryOffset == 0) {
|
||||
break;
|
||||
}
|
||||
offset += e->NextEntryOffset;
|
||||
}
|
||||
return events;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "platform/globals.h"
|
||||
#include "vm/unit_test.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "bin/utils_win.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -110,7 +109,7 @@ bool File::Flush() {
|
||||
|
||||
bool File::Lock(File::LockType lock, int64_t start, int64_t end) {
|
||||
ASSERT(handle_->fd() >= 0);
|
||||
ASSERT(end == -1 || end > start);
|
||||
ASSERT((end == -1) || (end > start));
|
||||
HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(handle_->fd()));
|
||||
OVERLAPPED overlapped;
|
||||
ZeroMemory(&overlapped, sizeof(OVERLAPPED));
|
||||
@@ -125,7 +124,6 @@ bool File::Lock(File::LockType lock, int64_t start, int64_t end) {
|
||||
int32_t length_low = Utils::Low32Bits(length);
|
||||
int32_t length_high = Utils::High32Bits(length);
|
||||
|
||||
|
||||
BOOL rc;
|
||||
switch (lock) {
|
||||
case File::kLockUnlock:
|
||||
@@ -549,9 +547,9 @@ bool File::IsAbsolutePath(const char* pathname) {
|
||||
if (pathname == NULL) {
|
||||
return false;
|
||||
}
|
||||
return (strlen(pathname) > 2) &&
|
||||
return ((strlen(pathname) > 2) &&
|
||||
(pathname[1] == ':') &&
|
||||
(pathname[2] == '\\' || pathname[2] == '/');
|
||||
((pathname[2] == '\\') || (pathname[2] == '/')));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#include "zlib/zlib.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "include/dart_api.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -5,14 +5,12 @@
|
||||
// Generate a snapshot file after loading all the scripts specified on the
|
||||
// command line.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <cstdarg>
|
||||
|
||||
#include "include/dart_api.h"
|
||||
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/eventhandler.h"
|
||||
@@ -22,8 +20,9 @@
|
||||
#include "bin/utils.h"
|
||||
#include "bin/vmservice_impl.h"
|
||||
|
||||
#include "platform/globals.h"
|
||||
#include "include/dart_api.h"
|
||||
|
||||
#include "platform/globals.h"
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
@@ -181,16 +180,16 @@ static int ParseArguments(int argc,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (instructions_snapshot_filename != NULL &&
|
||||
embedder_entry_points_manifest == NULL) {
|
||||
if ((instructions_snapshot_filename != NULL) &&
|
||||
(embedder_entry_points_manifest == NULL)) {
|
||||
Log::PrintErr(
|
||||
"Specifying an instructions snapshot filename indicates precompilation"
|
||||
". But no embedder entry points manifest was specified.\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (embedder_entry_points_manifest != NULL &&
|
||||
instructions_snapshot_filename == NULL) {
|
||||
if ((embedder_entry_points_manifest != NULL) &&
|
||||
(instructions_snapshot_filename == NULL)) {
|
||||
Log::PrintErr(
|
||||
"Specifying the embedder entry points manifest indicates "
|
||||
"precompilation. But no instuctions snapshot was specified.\n\n");
|
||||
@@ -828,7 +827,7 @@ static Dart_QualifiedFunctionName* ParseEntryPointsManifestFile(
|
||||
static Dart_QualifiedFunctionName* ParseEntryPointsManifestIfPresent() {
|
||||
Dart_QualifiedFunctionName* entries =
|
||||
ParseEntryPointsManifestFile(embedder_entry_points_manifest);
|
||||
if (entries == NULL && IsSnapshottingForPrecompilation()) {
|
||||
if ((entries == NULL) && IsSnapshottingForPrecompilation()) {
|
||||
Log::PrintErr(
|
||||
"Could not find native embedder entry points during precompilation\n");
|
||||
exit(255);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "bin/io_buffer.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -5,10 +5,8 @@
|
||||
#ifndef BIN_IO_BUFFER_H_
|
||||
#define BIN_IO_BUFFER_H_
|
||||
|
||||
#include "platform/globals.h"
|
||||
|
||||
#include "include/dart_api.h"
|
||||
|
||||
#include "platform/globals.h"
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "include/dart_api.h"
|
||||
#include "platform/assert.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -169,7 +168,7 @@ Dart_NativeFunction IONativeLookup(Dart_Handle name,
|
||||
int num_entries = sizeof(IOEntries) / sizeof(struct NativeEntries);
|
||||
for (int i = 0; i < num_entries; i++) {
|
||||
struct NativeEntries* entry = &(IOEntries[i]);
|
||||
if (!strcmp(function_name, entry->name_) &&
|
||||
if ((strcmp(function_name, entry->name_) == 0) &&
|
||||
(entry->argument_count_ == argument_count)) {
|
||||
return reinterpret_cast<Dart_NativeFunction>(entry->function_);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "include/dart_api.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -11,11 +11,10 @@
|
||||
#include "bin/socket.h"
|
||||
#include "bin/utils.h"
|
||||
|
||||
#include "platform/globals.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
#include "include/dart_api.h"
|
||||
|
||||
#include "platform/globals.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
@@ -30,8 +29,8 @@ void IOServiceCallback(Dart_Port dest_port_id,
|
||||
Dart_Port reply_port_id = ILLEGAL_PORT;
|
||||
CObject* response = CObject::IllegalArgumentError();
|
||||
CObjectArray request(message);
|
||||
if (message->type == Dart_CObject_kArray &&
|
||||
request.Length() == 4 &&
|
||||
if ((message->type == Dart_CObject_kArray) &&
|
||||
(request.Length() == 4) &&
|
||||
request[0]->IsInt32() &&
|
||||
request[1]->IsSendPort() &&
|
||||
request[2]->IsInt32() &&
|
||||
@@ -57,10 +56,7 @@ void IOServiceCallback(Dart_Port dest_port_id,
|
||||
|
||||
|
||||
Dart_Port IOService::GetServicePort() {
|
||||
Dart_Port result = Dart_NewNativePort("IOService",
|
||||
IOServiceCallback,
|
||||
true);
|
||||
return result;
|
||||
return Dart_NewNativePort("IOService", IOServiceCallback, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +70,5 @@ void FUNCTION_NAME(IOService_NewServicePort)(Dart_NativeArguments args) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace bin
|
||||
} // namespace dart
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/utils.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -65,6 +64,10 @@ IO_SERVICE_REQUEST_LIST(DECLARE_REQUEST)
|
||||
};
|
||||
|
||||
static Dart_Port GetServicePort();
|
||||
|
||||
private:
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(IOService);
|
||||
};
|
||||
|
||||
} // namespace bin
|
||||
|
||||
@@ -10,11 +10,10 @@
|
||||
#include "bin/socket.h"
|
||||
#include "bin/utils.h"
|
||||
|
||||
#include "platform/globals.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
#include "include/dart_api.h"
|
||||
|
||||
#include "platform/globals.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
@@ -29,8 +28,8 @@ void IOServiceCallback(Dart_Port dest_port_id,
|
||||
Dart_Port reply_port_id = ILLEGAL_PORT;
|
||||
CObject* response = CObject::IllegalArgumentError();
|
||||
CObjectArray request(message);
|
||||
if (message->type == Dart_CObject_kArray &&
|
||||
request.Length() == 4 &&
|
||||
if ((message->type == Dart_CObject_kArray) &&
|
||||
(request.Length() == 4) &&
|
||||
request[0]->IsInt32() &&
|
||||
request[1]->IsSendPort() &&
|
||||
request[2]->IsInt32() &&
|
||||
@@ -56,10 +55,7 @@ void IOServiceCallback(Dart_Port dest_port_id,
|
||||
|
||||
|
||||
Dart_Port IOService::GetServicePort() {
|
||||
Dart_Port result = Dart_NewNativePort("IOService",
|
||||
IOServiceCallback,
|
||||
true);
|
||||
return result;
|
||||
return Dart_NewNativePort("IOService", IOServiceCallback, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +69,5 @@ void FUNCTION_NAME(IOService_NewServicePort)(Dart_NativeArguments args) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace bin
|
||||
} // namespace dart
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/utils.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -66,6 +65,10 @@ IO_SERVICE_REQUEST_LIST(DECLARE_REQUEST)
|
||||
};
|
||||
|
||||
static Dart_Port GetServicePort();
|
||||
|
||||
private:
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(IOService);
|
||||
};
|
||||
|
||||
} // namespace bin
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "include/dart_api.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "platform/assert.h"
|
||||
#include "platform/globals.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "bin/thread.h"
|
||||
#include "platform/assert.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "platform/globals.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -34,6 +33,7 @@ class Log {
|
||||
|
||||
static void VPrintErr(const char* format, va_list args);
|
||||
|
||||
private:
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(Log);
|
||||
};
|
||||
|
||||
@@ -7,9 +7,8 @@
|
||||
|
||||
#include "bin/log.h"
|
||||
|
||||
#include <stdio.h> // NOLINT
|
||||
#include <android/log.h> // NOLINT
|
||||
|
||||
#include <stdio.h> // NOLINT
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <stdio.h> // NOLINT
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <stdio.h> // NOLINT
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <stdio.h> // NOLINT
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
+5
-5
@@ -218,7 +218,7 @@ static bool ProcessPackageRootOption(const char* arg,
|
||||
static bool ProcessPackagesOption(const char* arg,
|
||||
CommandLineOptions* vm_options) {
|
||||
ASSERT(arg != NULL);
|
||||
if (*arg == '\0' || *arg == '-') {
|
||||
if ((*arg == '\0') || (*arg == '-')) {
|
||||
return false;
|
||||
}
|
||||
commandline_packages_file = arg;
|
||||
@@ -1076,7 +1076,7 @@ static void WriteSnapshotFile(const char* snapshot_directory,
|
||||
const intptr_t size) {
|
||||
char* concat = NULL;
|
||||
const char* qualified_filename;
|
||||
if ((snapshot_directory != NULL) && strlen(snapshot_directory) > 0) {
|
||||
if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) {
|
||||
intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename);
|
||||
concat = new char[len + 1];
|
||||
snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename);
|
||||
@@ -1110,7 +1110,7 @@ static void ReadSnapshotFile(const char* snapshot_directory,
|
||||
const uint8_t** buffer) {
|
||||
char* concat = NULL;
|
||||
const char* qualified_filename;
|
||||
if ((snapshot_directory != NULL) && strlen(snapshot_directory) > 0) {
|
||||
if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) {
|
||||
intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename);
|
||||
concat = new char[len + 1];
|
||||
snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename);
|
||||
@@ -1129,7 +1129,7 @@ static void ReadSnapshotFile(const char* snapshot_directory,
|
||||
}
|
||||
intptr_t len = -1;
|
||||
DartUtils::ReadFile(buffer, &len, file);
|
||||
if (*buffer == NULL || len == -1) {
|
||||
if ((*buffer == NULL) || (len == -1)) {
|
||||
fprintf(stderr,
|
||||
"Error: Unable to read snapshot file %s\n", qualified_filename);
|
||||
fflush(stderr);
|
||||
@@ -1147,7 +1147,7 @@ static void* LoadLibrarySymbol(const char* snapshot_directory,
|
||||
const char* symname) {
|
||||
char* concat = NULL;
|
||||
const char* qualified_libname;
|
||||
if ((snapshot_directory != NULL) && strlen(snapshot_directory) > 0) {
|
||||
if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) {
|
||||
intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, libname);
|
||||
concat = new char[len + 1];
|
||||
snprintf(concat, len + 1, "%s/%s", snapshot_directory, libname);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "bin/builtin.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -5,22 +5,19 @@
|
||||
#include "platform/globals.h"
|
||||
#if defined(TARGET_OS_MACOS)
|
||||
|
||||
#include <mach-o/dyld.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include "bin/file.h"
|
||||
#include "bin/platform.h"
|
||||
|
||||
#if !TARGET_OS_IOS
|
||||
#include <crt_externs.h> // NOLINT
|
||||
#endif // !TARGET_OS_IOS
|
||||
#include <mach-o/dyld.h>
|
||||
#include <signal.h> // NOLINT
|
||||
#include <string.h> // NOLINT
|
||||
#include <sys/sysctl.h> // NOLINT
|
||||
#include <sys/types.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
|
||||
#include "bin/file.h"
|
||||
#include "bin/platform.h"
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
#if defined(TARGET_OS_WINDOWS)
|
||||
|
||||
#include "bin/file.h"
|
||||
#include "bin/platform.h"
|
||||
#include "bin/log.h"
|
||||
#include "bin/platform.h"
|
||||
#include "bin/socket.h"
|
||||
#include "bin/utils.h"
|
||||
#include "bin/utils_win.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
|
||||
// Defined in vm/os_thread_win.cc
|
||||
|
||||
@@ -34,7 +34,7 @@ static char** ExtractCStringList(Dart_Handle strings,
|
||||
}
|
||||
// Protect against user-defined list implementations that can have
|
||||
// arbitrary length.
|
||||
if (len < 0 || len > kMaxArgumentListLength) {
|
||||
if ((len < 0) || (len > kMaxArgumentListLength)) {
|
||||
result = DartUtils::SetIntegerField(status_handle, "_errorCode", 0);
|
||||
if (Dart_IsError(result)) {
|
||||
Dart_PropagateError(result);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "platform/globals.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -183,6 +182,8 @@ class SignalInfo {
|
||||
Dart_Port port_;
|
||||
SignalInfo* next_;
|
||||
SignalInfo* prev_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SignalInfo);
|
||||
};
|
||||
|
||||
|
||||
@@ -285,6 +286,9 @@ class BufferListBase {
|
||||
|
||||
// Number of free bytes in the last node in the list.
|
||||
intptr_t free_size_;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(BufferListBase);
|
||||
};
|
||||
|
||||
} // namespace bin
|
||||
|
||||
@@ -25,10 +25,8 @@
|
||||
#include "platform/signal_blocker.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
|
||||
extern char **environ;
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -54,6 +52,8 @@ class ProcessInfo {
|
||||
pid_t pid_;
|
||||
intptr_t fd_;
|
||||
ProcessInfo* next_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProcessInfo);
|
||||
};
|
||||
|
||||
|
||||
@@ -108,6 +108,9 @@ class ProcessInfoList {
|
||||
// Mutex protecting all accesses to the linked list of active
|
||||
// processes.
|
||||
static Mutex* mutex_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessInfoList);
|
||||
};
|
||||
|
||||
|
||||
@@ -175,7 +178,7 @@ class ExitCodeHandler {
|
||||
while (true) {
|
||||
{
|
||||
MonitorLocker locker(monitor_);
|
||||
while (running_ && process_count_ == 0) {
|
||||
while (running_ && (process_count_ == 0)) {
|
||||
monitor_->Wait(Monitor::kNoTimeout);
|
||||
}
|
||||
if (!running_) {
|
||||
@@ -204,9 +207,9 @@ class ExitCodeHandler {
|
||||
// pipe has been closed. It is therefore not a problem that
|
||||
// write fails with a broken pipe error. Other errors should
|
||||
// not happen.
|
||||
if (result != -1 && result != sizeof(message)) {
|
||||
if ((result != -1) && (result != sizeof(message))) {
|
||||
FATAL("Failed to write entire process exit message");
|
||||
} else if (result == -1 && errno != EPIPE) {
|
||||
} else if ((result == -1) && (errno != EPIPE)) {
|
||||
FATAL1("Failed to write exit code: %d", errno);
|
||||
}
|
||||
ProcessInfoList::RemoveProcess(pid);
|
||||
@@ -223,6 +226,9 @@ class ExitCodeHandler {
|
||||
static int process_count_;
|
||||
static bool running_;
|
||||
static Monitor* monitor_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ExitCodeHandler);
|
||||
};
|
||||
|
||||
|
||||
@@ -265,7 +271,8 @@ class ProcessStarter {
|
||||
exec_control_[0] = -1;
|
||||
exec_control_[1] = -1;
|
||||
|
||||
program_arguments_ = new char*[arguments_length + 2];
|
||||
program_arguments_ = reinterpret_cast<char**>(Dart_ScopeAllocate(
|
||||
(arguments_length + 2) * sizeof(*program_arguments_)));
|
||||
program_arguments_[0] = const_cast<char*>(path_);
|
||||
for (int i = 0; i < arguments_length; i++) {
|
||||
program_arguments_[i + 1] = arguments[i];
|
||||
@@ -274,7 +281,8 @@ class ProcessStarter {
|
||||
|
||||
program_environment_ = NULL;
|
||||
if (environment != NULL) {
|
||||
program_environment_ = new char*[environment_length + 1];
|
||||
program_environment_ = reinterpret_cast<char**>(Dart_ScopeAllocate(
|
||||
(environment_length + 1) * sizeof(*program_environment_)));
|
||||
for (int i = 0; i < environment_length; i++) {
|
||||
program_environment_[i] = environment[i];
|
||||
}
|
||||
@@ -283,16 +291,12 @@ class ProcessStarter {
|
||||
}
|
||||
|
||||
|
||||
~ProcessStarter() {
|
||||
delete[] program_arguments_;
|
||||
delete[] program_environment_;
|
||||
}
|
||||
|
||||
|
||||
int Start() {
|
||||
// Create pipes required.
|
||||
int err = CreatePipes();
|
||||
if (err != 0) return err;
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// Fork to create the new process.
|
||||
pid_t pid = TEMP_FAILURE_RETRY(fork());
|
||||
@@ -312,7 +316,9 @@ class ProcessStarter {
|
||||
// Register the child process if not detached.
|
||||
if (mode_ == kNormal) {
|
||||
err = RegisterProcess(pid);
|
||||
if (err != 0) return err;
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
// Notify child process to start. This is done to delay the call to exec
|
||||
@@ -491,8 +497,8 @@ class ProcessStarter {
|
||||
SetupDetachedWithStdio();
|
||||
}
|
||||
|
||||
if (working_directory_ != NULL &&
|
||||
TEMP_FAILURE_RETRY(chdir(working_directory_)) == -1) {
|
||||
if ((working_directory_ != NULL) &&
|
||||
(TEMP_FAILURE_RETRY(chdir(working_directory_)) == -1)) {
|
||||
ReportChildError();
|
||||
}
|
||||
|
||||
@@ -534,9 +540,8 @@ class ProcessStarter {
|
||||
// Read exec result from child. If no data is returned the exec was
|
||||
// successful and the exec call closed the pipe. Otherwise the errno
|
||||
// is written to the pipe.
|
||||
bytes_read =
|
||||
FDUtils::ReadFromBlocking(
|
||||
exec_control_[0], &child_errno, sizeof(child_errno));
|
||||
bytes_read = FDUtils::ReadFromBlocking(
|
||||
exec_control_[0], &child_errno, sizeof(child_errno));
|
||||
if (bytes_read == sizeof(child_errno)) {
|
||||
ReadChildError();
|
||||
return child_errno;
|
||||
@@ -555,8 +560,7 @@ class ProcessStarter {
|
||||
// is written to the pipe as well.
|
||||
int result[2];
|
||||
bytes_read =
|
||||
FDUtils::ReadFromBlocking(
|
||||
exec_control_[0], result, sizeof(result));
|
||||
FDUtils::ReadFromBlocking(exec_control_[0], result, sizeof(result));
|
||||
if (bytes_read == sizeof(int)) {
|
||||
*pid = result[0];
|
||||
} else if (bytes_read == 2 * sizeof(int)) {
|
||||
@@ -576,7 +580,9 @@ class ProcessStarter {
|
||||
|
||||
// Close all open file descriptors except for exec_control_[1].
|
||||
int max_fds = sysconf(_SC_OPEN_MAX);
|
||||
if (max_fds == -1) max_fds = _POSIX_OPEN_MAX;
|
||||
if (max_fds == -1) {
|
||||
max_fds = _POSIX_OPEN_MAX;
|
||||
}
|
||||
for (int fd = 0; fd < max_fds; fd++) {
|
||||
if (fd != exec_control_[1]) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
@@ -605,12 +611,14 @@ class ProcessStarter {
|
||||
// exec_control_[1], write_out_[0], read_in_[1] and
|
||||
// read_err_[1].
|
||||
int max_fds = sysconf(_SC_OPEN_MAX);
|
||||
if (max_fds == -1) max_fds = _POSIX_OPEN_MAX;
|
||||
if (max_fds == -1) {
|
||||
max_fds = _POSIX_OPEN_MAX;
|
||||
}
|
||||
for (int fd = 0; fd < max_fds; fd++) {
|
||||
if (fd != exec_control_[1] &&
|
||||
fd != write_out_[0] &&
|
||||
fd != read_in_[1] &&
|
||||
fd != read_err_[1]) {
|
||||
if ((fd != exec_control_[1]) &&
|
||||
(fd != write_out_[0]) &&
|
||||
(fd != read_in_[1]) &&
|
||||
(fd != read_err_[1])) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
}
|
||||
}
|
||||
@@ -731,6 +739,9 @@ class ProcessStarter {
|
||||
intptr_t* id_;
|
||||
intptr_t* exit_event_;
|
||||
char** os_error_message_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessStarter);
|
||||
};
|
||||
|
||||
|
||||
@@ -766,10 +777,14 @@ int Process::Start(const char* path,
|
||||
|
||||
class BufferList: public BufferListBase {
|
||||
public:
|
||||
BufferList() {}
|
||||
|
||||
bool Read(int fd, intptr_t available) {
|
||||
// Read all available bytes.
|
||||
while (available > 0) {
|
||||
if (free_size_ == 0) Allocate();
|
||||
if (free_size_ == 0) {
|
||||
Allocate();
|
||||
}
|
||||
ASSERT(free_size_ > 0);
|
||||
ASSERT(free_size_ <= kBufferSize);
|
||||
intptr_t block_size = dart::Utils::Minimum(free_size_, available);
|
||||
@@ -777,13 +792,18 @@ class BufferList: public BufferListBase {
|
||||
fd,
|
||||
reinterpret_cast<void*>(FreeSpaceAddress()),
|
||||
block_size));
|
||||
if (bytes < 0) return false;
|
||||
if (bytes < 0) {
|
||||
return false;
|
||||
}
|
||||
data_size_ += bytes;
|
||||
free_size_ -= bytes;
|
||||
available -= bytes;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(BufferList);
|
||||
};
|
||||
|
||||
|
||||
@@ -835,7 +855,7 @@ bool Process::Wait(intptr_t pid,
|
||||
// Process incoming data.
|
||||
int current_alive = alive;
|
||||
for (int i = 0; i < current_alive; i++) {
|
||||
if (fds[i].revents & POLLIN) {
|
||||
if ((fds[i].revents & POLLIN) != 0) {
|
||||
intptr_t avail = FDUtils::AvailableBytes(fds[i].fd);
|
||||
if (fds[i].fd == out) {
|
||||
if (!out_data.Read(out, avail)) {
|
||||
@@ -857,7 +877,7 @@ bool Process::Wait(intptr_t pid,
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if (fds[i].revents & POLLHUP) {
|
||||
if ((fds[i].revents & POLLHUP) != 0) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fds[i].fd));
|
||||
alive--;
|
||||
if (i < alive) {
|
||||
@@ -874,7 +894,9 @@ bool Process::Wait(intptr_t pid,
|
||||
// Calculate the exit code.
|
||||
intptr_t exit_code = exit_code_data.ints[0];
|
||||
intptr_t negative = exit_code_data.ints[1];
|
||||
if (negative) exit_code = -exit_code;
|
||||
if (negative != 0) {
|
||||
exit_code = -exit_code;
|
||||
}
|
||||
result->set_exit_code(exit_code);
|
||||
|
||||
return true;
|
||||
@@ -936,7 +958,9 @@ intptr_t Process::SetSignalHandler(intptr_t signal) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) return -1;
|
||||
if (!found) {
|
||||
return -1;
|
||||
}
|
||||
int fds[2];
|
||||
if (NO_RETRY_EXPECTED(pipe2(fds, O_CLOEXEC)) != 0) {
|
||||
return -1;
|
||||
@@ -986,7 +1010,9 @@ void Process::ClearSignalHandler(intptr_t signal) {
|
||||
bool remove = false;
|
||||
if (handler->signal() == signal) {
|
||||
if (handler->port() == Dart_GetMainPortId()) {
|
||||
if (signal_handlers == handler) signal_handlers = handler->next();
|
||||
if (signal_handlers == handler) {
|
||||
signal_handlers = handler->next();
|
||||
}
|
||||
handler->Unlink();
|
||||
remove = true;
|
||||
} else {
|
||||
@@ -994,7 +1020,9 @@ void Process::ClearSignalHandler(intptr_t signal) {
|
||||
}
|
||||
}
|
||||
SignalInfo* next = handler->next();
|
||||
if (remove) delete handler;
|
||||
if (remove) {
|
||||
delete handler;
|
||||
}
|
||||
handler = next;
|
||||
}
|
||||
if (unlisten) {
|
||||
|
||||
@@ -24,10 +24,8 @@
|
||||
#include "platform/signal_blocker.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
|
||||
extern char **environ;
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -53,6 +51,8 @@ class ProcessInfo {
|
||||
pid_t pid_;
|
||||
intptr_t fd_;
|
||||
ProcessInfo* next_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProcessInfo);
|
||||
};
|
||||
|
||||
|
||||
@@ -107,6 +107,9 @@ class ProcessInfoList {
|
||||
// Mutex protecting all accesses to the linked list of active
|
||||
// processes.
|
||||
static Mutex* mutex_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessInfoList);
|
||||
};
|
||||
|
||||
|
||||
@@ -203,9 +206,9 @@ class ExitCodeHandler {
|
||||
// pipe has been closed. It is therefore not a problem that
|
||||
// write fails with a broken pipe error. Other errors should
|
||||
// not happen.
|
||||
if (result != -1 && result != sizeof(message)) {
|
||||
if ((result != -1) && (result != sizeof(message))) {
|
||||
FATAL("Failed to write entire process exit message");
|
||||
} else if (result == -1 && errno != EPIPE) {
|
||||
} else if ((result == -1) && (errno != EPIPE)) {
|
||||
FATAL1("Failed to write exit code: %d", errno);
|
||||
}
|
||||
ProcessInfoList::RemoveProcess(pid);
|
||||
@@ -222,6 +225,9 @@ class ExitCodeHandler {
|
||||
static int process_count_;
|
||||
static bool running_;
|
||||
static Monitor* monitor_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ExitCodeHandler);
|
||||
};
|
||||
|
||||
|
||||
@@ -264,7 +270,8 @@ class ProcessStarter {
|
||||
exec_control_[0] = -1;
|
||||
exec_control_[1] = -1;
|
||||
|
||||
program_arguments_ = new char*[arguments_length + 2];
|
||||
program_arguments_ = reinterpret_cast<char**>(Dart_ScopeAllocate(
|
||||
(arguments_length + 2) * sizeof(*program_arguments_)));
|
||||
program_arguments_[0] = const_cast<char*>(path_);
|
||||
for (int i = 0; i < arguments_length; i++) {
|
||||
program_arguments_[i + 1] = arguments[i];
|
||||
@@ -273,7 +280,8 @@ class ProcessStarter {
|
||||
|
||||
program_environment_ = NULL;
|
||||
if (environment != NULL) {
|
||||
program_environment_ = new char*[environment_length + 1];
|
||||
program_environment_ = reinterpret_cast<char**>(Dart_ScopeAllocate(
|
||||
(environment_length + 1) * sizeof(*program_environment_)));
|
||||
for (int i = 0; i < environment_length; i++) {
|
||||
program_environment_[i] = environment[i];
|
||||
}
|
||||
@@ -282,16 +290,12 @@ class ProcessStarter {
|
||||
}
|
||||
|
||||
|
||||
~ProcessStarter() {
|
||||
delete[] program_arguments_;
|
||||
delete[] program_environment_;
|
||||
}
|
||||
|
||||
|
||||
int Start() {
|
||||
// Create pipes required.
|
||||
int err = CreatePipes();
|
||||
if (err != 0) return err;
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// Fork to create the new process.
|
||||
pid_t pid = TEMP_FAILURE_RETRY(fork());
|
||||
@@ -311,7 +315,9 @@ class ProcessStarter {
|
||||
// Register the child process if not detached.
|
||||
if (mode_ == kNormal) {
|
||||
err = RegisterProcess(pid);
|
||||
if (err != 0) return err;
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
// Notify child process to start. This is done to delay the call to exec
|
||||
@@ -490,8 +496,8 @@ class ProcessStarter {
|
||||
SetupDetachedWithStdio();
|
||||
}
|
||||
|
||||
if (working_directory_ != NULL &&
|
||||
TEMP_FAILURE_RETRY(chdir(working_directory_)) == -1) {
|
||||
if ((working_directory_ != NULL) &&
|
||||
(TEMP_FAILURE_RETRY(chdir(working_directory_)) == -1)) {
|
||||
ReportChildError();
|
||||
}
|
||||
|
||||
@@ -533,9 +539,8 @@ class ProcessStarter {
|
||||
// Read exec result from child. If no data is returned the exec was
|
||||
// successful and the exec call closed the pipe. Otherwise the errno
|
||||
// is written to the pipe.
|
||||
bytes_read =
|
||||
FDUtils::ReadFromBlocking(
|
||||
exec_control_[0], &child_errno, sizeof(child_errno));
|
||||
bytes_read = FDUtils::ReadFromBlocking(
|
||||
exec_control_[0], &child_errno, sizeof(child_errno));
|
||||
if (bytes_read == sizeof(child_errno)) {
|
||||
ReadChildError();
|
||||
return child_errno;
|
||||
@@ -554,8 +559,7 @@ class ProcessStarter {
|
||||
// is written to the pipe as well.
|
||||
int result[2];
|
||||
bytes_read =
|
||||
FDUtils::ReadFromBlocking(
|
||||
exec_control_[0], result, sizeof(result));
|
||||
FDUtils::ReadFromBlocking(exec_control_[0], result, sizeof(result));
|
||||
if (bytes_read == sizeof(int)) {
|
||||
*pid = result[0];
|
||||
} else if (bytes_read == 2 * sizeof(int)) {
|
||||
@@ -575,7 +579,9 @@ class ProcessStarter {
|
||||
|
||||
// Close all open file descriptors except for exec_control_[1].
|
||||
int max_fds = sysconf(_SC_OPEN_MAX);
|
||||
if (max_fds == -1) max_fds = _POSIX_OPEN_MAX;
|
||||
if (max_fds == -1) {
|
||||
max_fds = _POSIX_OPEN_MAX;
|
||||
}
|
||||
for (int fd = 0; fd < max_fds; fd++) {
|
||||
if (fd != exec_control_[1]) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
@@ -604,12 +610,14 @@ class ProcessStarter {
|
||||
// exec_control_[1], write_out_[0], read_in_[1] and
|
||||
// read_err_[1].
|
||||
int max_fds = sysconf(_SC_OPEN_MAX);
|
||||
if (max_fds == -1) max_fds = _POSIX_OPEN_MAX;
|
||||
if (max_fds == -1) {
|
||||
max_fds = _POSIX_OPEN_MAX;
|
||||
}
|
||||
for (int fd = 0; fd < max_fds; fd++) {
|
||||
if (fd != exec_control_[1] &&
|
||||
fd != write_out_[0] &&
|
||||
fd != read_in_[1] &&
|
||||
fd != read_err_[1]) {
|
||||
if ((fd != exec_control_[1]) &&
|
||||
(fd != write_out_[0]) &&
|
||||
(fd != read_in_[1]) &&
|
||||
(fd != read_err_[1])) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
}
|
||||
}
|
||||
@@ -659,9 +667,8 @@ class ProcessStarter {
|
||||
const int kBufferSize = 1024;
|
||||
char error_buf[kBufferSize];
|
||||
char* os_error_message = Utils::StrError(errno, error_buf, kBufferSize);
|
||||
int bytes_written =
|
||||
FDUtils::WriteToBlocking(
|
||||
exec_control_[1], &child_errno, sizeof(child_errno));
|
||||
int bytes_written = FDUtils::WriteToBlocking(
|
||||
exec_control_[1], &child_errno, sizeof(child_errno));
|
||||
if (bytes_written == sizeof(child_errno)) {
|
||||
FDUtils::WriteToBlocking(
|
||||
exec_control_[1], os_error_message, strlen(os_error_message) + 1);
|
||||
@@ -730,6 +737,9 @@ class ProcessStarter {
|
||||
intptr_t* id_;
|
||||
intptr_t* exit_event_;
|
||||
char** os_error_message_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessStarter);
|
||||
};
|
||||
|
||||
|
||||
@@ -765,10 +775,14 @@ int Process::Start(const char* path,
|
||||
|
||||
class BufferList: public BufferListBase {
|
||||
public:
|
||||
BufferList() {}
|
||||
|
||||
bool Read(int fd, intptr_t available) {
|
||||
// Read all available bytes.
|
||||
while (available > 0) {
|
||||
if (free_size_ == 0) Allocate();
|
||||
if (free_size_ == 0) {
|
||||
Allocate();
|
||||
}
|
||||
ASSERT(free_size_ > 0);
|
||||
ASSERT(free_size_ <= kBufferSize);
|
||||
intptr_t block_size = dart::Utils::Minimum(free_size_, available);
|
||||
@@ -776,13 +790,18 @@ class BufferList: public BufferListBase {
|
||||
fd,
|
||||
reinterpret_cast<void*>(FreeSpaceAddress()),
|
||||
block_size));
|
||||
if (bytes < 0) return false;
|
||||
if (bytes < 0) {
|
||||
return false;
|
||||
}
|
||||
data_size_ += bytes;
|
||||
free_size_ -= bytes;
|
||||
available -= bytes;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(BufferList);
|
||||
};
|
||||
|
||||
|
||||
@@ -834,7 +853,7 @@ bool Process::Wait(intptr_t pid,
|
||||
// Process incoming data.
|
||||
int current_alive = alive;
|
||||
for (int i = 0; i < current_alive; i++) {
|
||||
if (fds[i].revents & POLLIN) {
|
||||
if ((fds[i].revents & POLLIN) != 0) {
|
||||
intptr_t avail = FDUtils::AvailableBytes(fds[i].fd);
|
||||
if (fds[i].fd == out) {
|
||||
if (!out_data.Read(out, avail)) {
|
||||
@@ -856,7 +875,7 @@ bool Process::Wait(intptr_t pid,
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if (fds[i].revents & POLLHUP) {
|
||||
if ((fds[i].revents & POLLHUP) != 0) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fds[i].fd));
|
||||
alive--;
|
||||
if (i < alive) {
|
||||
@@ -873,7 +892,9 @@ bool Process::Wait(intptr_t pid,
|
||||
// Calculate the exit code.
|
||||
intptr_t exit_code = exit_code_data.ints[0];
|
||||
intptr_t negative = exit_code_data.ints[1];
|
||||
if (negative) exit_code = -exit_code;
|
||||
if (negative != 0) {
|
||||
exit_code = -exit_code;
|
||||
}
|
||||
result->set_exit_code(exit_code);
|
||||
|
||||
return true;
|
||||
@@ -935,7 +956,9 @@ intptr_t Process::SetSignalHandler(intptr_t signal) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) return -1;
|
||||
if (!found) {
|
||||
return -1;
|
||||
}
|
||||
int fds[2];
|
||||
if (NO_RETRY_EXPECTED(pipe2(fds, O_CLOEXEC)) != 0) {
|
||||
return -1;
|
||||
@@ -982,7 +1005,9 @@ void Process::ClearSignalHandler(intptr_t signal) {
|
||||
bool remove = false;
|
||||
if (handler->signal() == signal) {
|
||||
if (handler->port() == Dart_GetMainPortId()) {
|
||||
if (signal_handlers == handler) signal_handlers = handler->next();
|
||||
if (signal_handlers == handler) {
|
||||
signal_handlers = handler->next();
|
||||
}
|
||||
handler->Unlink();
|
||||
remove = true;
|
||||
} else {
|
||||
@@ -990,7 +1015,9 @@ void Process::ClearSignalHandler(intptr_t signal) {
|
||||
}
|
||||
}
|
||||
SignalInfo* next = handler->next();
|
||||
if (remove) delete handler;
|
||||
if (remove) {
|
||||
delete handler;
|
||||
}
|
||||
handler = next;
|
||||
}
|
||||
if (unlisten) {
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include "platform/signal_blocker.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -55,6 +53,8 @@ class ProcessInfo {
|
||||
pid_t pid_;
|
||||
intptr_t fd_;
|
||||
ProcessInfo* next_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProcessInfo);
|
||||
};
|
||||
|
||||
|
||||
@@ -109,6 +109,9 @@ class ProcessInfoList {
|
||||
// Mutex protecting all accesses to the linked list of active
|
||||
// processes.
|
||||
static Mutex* mutex_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessInfoList);
|
||||
};
|
||||
|
||||
|
||||
@@ -205,9 +208,9 @@ class ExitCodeHandler {
|
||||
// pipe has been closed. It is therefore not a problem that
|
||||
// write fails with a broken pipe error. Other errors should
|
||||
// not happen.
|
||||
if (result != -1 && result != sizeof(message)) {
|
||||
if ((result != -1) && (result != sizeof(message))) {
|
||||
FATAL("Failed to write entire process exit message");
|
||||
} else if (result == -1 && errno != EPIPE) {
|
||||
} else if ((result == -1) && (errno != EPIPE)) {
|
||||
FATAL1("Failed to write exit code: %d", errno);
|
||||
}
|
||||
ProcessInfoList::RemoveProcess(pid);
|
||||
@@ -224,6 +227,9 @@ class ExitCodeHandler {
|
||||
static int process_count_;
|
||||
static bool running_;
|
||||
static Monitor* monitor_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ExitCodeHandler);
|
||||
};
|
||||
|
||||
|
||||
@@ -266,7 +272,8 @@ class ProcessStarter {
|
||||
exec_control_[0] = -1;
|
||||
exec_control_[1] = -1;
|
||||
|
||||
program_arguments_ = new char*[arguments_length + 2];
|
||||
program_arguments_ = reinterpret_cast<char**>(Dart_ScopeAllocate(
|
||||
(arguments_length + 2) * sizeof(*program_arguments_)));
|
||||
program_arguments_[0] = const_cast<char*>(path_);
|
||||
for (int i = 0; i < arguments_length; i++) {
|
||||
program_arguments_[i + 1] = arguments[i];
|
||||
@@ -275,7 +282,8 @@ class ProcessStarter {
|
||||
|
||||
program_environment_ = NULL;
|
||||
if (environment != NULL) {
|
||||
program_environment_ = new char*[environment_length + 1];
|
||||
program_environment_ = reinterpret_cast<char**>(Dart_ScopeAllocate(
|
||||
(environment_length + 1) * sizeof(*program_environment_)));
|
||||
for (int i = 0; i < environment_length; i++) {
|
||||
program_environment_[i] = environment[i];
|
||||
}
|
||||
@@ -284,12 +292,6 @@ class ProcessStarter {
|
||||
}
|
||||
|
||||
|
||||
~ProcessStarter() {
|
||||
delete[] program_arguments_;
|
||||
delete[] program_environment_;
|
||||
}
|
||||
|
||||
|
||||
int Start() {
|
||||
// Create pipes required.
|
||||
int err = CreatePipes();
|
||||
@@ -509,8 +511,8 @@ class ProcessStarter {
|
||||
SetupDetachedWithStdio();
|
||||
}
|
||||
|
||||
if (working_directory_ != NULL &&
|
||||
TEMP_FAILURE_RETRY(chdir(working_directory_)) == -1) {
|
||||
if ((working_directory_ != NULL) &&
|
||||
(TEMP_FAILURE_RETRY(chdir(working_directory_)) == -1)) {
|
||||
ReportChildError();
|
||||
}
|
||||
|
||||
@@ -554,9 +556,8 @@ class ProcessStarter {
|
||||
// Read exec result from child. If no data is returned the exec was
|
||||
// successful and the exec call closed the pipe. Otherwise the errno
|
||||
// is written to the pipe.
|
||||
bytes_read =
|
||||
FDUtils::ReadFromBlocking(
|
||||
exec_control_[0], &child_errno, sizeof(child_errno));
|
||||
bytes_read = FDUtils::ReadFromBlocking(
|
||||
exec_control_[0], &child_errno, sizeof(child_errno));
|
||||
if (bytes_read == sizeof(child_errno)) {
|
||||
ReadChildError();
|
||||
return child_errno;
|
||||
@@ -575,8 +576,7 @@ class ProcessStarter {
|
||||
// is written to the pipe as well.
|
||||
int result[2];
|
||||
bytes_read =
|
||||
FDUtils::ReadFromBlocking(
|
||||
exec_control_[0], result, sizeof(result));
|
||||
FDUtils::ReadFromBlocking(exec_control_[0], result, sizeof(result));
|
||||
if (bytes_read == sizeof(int)) {
|
||||
*pid = result[0];
|
||||
} else if (bytes_read == 2 * sizeof(int)) {
|
||||
@@ -596,7 +596,9 @@ class ProcessStarter {
|
||||
|
||||
// Close all open file descriptors except for exec_control_[1].
|
||||
int max_fds = sysconf(_SC_OPEN_MAX);
|
||||
if (max_fds == -1) max_fds = _POSIX_OPEN_MAX;
|
||||
if (max_fds == -1) {
|
||||
max_fds = _POSIX_OPEN_MAX;
|
||||
}
|
||||
for (int fd = 0; fd < max_fds; fd++) {
|
||||
if (fd != exec_control_[1]) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
@@ -625,12 +627,14 @@ class ProcessStarter {
|
||||
// exec_control_[1], write_out_[0], read_in_[1] and
|
||||
// read_err_[1].
|
||||
int max_fds = sysconf(_SC_OPEN_MAX);
|
||||
if (max_fds == -1) max_fds = _POSIX_OPEN_MAX;
|
||||
if (max_fds == -1) {
|
||||
max_fds = _POSIX_OPEN_MAX;
|
||||
}
|
||||
for (int fd = 0; fd < max_fds; fd++) {
|
||||
if (fd != exec_control_[1] &&
|
||||
fd != write_out_[0] &&
|
||||
fd != read_in_[1] &&
|
||||
fd != read_err_[1]) {
|
||||
if ((fd != exec_control_[1]) &&
|
||||
(fd != write_out_[0]) &&
|
||||
(fd != read_in_[1]) &&
|
||||
(fd != read_err_[1])) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
}
|
||||
}
|
||||
@@ -680,9 +684,8 @@ class ProcessStarter {
|
||||
const int kBufferSize = 1024;
|
||||
char os_error_message[kBufferSize];
|
||||
Utils::StrError(errno, os_error_message, kBufferSize);
|
||||
int bytes_written =
|
||||
FDUtils::WriteToBlocking(
|
||||
exec_control_[1], &child_errno, sizeof(child_errno));
|
||||
int bytes_written = FDUtils::WriteToBlocking(
|
||||
exec_control_[1], &child_errno, sizeof(child_errno));
|
||||
if (bytes_written == sizeof(child_errno)) {
|
||||
FDUtils::WriteToBlocking(
|
||||
exec_control_[1], os_error_message, strlen(os_error_message) + 1);
|
||||
@@ -751,6 +754,9 @@ class ProcessStarter {
|
||||
intptr_t* id_;
|
||||
intptr_t* exit_event_;
|
||||
char** os_error_message_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessStarter);
|
||||
};
|
||||
|
||||
|
||||
@@ -786,10 +792,14 @@ int Process::Start(const char* path,
|
||||
|
||||
class BufferList: public BufferListBase {
|
||||
public:
|
||||
BufferList() {}
|
||||
|
||||
bool Read(int fd, intptr_t available) {
|
||||
// Read all available bytes.
|
||||
while (available > 0) {
|
||||
if (free_size_ == 0) Allocate();
|
||||
if (free_size_ == 0) {
|
||||
Allocate();
|
||||
}
|
||||
ASSERT(free_size_ > 0);
|
||||
ASSERT(free_size_ <= kBufferSize);
|
||||
size_t block_size = dart::Utils::Minimum(free_size_, available);
|
||||
@@ -797,13 +807,18 @@ class BufferList: public BufferListBase {
|
||||
fd,
|
||||
reinterpret_cast<void*>(FreeSpaceAddress()),
|
||||
block_size));
|
||||
if (bytes < 0) return false;
|
||||
if (bytes < 0) {
|
||||
return false;
|
||||
}
|
||||
data_size_ += bytes;
|
||||
free_size_ -= bytes;
|
||||
available -= bytes;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(BufferList);
|
||||
};
|
||||
|
||||
|
||||
@@ -856,7 +871,7 @@ bool Process::Wait(intptr_t pid,
|
||||
int current_alive = alive;
|
||||
for (int i = 0; i < current_alive; i++) {
|
||||
intptr_t avail;
|
||||
if (fds[i].revents & POLLIN) {
|
||||
if ((fds[i].revents & POLLIN) != 0) {
|
||||
avail = FDUtils::AvailableBytes(fds[i].fd);
|
||||
// On Mac OS POLLIN can be set with zero available
|
||||
// bytes. POLLHUP is most likely also set in this case.
|
||||
@@ -882,8 +897,8 @@ bool Process::Wait(intptr_t pid,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fds[i].revents & POLLHUP ||
|
||||
((fds[i].revents & POLLIN) && avail == 0)) {
|
||||
if (((fds[i].revents & POLLHUP) != 0) ||
|
||||
(((fds[i].revents & POLLIN) != 0) && (avail == 0))) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fds[i].fd));
|
||||
alive--;
|
||||
if (i < alive) {
|
||||
@@ -900,7 +915,9 @@ bool Process::Wait(intptr_t pid,
|
||||
// Calculate the exit code.
|
||||
intptr_t exit_code = exit_code_data.ints[0];
|
||||
intptr_t negative = exit_code_data.ints[1];
|
||||
if (negative) exit_code = -exit_code;
|
||||
if (negative != 0) {
|
||||
exit_code = -exit_code;
|
||||
}
|
||||
result->set_exit_code(exit_code);
|
||||
|
||||
return true;
|
||||
@@ -992,7 +1009,9 @@ static void SignalHandler(int signal) {
|
||||
|
||||
intptr_t Process::SetSignalHandler(intptr_t signal) {
|
||||
signal = SignalMap(signal);
|
||||
if (signal == -1) return -1;
|
||||
if (signal == -1) {
|
||||
return -1;
|
||||
}
|
||||
bool found = false;
|
||||
for (int i = 0; i < kSignalsCount; i++) {
|
||||
if (kSignals[i] == signal) {
|
||||
@@ -1000,7 +1019,9 @@ intptr_t Process::SetSignalHandler(intptr_t signal) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) return -1;
|
||||
if (!found) {
|
||||
return -1;
|
||||
}
|
||||
int fds[2];
|
||||
if (NO_RETRY_EXPECTED(pipe(fds)) != 0) {
|
||||
return -1;
|
||||
@@ -1045,7 +1066,9 @@ intptr_t Process::SetSignalHandler(intptr_t signal) {
|
||||
|
||||
void Process::ClearSignalHandler(intptr_t signal) {
|
||||
signal = SignalMap(signal);
|
||||
if (signal == -1) return;
|
||||
if (signal == -1) {
|
||||
return;
|
||||
}
|
||||
ThreadSignalBlocker blocker(kSignalsCount, kSignals);
|
||||
MutexLocker lock(signal_mutex);
|
||||
SignalInfo* handler = signal_handlers;
|
||||
@@ -1054,7 +1077,9 @@ void Process::ClearSignalHandler(intptr_t signal) {
|
||||
bool remove = false;
|
||||
if (handler->signal() == signal) {
|
||||
if (handler->port() == Dart_GetMainPortId()) {
|
||||
if (signal_handlers == handler) signal_handlers = handler->next();
|
||||
if (signal_handlers == handler) {
|
||||
signal_handlers = handler->next();
|
||||
}
|
||||
handler->Unlink();
|
||||
remove = true;
|
||||
} else {
|
||||
@@ -1062,7 +1087,9 @@ void Process::ClearSignalHandler(intptr_t signal) {
|
||||
}
|
||||
}
|
||||
SignalInfo* next = handler->next();
|
||||
if (remove) delete handler;
|
||||
if (remove) {
|
||||
delete handler;
|
||||
}
|
||||
handler = next;
|
||||
}
|
||||
if (unlisten) {
|
||||
|
||||
+86
-49
@@ -5,11 +5,12 @@
|
||||
#include "platform/globals.h"
|
||||
#if defined(TARGET_OS_WINDOWS)
|
||||
|
||||
#include "bin/process.h"
|
||||
|
||||
#include <process.h> // NOLINT
|
||||
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/process.h"
|
||||
#include "bin/eventhandler.h"
|
||||
#include "bin/lockers.h"
|
||||
#include "bin/log.h"
|
||||
@@ -18,7 +19,6 @@
|
||||
#include "bin/utils.h"
|
||||
#include "bin/utils_win.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -72,6 +72,8 @@ class ProcessInfo {
|
||||
HANDLE exit_pipe_;
|
||||
// Link to next ProcessInfo object in the singly-linked list.
|
||||
ProcessInfo* next_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProcessInfo);
|
||||
};
|
||||
|
||||
|
||||
@@ -143,7 +145,9 @@ class ProcessInfoList {
|
||||
// Callback called when an exit code is available from one of the
|
||||
// processes in the list.
|
||||
static void CALLBACK ExitCodeCallback(PVOID data, BOOLEAN timed_out) {
|
||||
if (timed_out) return;
|
||||
if (timed_out) {
|
||||
return;
|
||||
}
|
||||
DWORD pid = reinterpret_cast<DWORD>(data);
|
||||
HANDLE handle;
|
||||
HANDLE wait_handle;
|
||||
@@ -154,13 +158,12 @@ class ProcessInfoList {
|
||||
}
|
||||
// Unregister the event in a non-blocking way.
|
||||
BOOL ok = UnregisterWait(wait_handle);
|
||||
if (!ok && GetLastError() != ERROR_IO_PENDING) {
|
||||
if (!ok && (GetLastError() != ERROR_IO_PENDING)) {
|
||||
FATAL("Failed unregistering wait operation");
|
||||
}
|
||||
// Get and report the exit code to Dart.
|
||||
int exit_code;
|
||||
ok = GetExitCodeProcess(handle,
|
||||
reinterpret_cast<DWORD*>(&exit_code));
|
||||
ok = GetExitCodeProcess(handle, reinterpret_cast<DWORD*>(&exit_code));
|
||||
if (!ok) {
|
||||
FATAL1("GetExitCodeProcess failed %d\n", GetLastError());
|
||||
}
|
||||
@@ -176,9 +179,9 @@ class ProcessInfoList {
|
||||
// pipe has been closed. It is therefore not a problem that
|
||||
// WriteFile fails with a closed pipe error
|
||||
// (ERROR_NO_DATA). Other errors should not happen.
|
||||
if (ok && written != sizeof(message)) {
|
||||
if (ok && (written != sizeof(message))) {
|
||||
FATAL("Failed to write entire process exit message");
|
||||
} else if (!ok && GetLastError() != ERROR_NO_DATA) {
|
||||
} else if (!ok && (GetLastError() != ERROR_NO_DATA)) {
|
||||
FATAL1("Failed to write exit code: %d", GetLastError());
|
||||
}
|
||||
// Remove the process from the list of active processes.
|
||||
@@ -191,6 +194,9 @@ class ProcessInfoList {
|
||||
// Mutex protecting all accesses to the linked list of active
|
||||
// processes.
|
||||
static Mutex* mutex_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessInfoList);
|
||||
};
|
||||
|
||||
|
||||
@@ -249,7 +255,7 @@ static bool CreateProcessPipe(HANDLE handles[2],
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
ASSERT(type == kInheritWrite || type == kInheritNone);
|
||||
ASSERT((type == kInheritWrite) || (type == kInheritNone));
|
||||
handles[kReadHandle] =
|
||||
CreateNamedPipeW(pipe_name,
|
||||
PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
|
||||
@@ -357,19 +363,19 @@ static bool EnsureInitialized() {
|
||||
HMODULE kernel32_module = GetModuleHandleW(L"kernel32.dll");
|
||||
if (!load_attempted) {
|
||||
MutexLocker locker(mutex);
|
||||
if (load_attempted) return delete_proc_thread_attr_list != NULL;
|
||||
if (load_attempted) {
|
||||
return (delete_proc_thread_attr_list != NULL);
|
||||
}
|
||||
init_proc_thread_attr_list = reinterpret_cast<InitProcThreadAttrListFn>(
|
||||
GetProcAddress(kernel32_module, "InitializeProcThreadAttributeList"));
|
||||
update_proc_thread_attr =
|
||||
reinterpret_cast<UpdateProcThreadAttrFn>(
|
||||
GetProcAddress(kernel32_module, "UpdateProcThreadAttribute"));
|
||||
update_proc_thread_attr = reinterpret_cast<UpdateProcThreadAttrFn>(
|
||||
GetProcAddress(kernel32_module, "UpdateProcThreadAttribute"));
|
||||
delete_proc_thread_attr_list = reinterpret_cast<DeleteProcThreadAttrListFn>(
|
||||
reinterpret_cast<DeleteProcThreadAttrListFn>(
|
||||
GetProcAddress(kernel32_module, "DeleteProcThreadAttributeList")));
|
||||
GetProcAddress(kernel32_module, "DeleteProcThreadAttributeList"));
|
||||
load_attempted = true;
|
||||
return delete_proc_thread_attr_list != NULL;
|
||||
return (delete_proc_thread_attr_list != NULL);
|
||||
}
|
||||
return delete_proc_thread_attr_list != NULL;
|
||||
return (delete_proc_thread_attr_list != NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -378,7 +384,7 @@ template<int Count>
|
||||
static int GenerateNames(wchar_t pipe_names[Count][kMaxPipeNameSize]) {
|
||||
UUID uuid;
|
||||
RPC_STATUS status = UuidCreateSequential(&uuid);
|
||||
if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) {
|
||||
if ((status != RPC_S_OK) && (status != RPC_S_UUID_LOCAL_ONLY)) {
|
||||
return status;
|
||||
}
|
||||
RPC_WSTR uuid_string;
|
||||
@@ -451,7 +457,8 @@ class ProcessStarter {
|
||||
command_line_length += arguments_length + 1;
|
||||
|
||||
// Put together command-line string.
|
||||
command_line_ = new wchar_t[command_line_length];
|
||||
command_line_ = reinterpret_cast<wchar_t*>(Dart_ScopeAllocate(
|
||||
command_line_length * sizeof(*command_line_)));
|
||||
int len = 0;
|
||||
int remaining = command_line_length;
|
||||
int written =
|
||||
@@ -460,9 +467,8 @@ class ProcessStarter {
|
||||
remaining -= written;
|
||||
ASSERT(remaining >= 0);
|
||||
for (int i = 0; i < arguments_length; i++) {
|
||||
written =
|
||||
_snwprintf(
|
||||
command_line_ + len, remaining, L" %s", system_arguments[i]);
|
||||
written = _snwprintf(
|
||||
command_line_ + len, remaining, L" %s", system_arguments[i]);
|
||||
len += written;
|
||||
remaining -= written;
|
||||
ASSERT(remaining >= 0);
|
||||
@@ -485,7 +491,8 @@ class ProcessStarter {
|
||||
for (intptr_t i = 0; i < environment_length; i++) {
|
||||
block_size += wcslen(system_environment[i]) + 1;
|
||||
}
|
||||
environment_block_ = new wchar_t[block_size];
|
||||
environment_block_ = reinterpret_cast<wchar_t*>(Dart_ScopeAllocate(
|
||||
block_size * sizeof(*environment_block_)));
|
||||
intptr_t block_index = 0;
|
||||
for (intptr_t i = 0; i < environment_length; i++) {
|
||||
intptr_t len = wcslen(system_environment[i]);
|
||||
@@ -513,12 +520,8 @@ class ProcessStarter {
|
||||
|
||||
|
||||
~ProcessStarter() {
|
||||
// Deallocate command-line and environment block strings.
|
||||
delete[] command_line_;
|
||||
delete[] environment_block_;
|
||||
if (attribute_list_ != NULL) {
|
||||
delete_proc_thread_attr_list(attribute_list_);
|
||||
free(attribute_list_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -526,7 +529,9 @@ class ProcessStarter {
|
||||
int Start() {
|
||||
// Create pipes required.
|
||||
int err = CreatePipes();
|
||||
if (err != 0) return err;
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// Setup info structures.
|
||||
STARTUPINFOEXW startup_info;
|
||||
@@ -545,11 +550,11 @@ class ProcessStarter {
|
||||
// The call to determine the size of an attribute list always fails with
|
||||
// ERROR_INSUFFICIENT_BUFFER and that error should be ignored.
|
||||
if (!init_proc_thread_attr_list(NULL, 1, 0, &size) &&
|
||||
GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||
(GetLastError() != ERROR_INSUFFICIENT_BUFFER)) {
|
||||
return CleanupAndReturnError();
|
||||
}
|
||||
attribute_list_ =
|
||||
reinterpret_cast<LPPROC_THREAD_ATTRIBUTE_LIST>(malloc(size));
|
||||
attribute_list_ = reinterpret_cast<LPPROC_THREAD_ATTRIBUTE_LIST>(
|
||||
Dart_ScopeAllocate(size));
|
||||
ZeroMemory(attribute_list_, size);
|
||||
if (!init_proc_thread_attr_list(attribute_list_, 1, 0, &size)) {
|
||||
return CleanupAndReturnError();
|
||||
@@ -650,10 +655,19 @@ class ProcessStarter {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Open NUL for stdin, stdout and stderr.
|
||||
if ((stdin_handles_[kReadHandle] = OpenNul()) == INVALID_HANDLE_VALUE ||
|
||||
(stdout_handles_[kWriteHandle] = OpenNul()) == INVALID_HANDLE_VALUE ||
|
||||
(stderr_handles_[kWriteHandle] = OpenNul()) == INVALID_HANDLE_VALUE) {
|
||||
// Open NUL for stdin, stdout, and stderr.
|
||||
stdin_handles_[kReadHandle] = OpenNul();
|
||||
if (stdin_handles_[kReadHandle] == INVALID_HANDLE_VALUE) {
|
||||
return CleanupAndReturnError();
|
||||
}
|
||||
|
||||
stdout_handles_[kWriteHandle] = OpenNul();
|
||||
if (stdout_handles_[kWriteHandle] == INVALID_HANDLE_VALUE) {
|
||||
return CleanupAndReturnError();
|
||||
}
|
||||
|
||||
stderr_handles_[kWriteHandle] = OpenNul();
|
||||
if (stderr_handles_[kWriteHandle] == INVALID_HANDLE_VALUE) {
|
||||
return CleanupAndReturnError();
|
||||
}
|
||||
}
|
||||
@@ -688,6 +702,10 @@ class ProcessStarter {
|
||||
intptr_t* id_;
|
||||
intptr_t* exit_handler_;
|
||||
char** os_error_message_;
|
||||
|
||||
private:
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ProcessStarter);
|
||||
};
|
||||
|
||||
|
||||
@@ -738,7 +756,9 @@ class BufferList: public BufferListBase {
|
||||
// The access to the read buffer for overlapped read.
|
||||
void GetReadBuffer(uint8_t** buffer, intptr_t* size) {
|
||||
ASSERT(!read_pending_);
|
||||
if (free_size_ == 0) Allocate();
|
||||
if (free_size_ == 0) {
|
||||
Allocate();
|
||||
}
|
||||
ASSERT(free_size_ > 0);
|
||||
ASSERT(free_size_ <= kBufferSize);
|
||||
*buffer = FreeSpaceAddress();
|
||||
@@ -763,11 +783,15 @@ class BufferList: public BufferListBase {
|
||||
|
||||
private:
|
||||
bool read_pending_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BufferList);
|
||||
};
|
||||
|
||||
|
||||
class OverlappedHandle {
|
||||
public:
|
||||
OverlappedHandle() {}
|
||||
|
||||
void Init(HANDLE handle, HANDLE event) {
|
||||
handle_ = handle;
|
||||
event_ = event;
|
||||
@@ -775,7 +799,7 @@ class OverlappedHandle {
|
||||
}
|
||||
|
||||
bool HasEvent(HANDLE event) {
|
||||
return event_ == event;
|
||||
return (event_ == event);
|
||||
}
|
||||
|
||||
bool Read() {
|
||||
@@ -793,7 +817,9 @@ class OverlappedHandle {
|
||||
intptr_t buffer_size;
|
||||
buffer_.GetReadBuffer(&buffer, &buffer_size);
|
||||
BOOL ok = ReadFile(handle_, buffer, buffer_size, NULL, &overlapped_);
|
||||
if (!ok) return GetLastError() == ERROR_IO_PENDING;
|
||||
if (!ok) {
|
||||
return (GetLastError() == ERROR_IO_PENDING);
|
||||
}
|
||||
buffer_.DataIsRead(overlapped_.InternalHigh);
|
||||
}
|
||||
}
|
||||
@@ -833,6 +859,7 @@ class OverlappedHandle {
|
||||
BufferList buffer_;
|
||||
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_COPY_AND_ASSIGN(OverlappedHandle);
|
||||
};
|
||||
|
||||
|
||||
@@ -905,12 +932,14 @@ bool Process::Wait(intptr_t pid,
|
||||
|
||||
// Calculate the exit code.
|
||||
ASSERT(oh[2].GetDataSize() == 8);
|
||||
uint32_t exit[2];
|
||||
memmove(&exit, oh[2].GetFirstDataBuffer(), sizeof(exit));
|
||||
uint32_t exit_codes[2];
|
||||
memmove(&exit_codes, oh[2].GetFirstDataBuffer(), sizeof(exit_codes));
|
||||
oh[2].FreeDataBuffer();
|
||||
intptr_t exit_code = exit[0];
|
||||
intptr_t negative = exit[1];
|
||||
if (negative) exit_code = -exit_code;
|
||||
intptr_t exit_code = exit_codes[0];
|
||||
intptr_t negative = exit_codes[1];
|
||||
if (negative != 0) {
|
||||
exit_code = -exit_code;
|
||||
}
|
||||
result->set_exit_code(exit_code);
|
||||
return true;
|
||||
}
|
||||
@@ -931,7 +960,9 @@ bool Process::Kill(intptr_t id, int signal) {
|
||||
if (!success) {
|
||||
process_handle = OpenProcess(PROCESS_TERMINATE, FALSE, id);
|
||||
// The process is already dead.
|
||||
if (process_handle == INVALID_HANDLE_VALUE) return false;
|
||||
if (process_handle == INVALID_HANDLE_VALUE) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
BOOL result = TerminateProcess(process_handle, -1);
|
||||
return result ? true : false;
|
||||
@@ -985,12 +1016,16 @@ intptr_t GetWinSignal(intptr_t signal) {
|
||||
|
||||
intptr_t Process::SetSignalHandler(intptr_t signal) {
|
||||
signal = GetWinSignal(signal);
|
||||
if (signal == -1) return -1;
|
||||
if (signal == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Generate a unique pipe name for the named pipe.
|
||||
wchar_t pipe_name[kMaxPipeNameSize];
|
||||
int status = GenerateNames<1>(&pipe_name);
|
||||
if (status != 0) return status;
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
|
||||
HANDLE fds[2];
|
||||
if (!CreateProcessPipe(fds, pipe_name, kInheritNone)) {
|
||||
@@ -1019,12 +1054,14 @@ intptr_t Process::SetSignalHandler(intptr_t signal) {
|
||||
|
||||
void Process::ClearSignalHandler(intptr_t signal) {
|
||||
signal = GetWinSignal(signal);
|
||||
if (signal == -1) return;
|
||||
if (signal == -1) {
|
||||
return;
|
||||
}
|
||||
MutexLocker lock(signal_mutex);
|
||||
SignalInfo* handler = signal_handlers;
|
||||
while (handler != NULL) {
|
||||
if (handler->port() == Dart_GetMainPortId() &&
|
||||
handler->signal() == signal) {
|
||||
if ((handler->port() == Dart_GetMainPortId()) &&
|
||||
(handler->signal() == signal)) {
|
||||
handler->Unlink();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "bin/file.h"
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/file.h"
|
||||
#include "bin/platform.h"
|
||||
|
||||
#include "vm/benchmark_test.h"
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
@@ -83,8 +83,7 @@ static void FetchErrorString(char* buffer, int length) {
|
||||
/* Handle an error reported from the BoringSSL library. */
|
||||
static void ThrowIOException(int status,
|
||||
const char* exception_type,
|
||||
const char* message,
|
||||
bool free_message = false) {
|
||||
const char* message) {
|
||||
char error_string[SSL_ERROR_MESSAGE_BUFFER_SIZE];
|
||||
FetchErrorString(error_string, SSL_ERROR_MESSAGE_BUFFER_SIZE);
|
||||
OSError os_error_struct(status, error_string, OSError::kBoringSSL);
|
||||
@@ -92,9 +91,6 @@ static void ThrowIOException(int status,
|
||||
Dart_Handle exception =
|
||||
DartUtils::NewDartIOException(exception_type, message, os_error);
|
||||
ASSERT(!Dart_IsError(exception));
|
||||
if (free_message) {
|
||||
free(const_cast<char*>(message));
|
||||
}
|
||||
Dart_ThrowException(exception);
|
||||
UNREACHABLE();
|
||||
}
|
||||
@@ -677,7 +673,7 @@ static int SetTrustedCertificatesBytesPKCS12(SSL_CTX* context,
|
||||
const char* password) {
|
||||
ScopedPKCS12 p12(d2i_PKCS12_bio(bio, NULL));
|
||||
if (p12.get() == NULL) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
EVP_PKEY* key = NULL;
|
||||
@@ -787,7 +783,7 @@ static int UseChainBytesPKCS12(SSL_CTX* context,
|
||||
const char* password) {
|
||||
ScopedPKCS12 p12(d2i_PKCS12_bio(bio, NULL));
|
||||
if (p12.get() == NULL) {
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
EVP_PKEY* key = NULL;
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
#error "secure_socket.h can only be included on builds with SSL enabled"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "bin/builtin.h"
|
||||
@@ -102,7 +102,6 @@ class SSLFilter {
|
||||
SSL* ssl_;
|
||||
BIO* socket_side_;
|
||||
|
||||
|
||||
private:
|
||||
static bool library_initialized_;
|
||||
static Mutex* mutex_; // To protect library initialization.
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "include/dart_api.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ typedef unsigned __int8 uint8_t;
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ typedef unsigned __int8 uint8_t;
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
+41
-22
@@ -2,12 +2,12 @@
|
||||
// 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.
|
||||
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/io_buffer.h"
|
||||
#include "bin/isolate_data.h"
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/lockers.h"
|
||||
#include "bin/socket.h"
|
||||
#include "bin/thread.h"
|
||||
#include "bin/lockers.h"
|
||||
#include "bin/utils.h"
|
||||
|
||||
#include "platform/globals.h"
|
||||
@@ -60,7 +60,6 @@ Dart_Handle ListeningSocketRegistry::CreateBindListen(Dart_Handle socket_object,
|
||||
// There is already a socket listening on this port. We need to ensure
|
||||
// that if there is one also listening on the same address, it was created
|
||||
// with `shared = true`, ...
|
||||
|
||||
OSSocket *os_socket = it->second;
|
||||
OSSocket *os_socket_same_addr = findOSSocketWithAddress(os_socket, addr);
|
||||
|
||||
@@ -146,7 +145,7 @@ bool ListeningSocketRegistry::CloseSafe(intptr_t socketfd) {
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
if (prev == NULL && current->next == NULL) {
|
||||
if ((prev == NULL) && (current->next == NULL)) {
|
||||
// Remove last element from the list.
|
||||
sockets_by_port_.erase(os_socket->port);
|
||||
} else if (prev == NULL) {
|
||||
@@ -271,7 +270,9 @@ void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) {
|
||||
}
|
||||
uint8_t* buffer = NULL;
|
||||
Dart_Handle result = IOBuffer::Allocate(length, &buffer);
|
||||
if (Dart_IsError(result)) Dart_PropagateError(result);
|
||||
if (Dart_IsError(result)) {
|
||||
Dart_PropagateError(result);
|
||||
}
|
||||
ASSERT(buffer != NULL);
|
||||
intptr_t bytes_read = Socket::Read(socket, buffer, length);
|
||||
if (bytes_read == length) {
|
||||
@@ -279,7 +280,9 @@ void FUNCTION_NAME(Socket_Read)(Dart_NativeArguments args) {
|
||||
} else if (bytes_read > 0) {
|
||||
uint8_t* new_buffer = NULL;
|
||||
Dart_Handle new_result = IOBuffer::Allocate(bytes_read, &new_buffer);
|
||||
if (Dart_IsError(new_result)) Dart_PropagateError(new_result);
|
||||
if (Dart_IsError(new_result)) {
|
||||
Dart_PropagateError(new_result);
|
||||
}
|
||||
ASSERT(new_buffer != NULL);
|
||||
memmove(new_buffer, buffer, bytes_read);
|
||||
Dart_SetReturnValue(args, new_result);
|
||||
@@ -326,7 +329,9 @@ void FUNCTION_NAME(Socket_RecvFrom)(Dart_NativeArguments args) {
|
||||
ASSERT(bytes_read > 0);
|
||||
uint8_t* data_buffer = NULL;
|
||||
Dart_Handle data = IOBuffer::Allocate(bytes_read, &data_buffer);
|
||||
if (Dart_IsError(data)) Dart_PropagateError(data);
|
||||
if (Dart_IsError(data)) {
|
||||
Dart_PropagateError(data);
|
||||
}
|
||||
ASSERT(data_buffer != NULL);
|
||||
memmove(data_buffer, isolate_data->udp_receive_buffer, bytes_read);
|
||||
|
||||
@@ -347,14 +352,20 @@ void FUNCTION_NAME(Socket_RecvFrom)(Dart_NativeArguments args) {
|
||||
Dart_Handle dart_args[kNumArgs];
|
||||
dart_args[0] = data;
|
||||
dart_args[1] = Dart_NewStringFromCString(numeric_address);
|
||||
if (Dart_IsError(dart_args[1])) Dart_PropagateError(dart_args[1]);
|
||||
if (Dart_IsError(dart_args[1])) {
|
||||
Dart_PropagateError(dart_args[1]);
|
||||
}
|
||||
dart_args[2] = SocketAddress::ToTypedData(addr);
|
||||
dart_args[3] = Dart_NewInteger(port);
|
||||
if (Dart_IsError(dart_args[3])) Dart_PropagateError(dart_args[3]);
|
||||
if (Dart_IsError(dart_args[3])) {
|
||||
Dart_PropagateError(dart_args[3]);
|
||||
}
|
||||
// TODO(sgjesse): Cache the _makeDatagram function somewhere.
|
||||
Dart_Handle io_lib =
|
||||
Dart_LookupLibrary(DartUtils::NewString("dart:io"));
|
||||
if (Dart_IsError(io_lib)) Dart_PropagateError(io_lib);
|
||||
if (Dart_IsError(io_lib)) {
|
||||
Dart_PropagateError(io_lib);
|
||||
}
|
||||
Dart_Handle result =
|
||||
Dart_Invoke(io_lib,
|
||||
DartUtils::NewString("_makeDatagram"),
|
||||
@@ -376,7 +387,9 @@ void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) {
|
||||
DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3));
|
||||
bool short_write = false;
|
||||
if (short_socket_writes) {
|
||||
if (length > 1) short_write = true;
|
||||
if (length > 1) {
|
||||
short_write = true;
|
||||
}
|
||||
length = (length + 1) / 2;
|
||||
}
|
||||
Dart_TypedData_Type type;
|
||||
@@ -384,7 +397,9 @@ void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) {
|
||||
intptr_t len;
|
||||
Dart_Handle result = Dart_TypedDataAcquireData(
|
||||
buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len);
|
||||
if (Dart_IsError(result)) Dart_PropagateError(result);
|
||||
if (Dart_IsError(result)) {
|
||||
Dart_PropagateError(result);
|
||||
}
|
||||
ASSERT((offset + length) <= len);
|
||||
buffer += offset;
|
||||
intptr_t bytes_written = Socket::Write(socket, buffer, length);
|
||||
@@ -428,7 +443,9 @@ void FUNCTION_NAME(Socket_SendTo)(Dart_NativeArguments args) {
|
||||
intptr_t len;
|
||||
Dart_Handle result = Dart_TypedDataAcquireData(
|
||||
buffer_obj, &type, reinterpret_cast<void**>(&buffer), &len);
|
||||
if (Dart_IsError(result)) Dart_PropagateError(result);
|
||||
if (Dart_IsError(result)) {
|
||||
Dart_PropagateError(result);
|
||||
}
|
||||
ASSERT((offset + length) <= len);
|
||||
buffer += offset;
|
||||
intptr_t bytes_written = Socket::SendTo(socket, buffer, length, addr);
|
||||
@@ -518,15 +535,13 @@ void FUNCTION_NAME(Socket_GetStdioHandle)(Dart_NativeArguments args) {
|
||||
|
||||
|
||||
void FUNCTION_NAME(Socket_GetSocketId)(Dart_NativeArguments args) {
|
||||
intptr_t id =
|
||||
Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0));
|
||||
intptr_t id = Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0));
|
||||
Dart_SetReturnValue(args, Dart_NewInteger(id));
|
||||
}
|
||||
|
||||
|
||||
void FUNCTION_NAME(Socket_SetSocketId)(Dart_NativeArguments args) {
|
||||
intptr_t id =
|
||||
DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
|
||||
intptr_t id = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1));
|
||||
Socket::SetSocketIdNativeField(Dart_GetNativeArgument(args, 0), id);
|
||||
}
|
||||
|
||||
@@ -569,7 +584,7 @@ void FUNCTION_NAME(ServerSocket_Accept)(Dart_NativeArguments args) {
|
||||
|
||||
|
||||
CObject* Socket::LookupRequest(const CObjectArray& request) {
|
||||
if (request.Length() == 2 &&
|
||||
if ((request.Length() == 2) &&
|
||||
request[0]->IsString() &&
|
||||
request[1]->IsInt32()) {
|
||||
CObjectString host(request[0]);
|
||||
@@ -613,7 +628,7 @@ CObject* Socket::LookupRequest(const CObjectArray& request) {
|
||||
|
||||
|
||||
CObject* Socket::ReverseLookupRequest(const CObjectArray& request) {
|
||||
if (request.Length() == 1 &&
|
||||
if ((request.Length() == 1) &&
|
||||
request[0]->IsTypedData()) {
|
||||
CObjectUint8Array addr_object(request[0]);
|
||||
RawAddr addr;
|
||||
@@ -648,7 +663,7 @@ CObject* Socket::ReverseLookupRequest(const CObjectArray& request) {
|
||||
|
||||
|
||||
CObject* Socket::ListInterfacesRequest(const CObjectArray& request) {
|
||||
if (request.Length() == 1 &&
|
||||
if ((request.Length() == 1) &&
|
||||
request[0]->IsInt32()) {
|
||||
CObjectInt32 type(request[0]);
|
||||
CObject* result = NULL;
|
||||
@@ -841,7 +856,9 @@ void FUNCTION_NAME(Socket_LeaveMulticast)(Dart_NativeArguments args) {
|
||||
void Socket::SetSocketIdNativeField(Dart_Handle socket, intptr_t id) {
|
||||
Dart_Handle err =
|
||||
Dart_SetNativeInstanceField(socket, kSocketIdNativeField, id);
|
||||
if (Dart_IsError(err)) Dart_PropagateError(err);
|
||||
if (Dart_IsError(err)) {
|
||||
Dart_PropagateError(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -849,7 +866,9 @@ intptr_t Socket::GetSocketIdNativeField(Dart_Handle socket_obj) {
|
||||
intptr_t socket = 0;
|
||||
Dart_Handle err =
|
||||
Dart_GetNativeInstanceField(socket_obj, kSocketIdNativeField, &socket);
|
||||
if (Dart_IsError(err)) Dart_PropagateError(err);
|
||||
if (Dart_IsError(err)) {
|
||||
Dart_PropagateError(err);
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
|
||||
|
||||
+38
-20
@@ -26,7 +26,6 @@
|
||||
#include "bin/thread.h"
|
||||
#include "bin/utils.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -59,7 +58,9 @@ class SocketAddress {
|
||||
~SocketAddress() {}
|
||||
|
||||
int GetType() {
|
||||
if (addr_.ss.ss_family == AF_INET6) return TYPE_IPV6;
|
||||
if (addr_.ss.ss_family == AF_INET6) {
|
||||
return TYPE_IPV6;
|
||||
}
|
||||
return TYPE_IPV4;
|
||||
}
|
||||
|
||||
@@ -67,23 +68,27 @@ class SocketAddress {
|
||||
const RawAddr& addr() const { return addr_; }
|
||||
|
||||
static intptr_t GetAddrLength(const RawAddr& addr) {
|
||||
ASSERT(addr.ss.ss_family == AF_INET || addr.ss.ss_family == AF_INET6);
|
||||
return addr.ss.ss_family == AF_INET6 ?
|
||||
ASSERT((addr.ss.ss_family == AF_INET) || (addr.ss.ss_family == AF_INET6));
|
||||
return (addr.ss.ss_family == AF_INET6) ?
|
||||
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
|
||||
}
|
||||
|
||||
static intptr_t GetInAddrLength(const RawAddr& addr) {
|
||||
ASSERT(addr.ss.ss_family == AF_INET || addr.ss.ss_family == AF_INET6);
|
||||
return addr.ss.ss_family == AF_INET6 ?
|
||||
ASSERT((addr.ss.ss_family == AF_INET) || (addr.ss.ss_family == AF_INET6));
|
||||
return (addr.ss.ss_family == AF_INET6) ?
|
||||
sizeof(struct in6_addr) : sizeof(struct in_addr);
|
||||
}
|
||||
|
||||
static bool AreAddressesEqual(const RawAddr& a, const RawAddr& b) {
|
||||
if (a.ss.ss_family == AF_INET) {
|
||||
if (b.ss.ss_family != AF_INET) return false;
|
||||
if (b.ss.ss_family != AF_INET) {
|
||||
return false;
|
||||
}
|
||||
return memcmp(&a.in.sin_addr, &b.in.sin_addr, sizeof(a.in.sin_addr)) == 0;
|
||||
} else if (a.ss.ss_family == AF_INET6) {
|
||||
if (b.ss.ss_family != AF_INET6) return false;
|
||||
if (b.ss.ss_family != AF_INET6) {
|
||||
return false;
|
||||
}
|
||||
return memcmp(&a.in6.sin6_addr,
|
||||
&b.in6.sin6_addr,
|
||||
sizeof(a.in6.sin6_addr)) == 0;
|
||||
@@ -99,9 +104,11 @@ class SocketAddress {
|
||||
intptr_t len;
|
||||
Dart_Handle result = Dart_TypedDataAcquireData(
|
||||
obj, &data_type, reinterpret_cast<void**>(&data), &len);
|
||||
if (Dart_IsError(result)) Dart_PropagateError(result);
|
||||
if (data_type != Dart_TypedData_kUint8 ||
|
||||
(len != sizeof(in_addr) && len != sizeof(in6_addr))) {
|
||||
if (Dart_IsError(result)) {
|
||||
Dart_PropagateError(result);
|
||||
}
|
||||
if ((data_type != Dart_TypedData_kUint8) ||
|
||||
((len != sizeof(in_addr)) && (len != sizeof(in6_addr)))) {
|
||||
Dart_PropagateError(
|
||||
Dart_NewApiError("Unexpected type for socket address"));
|
||||
}
|
||||
@@ -118,9 +125,13 @@ class SocketAddress {
|
||||
}
|
||||
|
||||
static int16_t FromType(int type) {
|
||||
if (type == TYPE_ANY) return AF_UNSPEC;
|
||||
if (type == TYPE_IPV4) return AF_INET;
|
||||
ASSERT(type == TYPE_IPV6 && "Invalid type");
|
||||
if (type == TYPE_ANY) {
|
||||
return AF_UNSPEC;
|
||||
}
|
||||
if (type == TYPE_IPV4) {
|
||||
return AF_INET;
|
||||
}
|
||||
ASSERT((type == TYPE_IPV6) && "Invalid type");
|
||||
return AF_INET6;
|
||||
}
|
||||
|
||||
@@ -143,7 +154,9 @@ class SocketAddress {
|
||||
static Dart_Handle ToTypedData(const RawAddr& addr) {
|
||||
int len = GetInAddrLength(addr);
|
||||
Dart_Handle result = Dart_NewTypedData(Dart_TypedData_kUint8, len);
|
||||
if (Dart_IsError(result)) Dart_PropagateError(result);
|
||||
if (Dart_IsError(result)) {
|
||||
Dart_PropagateError(result);
|
||||
}
|
||||
Dart_Handle err;
|
||||
if (addr.addr.sa_family == AF_INET6) {
|
||||
err = Dart_ListSetAsBytes(
|
||||
@@ -153,7 +166,9 @@ class SocketAddress {
|
||||
err = Dart_ListSetAsBytes(
|
||||
result, 0, reinterpret_cast<const uint8_t*>(&addr.in.sin_addr), len);
|
||||
}
|
||||
if (Dart_IsError(err)) Dart_PropagateError(err);
|
||||
if (Dart_IsError(err)) {
|
||||
Dart_PropagateError(err);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -178,11 +193,12 @@ class SocketAddress {
|
||||
DISALLOW_COPY_AND_ASSIGN(SocketAddress);
|
||||
};
|
||||
|
||||
|
||||
class InterfaceSocketAddress {
|
||||
public:
|
||||
explicit InterfaceSocketAddress(struct sockaddr* sa,
|
||||
const char* interface_name,
|
||||
intptr_t interface_index)
|
||||
InterfaceSocketAddress(struct sockaddr* sa,
|
||||
const char* interface_name,
|
||||
intptr_t interface_index)
|
||||
: socket_address_(new SocketAddress(sa)),
|
||||
interface_name_(interface_name),
|
||||
interface_index_(interface_index) {}
|
||||
@@ -203,6 +219,7 @@ class InterfaceSocketAddress {
|
||||
DISALLOW_COPY_AND_ASSIGN(InterfaceSocketAddress);
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
class AddressList {
|
||||
public:
|
||||
@@ -228,6 +245,7 @@ class AddressList {
|
||||
DISALLOW_COPY_AND_ASSIGN(AddressList);
|
||||
};
|
||||
|
||||
|
||||
class Socket {
|
||||
public:
|
||||
enum SocketRequest {
|
||||
@@ -340,6 +358,7 @@ class ServerSocket {
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ServerSocket);
|
||||
};
|
||||
|
||||
|
||||
class ListeningSocketRegistry {
|
||||
private:
|
||||
struct OSSocket {
|
||||
@@ -416,7 +435,6 @@ class ListeningSocketRegistry {
|
||||
DISALLOW_COPY_AND_ASSIGN(ListeningSocketRegistry);
|
||||
};
|
||||
|
||||
|
||||
} // namespace bin
|
||||
} // namespace dart
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
#include "bin/socket_android.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <netinet/tcp.h> // NOLINT
|
||||
#include <stdio.h> // NOLINT
|
||||
#include <stdlib.h> // NOLINT
|
||||
#include <string.h> // NOLINT
|
||||
#include <sys/stat.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <netinet/tcp.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
#include "bin/file.h"
|
||||
@@ -36,16 +36,8 @@ SocketAddress::SocketAddress(struct sockaddr* sa) {
|
||||
|
||||
bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) {
|
||||
socklen_t salen = SocketAddress::GetAddrLength(addr);
|
||||
if (NO_RETRY_EXPECTED(getnameinfo(&addr.addr,
|
||||
salen,
|
||||
address,
|
||||
len,
|
||||
NULL,
|
||||
0,
|
||||
NI_NUMERICHOST)) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return (NO_RETRY_EXPECTED(getnameinfo(
|
||||
&addr.addr, salen, address, len, NULL, 0, NI_NUMERICHOST)) == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +61,7 @@ static intptr_t Create(const RawAddr& addr) {
|
||||
static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
|
||||
intptr_t result = TEMP_FAILURE_RETRY(
|
||||
connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr)));
|
||||
if (result == 0 || errno == EINPROGRESS) {
|
||||
if ((result == 0) || (errno == EINPROGRESS)) {
|
||||
return fd;
|
||||
}
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
@@ -98,7 +90,7 @@ intptr_t Socket::CreateBindConnect(const RawAddr& addr,
|
||||
|
||||
intptr_t result = TEMP_FAILURE_RETRY(
|
||||
bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr)));
|
||||
if (result != 0 && errno != EINPROGRESS) {
|
||||
if ((result != 0) && (errno != EINPROGRESS)) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
return -1;
|
||||
}
|
||||
@@ -116,7 +108,7 @@ intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
|
||||
ASSERT(fd >= 0);
|
||||
ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
|
||||
ASSERT(EAGAIN == EWOULDBLOCK);
|
||||
if (read_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((read_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the read would block we need to retry and therefore return 0
|
||||
// as the number of bytes written.
|
||||
read_bytes = 0;
|
||||
@@ -131,7 +123,7 @@ intptr_t Socket::RecvFrom(
|
||||
socklen_t addr_len = sizeof(addr->ss);
|
||||
ssize_t read_bytes = TEMP_FAILURE_RETRY(
|
||||
recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len));
|
||||
if (read_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((read_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the read would block we need to retry and therefore return 0
|
||||
// as the number of bytes written.
|
||||
read_bytes = 0;
|
||||
@@ -144,7 +136,7 @@ intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
|
||||
ASSERT(fd >= 0);
|
||||
ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes));
|
||||
ASSERT(EAGAIN == EWOULDBLOCK);
|
||||
if (written_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((written_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the would block we need to retry and therefore return 0 as
|
||||
// the number of bytes written.
|
||||
written_bytes = 0;
|
||||
@@ -160,7 +152,7 @@ intptr_t Socket::SendTo(
|
||||
sendto(fd, buffer, num_bytes, 0,
|
||||
&addr.addr, SocketAddress::GetAddrLength(addr)));
|
||||
ASSERT(EAGAIN == EWOULDBLOCK);
|
||||
if (written_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((written_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the would block we need to retry and therefore return 0 as
|
||||
// the number of bytes written.
|
||||
written_bytes = 0;
|
||||
@@ -207,10 +199,18 @@ void Socket::GetError(intptr_t fd, OSError* os_error) {
|
||||
int Socket::GetType(intptr_t fd) {
|
||||
struct stat buf;
|
||||
int result = fstat(fd, &buf);
|
||||
if (result == -1) return -1;
|
||||
if (S_ISCHR(buf.st_mode)) return File::kTerminal;
|
||||
if (S_ISFIFO(buf.st_mode)) return File::kPipe;
|
||||
if (S_ISREG(buf.st_mode)) return File::kFile;
|
||||
if (result == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (S_ISCHR(buf.st_mode)) {
|
||||
return File::kTerminal;
|
||||
}
|
||||
if (S_ISFIFO(buf.st_mode)) {
|
||||
return File::kPipe;
|
||||
}
|
||||
if (S_ISREG(buf.st_mode)) {
|
||||
return File::kFile;
|
||||
}
|
||||
return File::kOther;
|
||||
}
|
||||
|
||||
@@ -247,12 +247,14 @@ AddressList<SocketAddress>* Socket::LookupAddress(const char* host,
|
||||
}
|
||||
intptr_t count = 0;
|
||||
for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
|
||||
if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++;
|
||||
if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
intptr_t i = 0;
|
||||
AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count);
|
||||
for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
|
||||
if (c->ai_family == AF_INET || c->ai_family == AF_INET6) {
|
||||
if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
|
||||
addresses->SetAt(i, new SocketAddress(c->ai_addr));
|
||||
i++;
|
||||
}
|
||||
@@ -294,7 +296,7 @@ bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) {
|
||||
ASSERT(type == SocketAddress::TYPE_IPV6);
|
||||
result = inet_pton(AF_INET6, address, &addr->in6.sin6_addr);
|
||||
}
|
||||
return result == 1;
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -302,7 +304,9 @@ intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) {
|
||||
intptr_t fd;
|
||||
|
||||
fd = NO_RETRY_EXPECTED(socket(addr.addr.sa_family, SOCK_DGRAM, IPPROTO_UDP));
|
||||
if (fd < 0) return -1;
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FDUtils::SetCloseOnExec(fd);
|
||||
|
||||
@@ -340,7 +344,9 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
|
||||
intptr_t fd;
|
||||
|
||||
fd = NO_RETRY_EXPECTED(socket(addr.ss.ss_family, SOCK_STREAM, 0));
|
||||
if (fd < 0) return -1;
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FDUtils::SetCloseOnExec(fd);
|
||||
|
||||
@@ -363,7 +369,8 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
|
||||
}
|
||||
|
||||
// Test for invalid socket port 65535 (some browsers disallow it).
|
||||
if (SocketAddress::GetAddrPort(addr) == 0 && Socket::GetPort(fd) == 65535) {
|
||||
if ((SocketAddress::GetAddrPort(addr)) == 0 &&
|
||||
(Socket::GetPort(fd) == 65535)) {
|
||||
// Don't close the socket until we have created a new socket, ensuring
|
||||
// that we do not get the bad port number again.
|
||||
intptr_t new_fd = CreateBindListen(addr, backlog, v6_only);
|
||||
@@ -435,9 +442,9 @@ bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
|
||||
reinterpret_cast<void *>(&on),
|
||||
&len));
|
||||
if (err == 0) {
|
||||
*enabled = on == 1;
|
||||
*enabled = (on == 1);
|
||||
}
|
||||
return err == 0;
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -521,9 +528,9 @@ bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
|
||||
reinterpret_cast<char *>(&on),
|
||||
&len));
|
||||
if (err == 0) {
|
||||
*enabled = on == 1;
|
||||
*enabled = (on == 1);
|
||||
}
|
||||
return err == 0;
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -539,7 +546,7 @@ bool Socket::SetBroadcast(intptr_t fd, bool enabled) {
|
||||
|
||||
bool Socket::JoinMulticast(
|
||||
intptr_t fd, const RawAddr& addr, const RawAddr&, int interfaceIndex) {
|
||||
int proto = addr.addr.sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
|
||||
int proto = (addr.addr.sa_family == AF_INET) ? IPPROTO_IP : IPPROTO_IPV6;
|
||||
struct group_req mreq;
|
||||
mreq.gr_interface = interfaceIndex;
|
||||
memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr));
|
||||
@@ -550,7 +557,7 @@ bool Socket::JoinMulticast(
|
||||
|
||||
bool Socket::LeaveMulticast(
|
||||
intptr_t fd, const RawAddr& addr, const RawAddr&, int interfaceIndex) {
|
||||
int proto = addr.addr.sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
|
||||
int proto = (addr.addr.sa_family == AF_INET) ? IPPROTO_IP : IPPROTO_IPV6;
|
||||
struct group_req mreq;
|
||||
mreq.gr_interface = interfaceIndex;
|
||||
memmove(&mreq.gr_group, &addr.ss, SocketAddress::GetAddrLength(addr));
|
||||
|
||||
+46
-35
@@ -9,14 +9,14 @@
|
||||
#include "bin/socket_linux.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <ifaddrs.h> // NOLINT
|
||||
#include <net/if.h> // NOLINT
|
||||
#include <netinet/tcp.h> // NOLINT
|
||||
#include <stdio.h> // NOLINT
|
||||
#include <stdlib.h> // NOLINT
|
||||
#include <string.h> // NOLINT
|
||||
#include <sys/stat.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <net/if.h> // NOLINT
|
||||
#include <netinet/tcp.h> // NOLINT
|
||||
#include <ifaddrs.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
#include "bin/file.h"
|
||||
@@ -39,11 +39,8 @@ SocketAddress::SocketAddress(struct sockaddr* sa) {
|
||||
|
||||
bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) {
|
||||
socklen_t salen = SocketAddress::GetAddrLength(addr);
|
||||
if (NO_RETRY_EXPECTED(getnameinfo(
|
||||
&addr.addr, salen, address, len, NULL, 0, NI_NUMERICHOST) != 0)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return (NO_RETRY_EXPECTED(getnameinfo(
|
||||
&addr.addr, salen, address, len, NULL, 0, NI_NUMERICHOST) == 0));
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +64,7 @@ static intptr_t Create(const RawAddr& addr) {
|
||||
static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
|
||||
intptr_t result = TEMP_FAILURE_RETRY(
|
||||
connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr)));
|
||||
if (result == 0 || errno == EINPROGRESS) {
|
||||
if ((result == 0) || (errno == EINPROGRESS)) {
|
||||
return fd;
|
||||
}
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
@@ -93,7 +90,7 @@ intptr_t Socket::CreateBindConnect(const RawAddr& addr,
|
||||
|
||||
intptr_t result = TEMP_FAILURE_RETRY(
|
||||
bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr)));
|
||||
if (result != 0 && errno != EINPROGRESS) {
|
||||
if ((result != 0) && (errno != EINPROGRESS)) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
return -1;
|
||||
}
|
||||
@@ -111,7 +108,7 @@ intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
|
||||
ASSERT(fd >= 0);
|
||||
ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
|
||||
ASSERT(EAGAIN == EWOULDBLOCK);
|
||||
if (read_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((read_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the read would block we need to retry and therefore return 0
|
||||
// as the number of bytes written.
|
||||
read_bytes = 0;
|
||||
@@ -126,7 +123,7 @@ intptr_t Socket::RecvFrom(
|
||||
socklen_t addr_len = sizeof(addr->ss);
|
||||
ssize_t read_bytes = TEMP_FAILURE_RETRY(
|
||||
recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len));
|
||||
if (read_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((read_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the read would block we need to retry and therefore return 0
|
||||
// as the number of bytes written.
|
||||
read_bytes = 0;
|
||||
@@ -139,7 +136,7 @@ intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
|
||||
ASSERT(fd >= 0);
|
||||
ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes));
|
||||
ASSERT(EAGAIN == EWOULDBLOCK);
|
||||
if (written_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((written_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the would block we need to retry and therefore return 0 as
|
||||
// the number of bytes written.
|
||||
written_bytes = 0;
|
||||
@@ -155,7 +152,7 @@ intptr_t Socket::SendTo(
|
||||
sendto(fd, buffer, num_bytes, 0,
|
||||
&addr.addr, SocketAddress::GetAddrLength(addr)));
|
||||
ASSERT(EAGAIN == EWOULDBLOCK);
|
||||
if (written_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((written_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the would block we need to retry and therefore return 0 as
|
||||
// the number of bytes written.
|
||||
written_bytes = 0;
|
||||
@@ -200,10 +197,18 @@ void Socket::GetError(intptr_t fd, OSError* os_error) {
|
||||
int Socket::GetType(intptr_t fd) {
|
||||
struct stat64 buf;
|
||||
int result = TEMP_FAILURE_RETRY(fstat64(fd, &buf));
|
||||
if (result == -1) return -1;
|
||||
if (S_ISCHR(buf.st_mode)) return File::kTerminal;
|
||||
if (S_ISFIFO(buf.st_mode)) return File::kPipe;
|
||||
if (S_ISREG(buf.st_mode)) return File::kFile;
|
||||
if (result == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (S_ISCHR(buf.st_mode)) {
|
||||
return File::kTerminal;
|
||||
}
|
||||
if (S_ISFIFO(buf.st_mode)) {
|
||||
return File::kPipe;
|
||||
}
|
||||
if (S_ISREG(buf.st_mode)) {
|
||||
return File::kFile;
|
||||
}
|
||||
return File::kOther;
|
||||
}
|
||||
|
||||
@@ -240,12 +245,14 @@ AddressList<SocketAddress>* Socket::LookupAddress(const char* host,
|
||||
}
|
||||
intptr_t count = 0;
|
||||
for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
|
||||
if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++;
|
||||
if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
intptr_t i = 0;
|
||||
AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count);
|
||||
for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
|
||||
if (c->ai_family == AF_INET || c->ai_family == AF_INET6) {
|
||||
if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
|
||||
addresses->SetAt(i, new SocketAddress(c->ai_addr));
|
||||
i++;
|
||||
}
|
||||
@@ -288,7 +295,7 @@ bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) {
|
||||
result = NO_RETRY_EXPECTED(
|
||||
inet_pton(AF_INET6, address, &addr->in6.sin6_addr));
|
||||
}
|
||||
return result == 1;
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -298,7 +305,9 @@ intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) {
|
||||
fd = NO_RETRY_EXPECTED(socket(addr.addr.sa_family,
|
||||
SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
|
||||
IPPROTO_UDP));
|
||||
if (fd < 0) return -1;
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (reuseAddress) {
|
||||
int optval = 1;
|
||||
@@ -321,12 +330,9 @@ static bool ShouldIncludeIfaAddrs(struct ifaddrs* ifa, int lookup_family) {
|
||||
return false;
|
||||
}
|
||||
int family = ifa->ifa_addr->sa_family;
|
||||
if (lookup_family == family) return true;
|
||||
if (lookup_family == AF_UNSPEC &&
|
||||
(family == AF_INET || family == AF_INET6)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ((lookup_family == family) ||
|
||||
(((lookup_family == AF_UNSPEC) &&
|
||||
((family == AF_INET) || (family == AF_INET6)))));
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +354,9 @@ AddressList<InterfaceSocketAddress>* Socket::ListInterfaces(
|
||||
|
||||
intptr_t count = 0;
|
||||
for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
if (ShouldIncludeIfaAddrs(ifa, lookup_family)) count++;
|
||||
if (ShouldIncludeIfaAddrs(ifa, lookup_family)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
AddressList<InterfaceSocketAddress>* addresses =
|
||||
@@ -374,7 +382,9 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
|
||||
|
||||
fd = NO_RETRY_EXPECTED(
|
||||
socket(addr.ss.ss_family, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0));
|
||||
if (fd < 0) return -1;
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int optval = 1;
|
||||
VOID_NO_RETRY_EXPECTED(
|
||||
@@ -393,7 +403,8 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
|
||||
}
|
||||
|
||||
// Test for invalid socket port 65535 (some browsers disallow it).
|
||||
if (SocketAddress::GetAddrPort(addr) == 0 && Socket::GetPort(fd) == 65535) {
|
||||
if ((SocketAddress::GetAddrPort(addr) == 0) &&
|
||||
(Socket::GetPort(fd) == 65535)) {
|
||||
// Don't close the socket until we have created a new socket, ensuring
|
||||
// that we do not get the bad port number again.
|
||||
intptr_t new_fd = CreateBindListen(addr, backlog, v6_only);
|
||||
@@ -461,9 +472,9 @@ bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
|
||||
int err = NO_RETRY_EXPECTED(getsockopt(
|
||||
fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<void *>(&on), &len));
|
||||
if (err == 0) {
|
||||
*enabled = on == 1;
|
||||
*enabled = (on == 1);
|
||||
}
|
||||
return err == 0;
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -533,9 +544,9 @@ bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
|
||||
int err = NO_RETRY_EXPECTED(getsockopt(
|
||||
fd, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<char *>(&on), &len));
|
||||
if (err == 0) {
|
||||
*enabled = on == 1;
|
||||
*enabled = (on == 1);
|
||||
}
|
||||
return err == 0;
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+43
-39
@@ -9,14 +9,14 @@
|
||||
#include "bin/socket_macos.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <ifaddrs.h> // NOLINT
|
||||
#include <net/if.h> // NOLINT
|
||||
#include <netinet/tcp.h> // NOLINT
|
||||
#include <stdio.h> // NOLINT
|
||||
#include <stdlib.h> // NOLINT
|
||||
#include <string.h> // NOLINT
|
||||
#include <sys/stat.h> // NOLINT
|
||||
#include <unistd.h> // NOLINT
|
||||
#include <net/if.h> // NOLINT
|
||||
#include <netinet/tcp.h> // NOLINT
|
||||
#include <ifaddrs.h> // NOLINT
|
||||
|
||||
#include "bin/fdutils.h"
|
||||
#include "bin/file.h"
|
||||
@@ -38,16 +38,8 @@ SocketAddress::SocketAddress(struct sockaddr* sa) {
|
||||
|
||||
bool Socket::FormatNumericAddress(const RawAddr& addr, char* address, int len) {
|
||||
socklen_t salen = SocketAddress::GetAddrLength(addr);
|
||||
if (NO_RETRY_EXPECTED(getnameinfo(&addr.addr,
|
||||
salen,
|
||||
address,
|
||||
len,
|
||||
NULL,
|
||||
0,
|
||||
NI_NUMERICHOST)) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return (NO_RETRY_EXPECTED(getnameinfo(
|
||||
&addr.addr, salen, address, len, NULL, 0, NI_NUMERICHOST)) == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +63,7 @@ static intptr_t Create(const RawAddr& addr) {
|
||||
static intptr_t Connect(intptr_t fd, const RawAddr& addr) {
|
||||
intptr_t result = TEMP_FAILURE_RETRY(
|
||||
connect(fd, &addr.addr, SocketAddress::GetAddrLength(addr)));
|
||||
if (result == 0 || errno == EINPROGRESS) {
|
||||
if ((result == 0) || (errno == EINPROGRESS)) {
|
||||
return fd;
|
||||
}
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
@@ -100,7 +92,7 @@ intptr_t Socket::CreateBindConnect(const RawAddr& addr,
|
||||
|
||||
intptr_t result = TEMP_FAILURE_RETRY(
|
||||
bind(fd, &source_addr.addr, SocketAddress::GetAddrLength(source_addr)));
|
||||
if (result != 0 && errno != EINPROGRESS) {
|
||||
if ((result != 0) && (errno != EINPROGRESS)) {
|
||||
VOID_TEMP_FAILURE_RETRY(close(fd));
|
||||
return -1;
|
||||
}
|
||||
@@ -118,7 +110,7 @@ intptr_t Socket::Read(intptr_t fd, void* buffer, intptr_t num_bytes) {
|
||||
ASSERT(fd >= 0);
|
||||
ssize_t read_bytes = TEMP_FAILURE_RETRY(read(fd, buffer, num_bytes));
|
||||
ASSERT(EAGAIN == EWOULDBLOCK);
|
||||
if (read_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((read_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the read would block we need to retry and therefore return 0
|
||||
// as the number of bytes written.
|
||||
read_bytes = 0;
|
||||
@@ -133,7 +125,7 @@ intptr_t Socket::RecvFrom(
|
||||
socklen_t addr_len = sizeof(addr->ss);
|
||||
ssize_t read_bytes = TEMP_FAILURE_RETRY(
|
||||
recvfrom(fd, buffer, num_bytes, 0, &addr->addr, &addr_len));
|
||||
if (read_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((read_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the read would block we need to retry and therefore return 0
|
||||
// as the number of bytes written.
|
||||
read_bytes = 0;
|
||||
@@ -146,7 +138,7 @@ intptr_t Socket::Write(intptr_t fd, const void* buffer, intptr_t num_bytes) {
|
||||
ASSERT(fd >= 0);
|
||||
ssize_t written_bytes = TEMP_FAILURE_RETRY(write(fd, buffer, num_bytes));
|
||||
ASSERT(EAGAIN == EWOULDBLOCK);
|
||||
if (written_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((written_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the would block we need to retry and therefore return 0 as
|
||||
// the number of bytes written.
|
||||
written_bytes = 0;
|
||||
@@ -162,7 +154,7 @@ intptr_t Socket::SendTo(
|
||||
sendto(fd, buffer, num_bytes, 0,
|
||||
&addr.addr, SocketAddress::GetAddrLength(addr)));
|
||||
ASSERT(EAGAIN == EWOULDBLOCK);
|
||||
if (written_bytes == -1 && errno == EWOULDBLOCK) {
|
||||
if ((written_bytes == -1) && (errno == EWOULDBLOCK)) {
|
||||
// If the would block we need to retry and therefore return 0 as
|
||||
// the number of bytes written.
|
||||
written_bytes = 0;
|
||||
@@ -208,10 +200,18 @@ void Socket::GetError(intptr_t fd, OSError* os_error) {
|
||||
int Socket::GetType(intptr_t fd) {
|
||||
struct stat buf;
|
||||
int result = fstat(fd, &buf);
|
||||
if (result == -1) return -1;
|
||||
if (S_ISCHR(buf.st_mode)) return File::kTerminal;
|
||||
if (S_ISFIFO(buf.st_mode)) return File::kPipe;
|
||||
if (S_ISREG(buf.st_mode)) return File::kFile;
|
||||
if (result == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (S_ISCHR(buf.st_mode)) {
|
||||
return File::kTerminal;
|
||||
}
|
||||
if (S_ISFIFO(buf.st_mode)) {
|
||||
return File::kPipe;
|
||||
}
|
||||
if (S_ISREG(buf.st_mode)) {
|
||||
return File::kFile;
|
||||
}
|
||||
return File::kOther;
|
||||
}
|
||||
|
||||
@@ -242,12 +242,14 @@ AddressList<SocketAddress>* Socket::LookupAddress(const char* host,
|
||||
}
|
||||
intptr_t count = 0;
|
||||
for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
|
||||
if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++;
|
||||
if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
intptr_t i = 0;
|
||||
AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count);
|
||||
for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
|
||||
if (c->ai_family == AF_INET || c->ai_family == AF_INET6) {
|
||||
if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
|
||||
addresses->SetAt(i, new SocketAddress(c->ai_addr));
|
||||
i++;
|
||||
}
|
||||
@@ -289,7 +291,7 @@ bool Socket::ParseAddress(int type, const char* address, RawAddr* addr) {
|
||||
ASSERT(type == SocketAddress::TYPE_IPV6);
|
||||
result = inet_pton(AF_INET6, address, &addr->in6.sin6_addr);
|
||||
}
|
||||
return result == 1;
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -297,7 +299,9 @@ intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) {
|
||||
intptr_t fd;
|
||||
|
||||
fd = NO_RETRY_EXPECTED(socket(addr.addr.sa_family, SOCK_DGRAM, IPPROTO_UDP));
|
||||
if (fd < 0) return -1;
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FDUtils::SetCloseOnExec(fd);
|
||||
|
||||
@@ -324,12 +328,9 @@ static bool ShouldIncludeIfaAddrs(struct ifaddrs* ifa, int lookup_family) {
|
||||
return false;
|
||||
}
|
||||
int family = ifa->ifa_addr->sa_family;
|
||||
if (lookup_family == family) return true;
|
||||
if (lookup_family == AF_UNSPEC &&
|
||||
(family == AF_INET || family == AF_INET6)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ((lookup_family == family) ||
|
||||
((lookup_family == AF_UNSPEC) &&
|
||||
((family == AF_INET) || (family == AF_INET6))));
|
||||
}
|
||||
|
||||
|
||||
@@ -376,7 +377,9 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
|
||||
intptr_t fd;
|
||||
|
||||
fd = TEMP_FAILURE_RETRY(socket(addr.ss.ss_family, SOCK_STREAM, 0));
|
||||
if (fd < 0) return -1;
|
||||
if (fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FDUtils::SetCloseOnExec(fd);
|
||||
|
||||
@@ -397,7 +400,8 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
|
||||
}
|
||||
|
||||
// Test for invalid socket port 65535 (some browsers disallow it).
|
||||
if (SocketAddress::GetAddrPort(addr) == 0 && Socket::GetPort(fd) == 65535) {
|
||||
if ((SocketAddress::GetAddrPort(addr) == 0) &&
|
||||
(Socket::GetPort(fd) == 65535)) {
|
||||
// Don't close the socket until we have created a new socket, ensuring
|
||||
// that we do not get the bad port number again.
|
||||
intptr_t new_fd = CreateBindListen(addr, backlog, v6_only);
|
||||
@@ -459,9 +463,9 @@ bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
|
||||
reinterpret_cast<void *>(&on),
|
||||
&len));
|
||||
if (err == 0) {
|
||||
*enabled = on == 1;
|
||||
*enabled = (on == 1);
|
||||
}
|
||||
return err == 0;
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -546,9 +550,9 @@ bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
|
||||
reinterpret_cast<char *>(&on),
|
||||
&len));
|
||||
if (err == 0) {
|
||||
*enabled = on == 1;
|
||||
*enabled = (on == 1);
|
||||
}
|
||||
return err == 0;
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+21
-24
@@ -54,7 +54,9 @@ static bool socket_initialized = false;
|
||||
|
||||
bool Socket::Initialize() {
|
||||
MutexLocker lock(init_mutex);
|
||||
if (socket_initialized) return true;
|
||||
if (socket_initialized) {
|
||||
return true;
|
||||
}
|
||||
int err;
|
||||
WSADATA winsock_data;
|
||||
WORD version_requested = MAKEWORD(2, 2);
|
||||
@@ -64,7 +66,7 @@ bool Socket::Initialize() {
|
||||
} else {
|
||||
Log::PrintErr("Unable to initialize Winsock: %d\n", WSAGetLastError());
|
||||
}
|
||||
return err == 0;
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
intptr_t Socket::Available(intptr_t fd) {
|
||||
@@ -107,9 +109,7 @@ intptr_t Socket::GetPort(intptr_t fd) {
|
||||
SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd);
|
||||
RawAddr raw;
|
||||
socklen_t size = sizeof(raw);
|
||||
if (getsockname(socket_handle->socket(),
|
||||
&raw.addr,
|
||||
&size) == SOCKET_ERROR) {
|
||||
if (getsockname(socket_handle->socket(), &raw.addr, &size) == SOCKET_ERROR) {
|
||||
return 0;
|
||||
}
|
||||
return SocketAddress::GetAddrPort(raw);
|
||||
@@ -121,9 +121,7 @@ SocketAddress* Socket::GetRemotePeer(intptr_t fd, intptr_t* port) {
|
||||
SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd);
|
||||
RawAddr raw;
|
||||
socklen_t size = sizeof(raw);
|
||||
if (getpeername(socket_handle->socket(),
|
||||
&raw.addr,
|
||||
&size)) {
|
||||
if (getpeername(socket_handle->socket(), &raw.addr, &size)) {
|
||||
return NULL;
|
||||
}
|
||||
*port = SocketAddress::GetAddrPort(raw);
|
||||
@@ -268,7 +266,9 @@ int Socket::GetType(intptr_t fd) {
|
||||
|
||||
|
||||
intptr_t Socket::GetStdioHandle(intptr_t num) {
|
||||
if (num != 0) return -1;
|
||||
if (num != 0) {
|
||||
return -1;
|
||||
}
|
||||
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (handle == INVALID_HANDLE_VALUE) {
|
||||
return -1;
|
||||
@@ -320,12 +320,14 @@ AddressList<SocketAddress>* Socket::LookupAddress(const char* host,
|
||||
}
|
||||
intptr_t count = 0;
|
||||
for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
|
||||
if (c->ai_family == AF_INET || c->ai_family == AF_INET6) count++;
|
||||
if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
AddressList<SocketAddress>* addresses = new AddressList<SocketAddress>(count);
|
||||
intptr_t i = 0;
|
||||
for (struct addrinfo* c = info; c != NULL; c = c->ai_next) {
|
||||
if (c->ai_family == AF_INET || c->ai_family == AF_INET6) {
|
||||
if ((c->ai_family == AF_INET) || (c->ai_family == AF_INET6)) {
|
||||
addresses->SetAt(i, new SocketAddress(c->ai_addr));
|
||||
i++;
|
||||
}
|
||||
@@ -393,9 +395,7 @@ intptr_t Socket::CreateBindDatagram(const RawAddr& addr, bool reuseAddress) {
|
||||
}
|
||||
}
|
||||
|
||||
status = bind(s,
|
||||
&addr.addr,
|
||||
SocketAddress::GetAddrLength(addr));
|
||||
status = bind(s, &addr.addr, SocketAddress::GetAddrLength(addr));
|
||||
if (status == SOCKET_ERROR) {
|
||||
DWORD rc = WSAGetLastError();
|
||||
closesocket(s);
|
||||
@@ -496,9 +496,7 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
|
||||
sizeof(optval));
|
||||
}
|
||||
|
||||
status = bind(s,
|
||||
&addr.addr,
|
||||
SocketAddress::GetAddrLength(addr));
|
||||
status = bind(s, &addr.addr, SocketAddress::GetAddrLength(addr));
|
||||
if (status == SOCKET_ERROR) {
|
||||
DWORD rc = WSAGetLastError();
|
||||
closesocket(s);
|
||||
@@ -509,8 +507,8 @@ intptr_t ServerSocket::CreateBindListen(const RawAddr& addr,
|
||||
ListenSocket* listen_socket = new ListenSocket(s);
|
||||
|
||||
// Test for invalid socket port 65535 (some browsers disallow it).
|
||||
if (SocketAddress::GetAddrPort(addr) == 0 &&
|
||||
Socket::GetPort(reinterpret_cast<intptr_t>(listen_socket)) == 65535) {
|
||||
if ((SocketAddress::GetAddrPort(addr) == 0) &&
|
||||
(Socket::GetPort(reinterpret_cast<intptr_t>(listen_socket)) == 65535)) {
|
||||
// Don't close fd until we have created new. By doing that we ensure another
|
||||
// port.
|
||||
intptr_t new_s = CreateBindListen(addr, backlog, v6_only);
|
||||
@@ -571,9 +569,9 @@ bool Socket::GetNoDelay(intptr_t fd, bool* enabled) {
|
||||
reinterpret_cast<char *>(&on),
|
||||
&len);
|
||||
if (err == 0) {
|
||||
*enabled = on == 1;
|
||||
*enabled = (on == 1);
|
||||
}
|
||||
return err == 0;
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -618,7 +616,6 @@ bool Socket::SetMulticastLoop(intptr_t fd, intptr_t protocol, bool enabled) {
|
||||
optname,
|
||||
reinterpret_cast<char *>(&on),
|
||||
sizeof(on)) == 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -665,9 +662,9 @@ bool Socket::GetBroadcast(intptr_t fd, bool* enabled) {
|
||||
reinterpret_cast<char *>(&on),
|
||||
&len);
|
||||
if (err == 0) {
|
||||
*enabled = on == 1;
|
||||
*enabled = (on == 1);
|
||||
}
|
||||
return err == 0;
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
#ifndef BIN_SOCKET_WIN_H_
|
||||
#define BIN_SOCKET_WIN_H_
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <mswsock.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#endif // BIN_SOCKET_WIN_H_
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
// 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.
|
||||
|
||||
#include "bin/stdio.h"
|
||||
|
||||
#include "bin/builtin.h"
|
||||
#include "bin/dartutils.h"
|
||||
#include "bin/utils.h"
|
||||
#include "bin/stdio.h"
|
||||
|
||||
#include "platform/globals.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
#include "include/dart_api.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -51,7 +51,7 @@ void FUNCTION_NAME(Stdout_GetTerminalSize)(Dart_NativeArguments args) {
|
||||
return;
|
||||
}
|
||||
intptr_t fd = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0));
|
||||
if (fd != 1 && fd != 2) {
|
||||
if ((fd != 1) && (fd != 2)) {
|
||||
Dart_SetReturnValue(args, Dart_NewApiError("Terminal fd must be 1 or 2"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#include "platform/globals.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
|
||||
@@ -5,16 +5,15 @@
|
||||
#include "platform/globals.h"
|
||||
#if defined(TARGET_OS_ANDROID)
|
||||
|
||||
#include "bin/stdio.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <sys/ioctl.h> // NOLINT
|
||||
#include <termios.h> // NOLINT
|
||||
|
||||
#include "bin/stdio.h"
|
||||
#include "bin/fdutils.h"
|
||||
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -30,7 +29,7 @@ int Stdin::ReadByte() {
|
||||
bool Stdin::GetEchoMode() {
|
||||
struct termios term;
|
||||
tcgetattr(STDIN_FILENO, &term);
|
||||
return (term.c_lflag & ECHO) != 0;
|
||||
return ((term.c_lflag & ECHO) != 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +37,9 @@ void Stdin::SetEchoMode(bool enabled) {
|
||||
struct termios term;
|
||||
tcgetattr(STDIN_FILENO, &term);
|
||||
if (enabled) {
|
||||
term.c_lflag |= ECHO|ECHONL;
|
||||
term.c_lflag |= (ECHO | ECHONL);
|
||||
} else {
|
||||
term.c_lflag &= ~(ECHO|ECHONL);
|
||||
term.c_lflag &= ~(ECHO | ECHONL);
|
||||
}
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &term);
|
||||
}
|
||||
@@ -49,7 +48,7 @@ void Stdin::SetEchoMode(bool enabled) {
|
||||
bool Stdin::GetLineMode() {
|
||||
struct termios term;
|
||||
tcgetattr(STDIN_FILENO, &term);
|
||||
return (term.c_lflag & ICANON) != 0;
|
||||
return ((term.c_lflag & ICANON) != 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +66,8 @@ void Stdin::SetLineMode(bool enabled) {
|
||||
|
||||
bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
|
||||
struct winsize w;
|
||||
if (NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w) == 0) &&
|
||||
(w.ws_col != 0 || w.ws_row != 0)) {
|
||||
int status = NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w));
|
||||
if ((status == 0) && ((w.ws_col != 0) || (w.ws_row != 0))) {
|
||||
size[0] = w.ws_col;
|
||||
size[1] = w.ws_row;
|
||||
return true;
|
||||
|
||||
@@ -5,16 +5,15 @@
|
||||
#include "platform/globals.h"
|
||||
#if defined(TARGET_OS_LINUX)
|
||||
|
||||
#include "bin/stdio.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <sys/ioctl.h> // NOLINT
|
||||
#include <termios.h> // NOLINT
|
||||
|
||||
#include "bin/stdio.h"
|
||||
#include "bin/fdutils.h"
|
||||
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -30,7 +29,7 @@ int Stdin::ReadByte() {
|
||||
bool Stdin::GetEchoMode() {
|
||||
struct termios term;
|
||||
VOID_NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
|
||||
return (term.c_lflag & ECHO) != 0;
|
||||
return ((term.c_lflag & ECHO) != 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +37,9 @@ void Stdin::SetEchoMode(bool enabled) {
|
||||
struct termios term;
|
||||
VOID_NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
|
||||
if (enabled) {
|
||||
term.c_lflag |= ECHO|ECHONL;
|
||||
term.c_lflag |= (ECHO | ECHONL);
|
||||
} else {
|
||||
term.c_lflag &= ~(ECHO|ECHONL);
|
||||
term.c_lflag &= ~(ECHO | ECHONL);
|
||||
}
|
||||
VOID_NO_RETRY_EXPECTED(tcsetattr(STDIN_FILENO, TCSANOW, &term));
|
||||
}
|
||||
@@ -49,7 +48,7 @@ void Stdin::SetEchoMode(bool enabled) {
|
||||
bool Stdin::GetLineMode() {
|
||||
struct termios term;
|
||||
VOID_NO_RETRY_EXPECTED(tcgetattr(STDIN_FILENO, &term));
|
||||
return (term.c_lflag & ICANON) != 0;
|
||||
return ((term.c_lflag & ICANON) != 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +66,8 @@ void Stdin::SetLineMode(bool enabled) {
|
||||
|
||||
bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
|
||||
struct winsize w;
|
||||
if (NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w)) == 0 &&
|
||||
(w.ws_col != 0 || w.ws_row != 0)) {
|
||||
int status = NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w));
|
||||
if ((status == 0) && ((w.ws_col != 0) || (w.ws_row != 0))) {
|
||||
size[0] = w.ws_col;
|
||||
size[1] = w.ws_row;
|
||||
return true;
|
||||
|
||||
@@ -5,16 +5,15 @@
|
||||
#include "platform/globals.h"
|
||||
#if defined(TARGET_OS_MACOS)
|
||||
|
||||
#include "bin/stdio.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <sys/ioctl.h> // NOLINT
|
||||
#include <termios.h> // NOLINT
|
||||
|
||||
#include "bin/stdio.h"
|
||||
#include "bin/fdutils.h"
|
||||
|
||||
#include "platform/signal_blocker.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -30,7 +29,7 @@ int Stdin::ReadByte() {
|
||||
bool Stdin::GetEchoMode() {
|
||||
struct termios term;
|
||||
tcgetattr(STDIN_FILENO, &term);
|
||||
return (term.c_lflag & ECHO) != 0;
|
||||
return ((term.c_lflag & ECHO) != 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +37,9 @@ void Stdin::SetEchoMode(bool enabled) {
|
||||
struct termios term;
|
||||
tcgetattr(STDIN_FILENO, &term);
|
||||
if (enabled) {
|
||||
term.c_lflag |= ECHO|ECHONL;
|
||||
term.c_lflag |= (ECHO | ECHONL);
|
||||
} else {
|
||||
term.c_lflag &= ~(ECHO|ECHONL);
|
||||
term.c_lflag &= ~(ECHO | ECHONL);
|
||||
}
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &term);
|
||||
}
|
||||
@@ -49,7 +48,7 @@ void Stdin::SetEchoMode(bool enabled) {
|
||||
bool Stdin::GetLineMode() {
|
||||
struct termios term;
|
||||
tcgetattr(STDIN_FILENO, &term);
|
||||
return (term.c_lflag & ICANON) != 0;
|
||||
return ((term.c_lflag & ICANON) != 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +66,8 @@ void Stdin::SetLineMode(bool enabled) {
|
||||
|
||||
bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
|
||||
struct winsize w;
|
||||
if (NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w) == 0) &&
|
||||
(w.ws_col != 0 || w.ws_row != 0)) {
|
||||
int status = NO_RETRY_EXPECTED(ioctl(fd, TIOCGWINSZ, &w));
|
||||
if ((status == 0) && ((w.ws_col != 0) || (w.ws_row != 0))) {
|
||||
size[0] = w.ws_col;
|
||||
size[1] = w.ws_row;
|
||||
return true;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "bin/stdio.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -16,7 +15,7 @@ int Stdin::ReadByte() {
|
||||
uint8_t buffer[1];
|
||||
DWORD read = 0;
|
||||
int c = -1;
|
||||
if (ReadFile(h, buffer, 1, &read, NULL) && read == 1) {
|
||||
if (ReadFile(h, buffer, 1, &read, NULL) && (read == 1)) {
|
||||
c = buffer[0];
|
||||
}
|
||||
return c;
|
||||
@@ -26,15 +25,19 @@ int Stdin::ReadByte() {
|
||||
bool Stdin::GetEchoMode() {
|
||||
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD mode;
|
||||
if (!GetConsoleMode(h, &mode)) return false;
|
||||
return (mode & ENABLE_ECHO_INPUT) != 0;
|
||||
if (!GetConsoleMode(h, &mode)) {
|
||||
return false;
|
||||
}
|
||||
return ((mode & ENABLE_ECHO_INPUT) != 0);
|
||||
}
|
||||
|
||||
|
||||
void Stdin::SetEchoMode(bool enabled) {
|
||||
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD mode;
|
||||
if (!GetConsoleMode(h, &mode)) return;
|
||||
if (!GetConsoleMode(h, &mode)) {
|
||||
return;
|
||||
}
|
||||
if (enabled) {
|
||||
mode |= ENABLE_ECHO_INPUT;
|
||||
} else {
|
||||
@@ -47,7 +50,9 @@ void Stdin::SetEchoMode(bool enabled) {
|
||||
bool Stdin::GetLineMode() {
|
||||
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD mode;
|
||||
if (!GetConsoleMode(h, &mode)) return false;
|
||||
if (!GetConsoleMode(h, &mode)) {
|
||||
return false;
|
||||
}
|
||||
return (mode & ENABLE_LINE_INPUT) != 0;
|
||||
}
|
||||
|
||||
@@ -55,7 +60,9 @@ bool Stdin::GetLineMode() {
|
||||
void Stdin::SetLineMode(bool enabled) {
|
||||
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD mode;
|
||||
if (!GetConsoleMode(h, &mode)) return;
|
||||
if (!GetConsoleMode(h, &mode)) {
|
||||
return;
|
||||
}
|
||||
if (enabled) {
|
||||
mode |= ENABLE_LINE_INPUT;
|
||||
} else {
|
||||
@@ -73,7 +80,9 @@ bool Stdout::GetTerminalSize(intptr_t fd, int size[2]) {
|
||||
h = GetStdHandle(STD_ERROR_HANDLE);
|
||||
}
|
||||
CONSOLE_SCREEN_BUFFER_INFO info;
|
||||
if (!GetConsoleScreenBufferInfo(h, &info)) return false;
|
||||
if (!GetConsoleScreenBufferInfo(h, &info)) {
|
||||
return false;
|
||||
}
|
||||
size[0] = info.srWindow.Right - info.srWindow.Left + 1;
|
||||
size[1] = info.srWindow.Bottom - info.srWindow.Top + 1;
|
||||
return true;
|
||||
|
||||
@@ -57,6 +57,10 @@ class Thread {
|
||||
static void GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage);
|
||||
|
||||
static void InitOnce();
|
||||
|
||||
private:
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(Thread);
|
||||
};
|
||||
|
||||
|
||||
@@ -105,7 +109,6 @@ class Monitor {
|
||||
DISALLOW_COPY_AND_ASSIGN(Monitor);
|
||||
};
|
||||
|
||||
|
||||
} // namespace bin
|
||||
} // namespace dart
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#if defined(TARGET_OS_ANDROID)
|
||||
|
||||
#include "bin/thread.h"
|
||||
#include "bin/thread_android.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <sys/time.h> // NOLINT
|
||||
@@ -37,7 +38,9 @@ namespace bin {
|
||||
}
|
||||
#else
|
||||
#define RETURN_ON_PTHREAD_FAILURE(result) \
|
||||
if (result != 0) return result;
|
||||
if (result != 0) { \
|
||||
return result; \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -164,7 +167,7 @@ intptr_t Thread::ThreadIdToIntPtr(ThreadId id) {
|
||||
|
||||
|
||||
bool Thread::Compare(ThreadId a, ThreadId b) {
|
||||
return a == b;
|
||||
return (a == b);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#if defined(TARGET_OS_LINUX)
|
||||
|
||||
#include "bin/thread.h"
|
||||
#include "bin/thread_linux.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <sys/resource.h> // NOLINT
|
||||
@@ -38,7 +39,9 @@ namespace bin {
|
||||
}
|
||||
#else
|
||||
#define RETURN_ON_PTHREAD_FAILURE(result) \
|
||||
if (result != 0) return result;
|
||||
if (result != 0) { \
|
||||
return result; \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -165,7 +168,7 @@ intptr_t Thread::ThreadIdToIntPtr(ThreadId id) {
|
||||
|
||||
|
||||
bool Thread::Compare(ThreadId a, ThreadId b) {
|
||||
return pthread_equal(a, b) != 0;
|
||||
return (pthread_equal(a, b) != 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,17 +6,18 @@
|
||||
#if defined(TARGET_OS_MACOS)
|
||||
|
||||
#include "bin/thread.h"
|
||||
#include "bin/thread_macos.h"
|
||||
|
||||
#include <sys/errno.h> // NOLINT
|
||||
#include <sys/types.h> // NOLINT
|
||||
#include <sys/sysctl.h> // NOLINT
|
||||
#include <mach/mach_init.h> // NOLINT
|
||||
#include <mach/mach_host.h> // NOLINT
|
||||
#include <mach/mach_init.h> // NOLINT
|
||||
#include <mach/mach_port.h> // NOLINT
|
||||
#include <mach/mach_traps.h> // NOLINT
|
||||
#include <mach/task_info.h> // NOLINT
|
||||
#include <mach/thread_info.h> // NOLINT
|
||||
#include <mach/thread_act.h> // NOLINT
|
||||
#include <mach/thread_info.h> // NOLINT
|
||||
#include <sys/errno.h> // NOLINT
|
||||
#include <sys/sysctl.h> // NOLINT
|
||||
#include <sys/types.h> // NOLINT
|
||||
|
||||
#include "platform/assert.h"
|
||||
#include "platform/utils.h"
|
||||
@@ -45,7 +46,9 @@ namespace bin {
|
||||
}
|
||||
#else
|
||||
#define RETURN_ON_PTHREAD_FAILURE(result) \
|
||||
if (result != 0) return result;
|
||||
if (result != 0) { \
|
||||
return result; \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -157,7 +160,7 @@ intptr_t Thread::ThreadIdToIntPtr(ThreadId id) {
|
||||
|
||||
|
||||
bool Thread::Compare(ThreadId a, ThreadId b) {
|
||||
return pthread_equal(a, b) != 0;
|
||||
return (pthread_equal(a, b) != 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#if defined(TARGET_OS_WINDOWS)
|
||||
|
||||
#include "bin/thread.h"
|
||||
#include "bin/thread_win.h"
|
||||
|
||||
#include <process.h> // NOLINT
|
||||
|
||||
@@ -57,7 +58,7 @@ int Thread::Start(ThreadStartFunction function, uword parameter) {
|
||||
uint32_t tid;
|
||||
uintptr_t thread = _beginthreadex(NULL, Thread::GetMaxStackSize(),
|
||||
ThreadEntry, start_data, 0, &tid);
|
||||
if (thread == -1L || thread == 0) {
|
||||
if ((thread == -1L) || (thread == 0)) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "_beginthreadex error: %d (%s)\n", errno, strerror(errno));
|
||||
#endif
|
||||
@@ -130,7 +131,7 @@ intptr_t Thread::ThreadIdToIntPtr(ThreadId id) {
|
||||
|
||||
|
||||
bool Thread::Compare(ThreadId a, ThreadId b) {
|
||||
return a == b;
|
||||
return (a == b);
|
||||
}
|
||||
|
||||
|
||||
@@ -209,7 +210,7 @@ bool Mutex::TryLock() {
|
||||
if (result == WAIT_OBJECT_0) {
|
||||
return true;
|
||||
}
|
||||
if (result == WAIT_ABANDONED || result == WAIT_FAILED) {
|
||||
if ((result == WAIT_ABANDONED) || (result == WAIT_FAILED)) {
|
||||
FATAL1("Mutex try lock failed %d", GetLastError());
|
||||
}
|
||||
ASSERT(result == WAIT_TIMEOUT);
|
||||
@@ -273,7 +274,8 @@ void MonitorData::AddWaiter(MonitorWaitData* wait_data) {
|
||||
EnterCriticalSection(&waiters_cs_);
|
||||
if (waiters_tail_ == NULL) {
|
||||
ASSERT(waiters_head_ == NULL);
|
||||
waiters_head_ = waiters_tail_ = wait_data;
|
||||
waiters_head_ = wait_data;
|
||||
waiters_tail_ = wait_data;
|
||||
} else {
|
||||
waiters_tail_->next_ = wait_data;
|
||||
waiters_tail_ = wait_data;
|
||||
@@ -291,7 +293,8 @@ void MonitorData::RemoveWaiter(MonitorWaitData* wait_data) {
|
||||
while (current != NULL) {
|
||||
if (current == wait_data) {
|
||||
if (waiters_head_ == waiters_tail_) {
|
||||
waiters_head_ = waiters_tail_ = NULL;
|
||||
waiters_head_ = NULL;
|
||||
waiters_tail_ = NULL;
|
||||
} else if (current == waiters_head_) {
|
||||
waiters_head_ = waiters_head_->next_;
|
||||
} else if (current == waiters_tail_) {
|
||||
@@ -319,7 +322,8 @@ void MonitorData::SignalAndRemoveFirstWaiter() {
|
||||
if (first != NULL) {
|
||||
// Remove from list.
|
||||
if (waiters_head_ == waiters_tail_) {
|
||||
waiters_tail_ = waiters_head_ = NULL;
|
||||
waiters_tail_ = NULL;
|
||||
waiters_head_ = NULL;
|
||||
} else {
|
||||
waiters_head_ = waiters_head_->next_;
|
||||
}
|
||||
@@ -340,7 +344,8 @@ void MonitorData::SignalAndRemoveAllWaiters() {
|
||||
// Extract list to signal.
|
||||
MonitorWaitData* current = waiters_head_;
|
||||
// Clear list.
|
||||
waiters_head_ = waiters_tail_ = NULL;
|
||||
waiters_head_ = NULL;
|
||||
waiters_tail_ = NULL;
|
||||
// Iterate and signal all events.
|
||||
while (current != NULL) {
|
||||
// Copy next.
|
||||
|
||||
@@ -83,6 +83,10 @@ class StringUtils {
|
||||
static char* Utf8ToConsoleString(char* utf8,
|
||||
intptr_t len = -1,
|
||||
intptr_t* result_len = NULL);
|
||||
|
||||
private:
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(StringUtils);
|
||||
};
|
||||
|
||||
|
||||
@@ -94,14 +98,23 @@ class ShellUtils {
|
||||
// Returns true if the arguments are converted. In that case
|
||||
// each of the arguments need to be deallocated using free.
|
||||
static bool GetUtf8Argv(int argc, char** argv);
|
||||
|
||||
private:
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(ShellUtils);
|
||||
};
|
||||
|
||||
|
||||
class TimerUtils {
|
||||
public:
|
||||
static void InitOnce();
|
||||
static int64_t GetCurrentMonotonicMicros();
|
||||
static int64_t GetCurrentMonotonicMillis();
|
||||
static void Sleep(int64_t millis);
|
||||
|
||||
private:
|
||||
DISALLOW_ALLOCATION();
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(TimerUtils);
|
||||
};
|
||||
|
||||
} // namespace bin
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "platform/assert.h"
|
||||
#include "platform/utils.h"
|
||||
|
||||
|
||||
namespace dart {
|
||||
namespace bin {
|
||||
|
||||
@@ -43,41 +42,49 @@ void OSError::SetCodeAndMessage(SubSystem sub_system, int code) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const char* StringUtils::ConsoleStringToUtf8(
|
||||
const char* str, intptr_t len, intptr_t* result_len) {
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
const char* StringUtils::Utf8ToConsoleString(
|
||||
const char* utf8, intptr_t len, intptr_t* result_len) {
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char* StringUtils::ConsoleStringToUtf8(
|
||||
char* str, intptr_t len, intptr_t* result_len) {
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char* StringUtils::Utf8ToConsoleString(
|
||||
char* utf8, intptr_t len, intptr_t* result_len) {
|
||||
UNIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool ShellUtils::GetUtf8Argv(int argc, char** argv) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void TimerUtils::InitOnce() {
|
||||
}
|
||||
|
||||
|
||||
int64_t TimerUtils::GetCurrentMonotonicMillis() {
|
||||
return GetCurrentMonotonicMicros() / 1000;
|
||||
}
|
||||
|
||||
|
||||
int64_t TimerUtils::GetCurrentMonotonicMicros() {
|
||||
struct timespec ts;
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
|
||||
@@ -91,6 +98,7 @@ int64_t TimerUtils::GetCurrentMonotonicMicros() {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void TimerUtils::Sleep(int64_t millis) {
|
||||
struct timespec req; // requested.
|
||||
struct timespec rem; // remainder.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user