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

Side by Side Diff: samples/chat/chat_server_lib.dart

Issue 9500002: Rename blahHandler to onBlah throughout dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/string_stream.dart ('k') | samples/chat/chat_stress_client.dart » ('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 #library("chat_server"); 5 #library("chat_server");
6 #import("dart:io"); 6 #import("dart:io");
7 #import("dart:isolate"); 7 #import("dart:isolate");
8 #import("dart:json"); 8 #import("dart:json");
9 9
10 typedef void RequestHandler(HttpRequest request, HttpResponse response); 10 typedef void RequestHandler(HttpRequest request, HttpResponse response);
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 response.contentLength = 0; 402 response.contentLength = 0;
403 response.outputStream.close(); 403 response.outputStream.close();
404 } 404 }
405 405
406 // Join request: 406 // Join request:
407 // { "request": "join", 407 // { "request": "join",
408 // "handle": <handle> } 408 // "handle": <handle> }
409 void _joinHandler(HttpRequest request, HttpResponse response) { 409 void _joinHandler(HttpRequest request, HttpResponse response) {
410 StringBuffer body = new StringBuffer(); 410 StringBuffer body = new StringBuffer();
411 StringInputStream input = new StringInputStream(request.inputStream); 411 StringInputStream input = new StringInputStream(request.inputStream);
412 input.dataHandler = () => body.add(input.read()); 412 input.onData = () => body.add(input.read());
413 input.closeHandler = () { 413 input.onClosed = () {
414 String data = body.toString(); 414 String data = body.toString();
415 if (data != null) { 415 if (data != null) {
416 var requestData = JSON.parse(data); 416 var requestData = JSON.parse(data);
417 if (requestData["request"] == "join") { 417 if (requestData["request"] == "join") {
418 String handle = requestData["handle"]; 418 String handle = requestData["handle"];
419 if (handle != null) { 419 if (handle != null) {
420 // New user joining. 420 // New user joining.
421 User user = _topic._userJoined(handle); 421 User user = _topic._userJoined(handle);
422 422
423 // Send response. 423 // Send response.
(...skipping 12 matching lines...) Expand all
436 } 436 }
437 }; 437 };
438 } 438 }
439 439
440 // Leave request: 440 // Leave request:
441 // { "request": "leave", 441 // { "request": "leave",
442 // "sessionId": <sessionId> } 442 // "sessionId": <sessionId> }
443 void _leaveHandler(HttpRequest request, HttpResponse response) { 443 void _leaveHandler(HttpRequest request, HttpResponse response) {
444 StringBuffer body = new StringBuffer(); 444 StringBuffer body = new StringBuffer();
445 StringInputStream input = new StringInputStream(request.inputStream); 445 StringInputStream input = new StringInputStream(request.inputStream);
446 input.dataHandler = () => body.add(input.read()); 446 input.onData = () => body.add(input.read());
447 input.closeHandler = () { 447 input.onClosed = () {
448 String data = body.toString(); 448 String data = body.toString();
449 var requestData = JSON.parse(data); 449 var requestData = JSON.parse(data);
450 if (requestData["request"] == "leave") { 450 if (requestData["request"] == "leave") {
451 String sessionId = requestData["sessionId"]; 451 String sessionId = requestData["sessionId"];
452 if (sessionId != null) { 452 if (sessionId != null) {
453 // User leaving. 453 // User leaving.
454 _topic._userLeft(sessionId); 454 _topic._userLeft(sessionId);
455 455
456 // Send response. 456 // Send response.
457 Map responseData = new Map(); 457 Map responseData = new Map();
458 responseData["response"] = "leave"; 458 responseData["response"] = "leave";
459 _sendJSONResponse(response, responseData); 459 _sendJSONResponse(response, responseData);
460 } else { 460 } else {
461 _protocolError(request, response); 461 _protocolError(request, response);
462 } 462 }
463 } else { 463 } else {
464 _protocolError(request, response); 464 _protocolError(request, response);
465 } 465 }
466 }; 466 };
467 } 467 }
468 468
469 // Message request: 469 // Message request:
470 // { "request": "message", 470 // { "request": "message",
471 // "sessionId": <sessionId>, 471 // "sessionId": <sessionId>,
472 // "message": <message> } 472 // "message": <message> }
473 void _messageHandler(HttpRequest request, HttpResponse response) { 473 void _messageHandler(HttpRequest request, HttpResponse response) {
474 StringBuffer body = new StringBuffer(); 474 StringBuffer body = new StringBuffer();
475 StringInputStream input = new StringInputStream(request.inputStream); 475 StringInputStream input = new StringInputStream(request.inputStream);
476 input.dataHandler = () => body.add(input.read()); 476 input.onData = () => body.add(input.read());
477 input.closeHandler = () { 477 input.onClosed = () {
478 String data = body.toString(); 478 String data = body.toString();
479 _messageCount++; 479 _messageCount++;
480 _messageRate.record(1); 480 _messageRate.record(1);
481 var requestData = JSON.parse(data); 481 var requestData = JSON.parse(data);
482 if (requestData["request"] == "message") { 482 if (requestData["request"] == "message") {
483 String sessionId = requestData["sessionId"]; 483 String sessionId = requestData["sessionId"];
484 if (sessionId != null) { 484 if (sessionId != null) {
485 // New message from user. 485 // New message from user.
486 bool success = _topic._userMessage(requestData); 486 bool success = _topic._userMessage(requestData);
487 487
(...skipping 15 matching lines...) Expand all
503 } 503 }
504 504
505 // Receive request: 505 // Receive request:
506 // { "request": "receive", 506 // { "request": "receive",
507 // "sessionId": <sessionId>, 507 // "sessionId": <sessionId>,
508 // "nextMessage": <nextMessage>, 508 // "nextMessage": <nextMessage>,
509 // "maxMessages": <maxMesssages> } 509 // "maxMessages": <maxMesssages> }
510 void _receiveHandler(HttpRequest request, HttpResponse response) { 510 void _receiveHandler(HttpRequest request, HttpResponse response) {
511 StringBuffer body = new StringBuffer(); 511 StringBuffer body = new StringBuffer();
512 StringInputStream input = new StringInputStream(request.inputStream); 512 StringInputStream input = new StringInputStream(request.inputStream);
513 input.dataHandler = () => body.add(input.read()); 513 input.onData = () => body.add(input.read());
514 input.closeHandler = () { 514 input.onClosed = () {
515 String data = body.toString(); 515 String data = body.toString();
516 var requestData = JSON.parse(data); 516 var requestData = JSON.parse(data);
517 if (requestData["request"] == "receive") { 517 if (requestData["request"] == "receive") {
518 String sessionId = requestData["sessionId"]; 518 String sessionId = requestData["sessionId"];
519 int nextMessage = requestData["nextMessage"]; 519 int nextMessage = requestData["nextMessage"];
520 int maxMessages = requestData["maxMessages"]; 520 int maxMessages = requestData["maxMessages"];
521 if (sessionId != null && nextMessage != null) { 521 if (sessionId != null && nextMessage != null) {
522 522
523 void sendResponse(messages) { 523 void sendResponse(messages) {
524 // Send response. 524 // Send response.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 580
581 this.port.receive((var message, SendPort replyTo) { 581 this.port.receive((var message, SendPort replyTo) {
582 if (message.isStart) { 582 if (message.isStart) {
583 _host = message.host; 583 _host = message.host;
584 _port = message.port; 584 _port = message.port;
585 _logging = message.logging; 585 _logging = message.logging;
586 replyTo.send(new ChatServerStatus.starting(), null); 586 replyTo.send(new ChatServerStatus.starting(), null);
587 _server = new HttpServer(); 587 _server = new HttpServer();
588 try { 588 try {
589 _server.listen(_host, _port, backlog: message.backlog); 589 _server.listen(_host, _port, backlog: message.backlog);
590 _server.requestHandler = (HttpRequest req, HttpResponse rsp) => 590 _server.onRequest = (HttpRequest req, HttpResponse rsp) =>
591 _requestReceivedHandler(req, rsp); 591 _requestReceivedHandler(req, rsp);
592 replyTo.send(new ChatServerStatus.started(_server.port), null); 592 replyTo.send(new ChatServerStatus.started(_server.port), null);
593 _loggingTimer = new Timer.repeating(_handleLogging, 1000); 593 _loggingTimer = new Timer.repeating(_handleLogging, 1000);
594 } catch (var e) { 594 } catch (var e) {
595 replyTo.send(new ChatServerStatus.error(e.toString()), null); 595 replyTo.send(new ChatServerStatus.error(e.toString()), null);
596 } 596 }
597 } else if (message.isStop) { 597 } else if (message.isStop) {
598 replyTo.send(new ChatServerStatus.stopping(), null); 598 replyTo.send(new ChatServerStatus.stopping(), null);
599 stop(); 599 stop();
600 replyTo.send(new ChatServerStatus.stopped(), null); 600 replyTo.send(new ChatServerStatus.stopped(), null);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 } 709 }
710 } 710 }
711 711
712 int _timeRange; 712 int _timeRange;
713 List<int> _buckets; 713 List<int> _buckets;
714 int _currentBucket; 714 int _currentBucket;
715 int _currentBucketTime; 715 int _currentBucketTime;
716 num _bucketTimeRange; 716 num _bucketTimeRange;
717 int _sum; 717 int _sum;
718 } 718 }
OLDNEW
« no previous file with comments | « runtime/bin/string_stream.dart ('k') | samples/chat/chat_stress_client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698