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

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

Issue 169383003: Make event-handlers edge-triggered and move socket-state to Dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mac os X support. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "bin/file_system_watcher.h" 8 #include "bin/file_system_watcher.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
11 #include <sys/inotify.h> // NOLINT 11 #include <sys/inotify.h> // NOLINT
12 12
13 #include "bin/fdutils.h" 13 #include "bin/fdutils.h"
14 #include "bin/socket.h"
14 15
15 16
16 namespace dart { 17 namespace dart {
17 namespace bin { 18 namespace bin {
18 19
19 bool FileSystemWatcher::IsSupported() { 20 bool FileSystemWatcher::IsSupported() {
20 return true; 21 return true;
21 } 22 }
22 23
23 24
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 USE(path_id); 64 USE(path_id);
64 return id; 65 return id;
65 } 66 }
66 67
67 68
68 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) { 69 Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
69 USE(path_id); 70 USE(path_id);
70 const intptr_t kEventSize = sizeof(struct inotify_event); 71 const intptr_t kEventSize = sizeof(struct inotify_event);
71 const intptr_t kBufferSize = kEventSize + NAME_MAX + 1; 72 const intptr_t kBufferSize = kEventSize + NAME_MAX + 1;
72 uint8_t buffer[kBufferSize]; 73 uint8_t buffer[kBufferSize];
73 intptr_t bytes = TEMP_FAILURE_RETRY(read(id, buffer, kBufferSize)); 74 intptr_t bytes = Socket::Read(id, buffer, kBufferSize);
74 if (bytes < 0) { 75 if (bytes < 0) {
75 return DartUtils::NewDartOSError(); 76 return DartUtils::NewDartOSError();
76 } 77 }
77 const intptr_t kMaxCount = bytes / kEventSize; 78 const intptr_t kMaxCount = bytes / kEventSize;
78 Dart_Handle events = Dart_NewList(kMaxCount); 79 Dart_Handle events = Dart_NewList(kMaxCount);
79 intptr_t offset = 0; 80 intptr_t offset = 0;
80 intptr_t i = 0; 81 intptr_t i = 0;
81 while (offset < bytes) { 82 while (offset < bytes) {
82 struct inotify_event* e = 83 struct inotify_event* e =
83 reinterpret_cast<struct inotify_event*>(buffer + offset); 84 reinterpret_cast<struct inotify_event*>(buffer + offset);
(...skipping 24 matching lines...) Expand all
108 } 109 }
109 ASSERT(offset == bytes); 110 ASSERT(offset == bytes);
110 return events; 111 return events;
111 } 112 }
112 113
113 } // namespace bin 114 } // namespace bin
114 } // namespace dart 115 } // namespace dart
115 116
116 #endif // defined(TARGET_OS_LINUX) 117 #endif // defined(TARGET_OS_LINUX)
117 118
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698