OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 define("mojo/public/js/bindings/connector", [ | 5 define("mojo/public/js/bindings/connector", [ |
6 "mojo/public/js/bindings/codec", | 6 "mojo/public/js/bindings/codec", |
7 "mojo/public/js/bindings/core", | 7 "mojo/public/js/bindings/core", |
8 "mojo/public/js/bindings/support", | 8 "mojo/public/js/bindings/support", |
9 ], function(codec, core, support) { | 9 ], function(codec, core, support) { |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 Connector.prototype.setErrorHandler = function(handler) { | 70 Connector.prototype.setErrorHandler = function(handler) { |
71 this.errorHandler_ = handler; | 71 this.errorHandler_ = handler; |
72 }; | 72 }; |
73 | 73 |
74 Connector.prototype.encounteredError = function() { | 74 Connector.prototype.encounteredError = function() { |
75 return this.error_; | 75 return this.error_; |
76 }; | 76 }; |
77 | 77 |
78 Connector.prototype.waitToReadMore_ = function() { | 78 Connector.prototype.waitToReadMore_ = function() { |
79 this.readWaitCookie_ = support.asyncWait(this.handle_, | 79 this.readWaitCookie_ = support.asyncWait(this.handle_, |
80 core.WAIT_FLAG_READABLE, | 80 core.HANDLE_SIGNAL_READABLE, |
81 this.readMore_.bind(this)); | 81 this.readMore_.bind(this)); |
82 }; | 82 }; |
83 | 83 |
84 Connector.prototype.readMore_ = function(result) { | 84 Connector.prototype.readMore_ = function(result) { |
85 for (;;) { | 85 for (;;) { |
86 var read = core.readMessage(this.handle_, | 86 var read = core.readMessage(this.handle_, |
87 core.READ_MESSAGE_FLAG_NONE); | 87 core.READ_MESSAGE_FLAG_NONE); |
88 if (read.result == core.RESULT_SHOULD_WAIT) { | 88 if (read.result == core.RESULT_SHOULD_WAIT) { |
89 this.waitToReadMore_(); | 89 this.waitToReadMore_(); |
90 return; | 90 return; |
91 } | 91 } |
92 if (read.result != core.RESULT_OK) { | 92 if (read.result != core.RESULT_OK) { |
93 this.error_ = true; | 93 this.error_ = true; |
94 if (this.errorHandler_) | 94 if (this.errorHandler_) |
95 this.errorHandler_.onError(read.result); | 95 this.errorHandler_.onError(read.result); |
96 return; | 96 return; |
97 } | 97 } |
98 var buffer = new codec.Buffer(read.buffer); | 98 var buffer = new codec.Buffer(read.buffer); |
99 var message = new codec.Message(buffer, read.handles); | 99 var message = new codec.Message(buffer, read.handles); |
100 if (this.incomingReceiver_) { | 100 if (this.incomingReceiver_) { |
101 this.incomingReceiver_.accept(message); | 101 this.incomingReceiver_.accept(message); |
102 } | 102 } |
103 } | 103 } |
104 }; | 104 }; |
105 | 105 |
106 var exports = {}; | 106 var exports = {}; |
107 exports.Connector = Connector; | 107 exports.Connector = Connector; |
108 return exports; | 108 return exports; |
109 }); | 109 }); |
OLD | NEW |