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

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

Issue 11312242: Revised CL for customisable logging (replacing printfs). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/eventhandler_android.cc ('k') | runtime/bin/eventhandler_macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/eventhandler.h" 5 #include "bin/eventhandler.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <pthread.h> 8 #include <pthread.h>
9 #include <stdio.h> 9 #include <stdio.h>
10 #include <string.h> 10 #include <string.h>
11 #include <sys/epoll.h> 11 #include <sys/epoll.h>
12 #include <sys/stat.h> 12 #include <sys/stat.h>
13 #include <sys/time.h> 13 #include <sys/time.h>
14 #include <unistd.h> 14 #include <unistd.h>
15 15
16 #include "bin/dartutils.h" 16 #include "bin/dartutils.h"
17 #include "bin/fdutils.h" 17 #include "bin/fdutils.h"
18 #include "bin/log.h"
18 #include "platform/hashmap.h" 19 #include "platform/hashmap.h"
19 #include "platform/thread.h" 20 #include "platform/thread.h"
20 #include "platform/utils.h" 21 #include "platform/utils.h"
21 22
22 23
23 int64_t GetCurrentTimeMilliseconds() { 24 int64_t GetCurrentTimeMilliseconds() {
24 struct timeval tv; 25 struct timeval tv;
25 if (gettimeofday(&tv, NULL) < 0) { 26 if (gettimeofday(&tv, NULL) < 0) {
26 UNREACHABLE(); 27 UNREACHABLE();
27 return 0; 28 return 0;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // Setup events to wait for. 223 // Setup events to wait for.
223 sd->SetPortAndMask(msg.dart_port, msg.data); 224 sd->SetPortAndMask(msg.dart_port, msg.data);
224 UpdateEpollInstance(epoll_fd_, sd); 225 UpdateEpollInstance(epoll_fd_, sd);
225 } 226 }
226 } 227 }
227 } 228 }
228 } 229 }
229 230
230 #ifdef DEBUG_POLL 231 #ifdef DEBUG_POLL
231 static void PrintEventMask(intptr_t fd, intptr_t events) { 232 static void PrintEventMask(intptr_t fd, intptr_t events) {
232 printf("%d ", fd); 233 Log::Print("%d ", fd);
233 if ((events & EPOLLIN) != 0) printf("EPOLLIN "); 234 if ((events & EPOLLIN) != 0) Log::Print("EPOLLIN ");
234 if ((events & EPOLLPRI) != 0) printf("EPOLLPRI "); 235 if ((events & EPOLLPRI) != 0) Log::Print("EPOLLPRI ");
235 if ((events & EPOLLOUT) != 0) printf("EPOLLOUT "); 236 if ((events & EPOLLOUT) != 0) Log::Print("EPOLLOUT ");
236 if ((events & EPOLLERR) != 0) printf("EPOLLERR "); 237 if ((events & EPOLLERR) != 0) Log::Print("EPOLLERR ");
237 if ((events & EPOLLHUP) != 0) printf("EPOLLHUP "); 238 if ((events & EPOLLHUP) != 0) Log::Print("EPOLLHUP ");
238 if ((events & EPOLLRDHUP) != 0) printf("EPOLLRDHUP "); 239 if ((events & EPOLLRDHUP) != 0) Log::Print("EPOLLRDHUP ");
239 int all_events = EPOLLIN | EPOLLPRI | EPOLLOUT | 240 int all_events = EPOLLIN | EPOLLPRI | EPOLLOUT |
240 EPOLLERR | EPOLLHUP | EPOLLRDHUP; 241 EPOLLERR | EPOLLHUP | EPOLLRDHUP;
241 if ((events & ~all_events) != 0) { 242 if ((events & ~all_events) != 0) {
242 printf("(and %08x) ", events & ~all_events); 243 Log::Print("(and %08x) ", events & ~all_events);
243 } 244 }
244 printf("(available %d) ", FDUtils::AvailableBytes(fd)); 245 Log::Print("(available %d) ", FDUtils::AvailableBytes(fd));
245 246
246 printf("\n"); 247 Log::Print("\n");
247 } 248 }
248 #endif 249 #endif
249 250
250 intptr_t EventHandlerImplementation::GetPollEvents(intptr_t events, 251 intptr_t EventHandlerImplementation::GetPollEvents(intptr_t events,
251 SocketData* sd) { 252 SocketData* sd) {
252 #ifdef DEBUG_POLL 253 #ifdef DEBUG_POLL
253 PrintEventMask(sd->fd(), events); 254 PrintEventMask(sd->fd(), events);
254 #endif 255 #endif
255 intptr_t event_mask = 0; 256 intptr_t event_mask = 0;
256 if (sd->IsListeningSocket()) { 257 if (sd->IsListeningSocket()) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // recv to peek for whether the other end of the socket 293 // recv to peek for whether the other end of the socket
293 // actually closed. 294 // actually closed.
294 char buffer; 295 char buffer;
295 ssize_t bytesPeeked = 296 ssize_t bytesPeeked =
296 TEMP_FAILURE_RETRY(recv(sd->fd(), &buffer, 1, MSG_PEEK)); 297 TEMP_FAILURE_RETRY(recv(sd->fd(), &buffer, 1, MSG_PEEK));
297 ASSERT(EAGAIN == EWOULDBLOCK); 298 ASSERT(EAGAIN == EWOULDBLOCK);
298 if (bytesPeeked == 0) { 299 if (bytesPeeked == 0) {
299 event_mask = (1 << kCloseEvent); 300 event_mask = (1 << kCloseEvent);
300 sd->MarkClosedRead(); 301 sd->MarkClosedRead();
301 } else if (errno != EWOULDBLOCK) { 302 } else if (errno != EWOULDBLOCK) {
302 fprintf(stderr, "Error recv: %s\n", strerror(errno)); 303 Log::PrintErr("Error recv: %s\n", strerror(errno));
303 } 304 }
304 } 305 }
305 } 306 }
306 } 307 }
307 308
308 // On pipes EPOLLHUP is reported without EPOLLIN when there is no 309 // On pipes EPOLLHUP is reported without EPOLLIN when there is no
309 // more data to read. 310 // more data to read.
310 if (sd->IsPipe()) { 311 if (sd->IsPipe()) {
311 if (((events & EPOLLIN) == 0) && 312 if (((events & EPOLLIN) == 0) &&
312 ((events & EPOLLHUP) != 0)) { 313 ((events & EPOLLHUP) != 0)) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) { 421 void* EventHandlerImplementation::GetHashmapKeyFromFd(intptr_t fd) {
421 // The hashmap does not support keys with value 0. 422 // The hashmap does not support keys with value 0.
422 return reinterpret_cast<void*>(fd + 1); 423 return reinterpret_cast<void*>(fd + 1);
423 } 424 }
424 425
425 426
426 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { 427 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) {
427 // The hashmap does not support keys with value 0. 428 // The hashmap does not support keys with value 0.
428 return dart::Utils::WordHash(fd + 1); 429 return dart::Utils::WordHash(fd + 1);
429 } 430 }
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_android.cc ('k') | runtime/bin/eventhandler_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698