Lines Matching full:this

106   this.file = file;
107 this.id = id;
108 this.endpoint = endpoint;
109 this.ws = null;
110 this.state = NBD_STATE_UNKNOWN;
111 this.msgbuf = null;
113 this.start = function() {
114 this.ws = new WebSocket(this.endpoint, [token]);
115 this.state = NBD_STATE_OPEN;
116 this.ws.binaryType = 'arraybuffer';
117 this.ws.onmessage = this._on_ws_message.bind(this);
118 this.ws.onopen = this._on_ws_open.bind(this);
119 this.ws.onclose = this._on_ws_close.bind(this);
120 this.ws.onerror = this._on_ws_error.bind(this);
123 this.stop = function() {
124 this.ws.close();
125 this.state = NBD_STATE_UNKNOWN;
128 this._on_ws_error = function(ev) {
132 this._on_ws_close = function(ev) {
139 this._on_ws_open = function(ev) {
141 this.client = {
144 this._negotiate();
147 this._on_ws_message = function(ev) {
150 if (this.msgbuf == null) {
151 this.msgbuf = data;
153 var tmp = new Uint8Array(this.msgbuf.byteLength + data.byteLength);
154 tmp.set(new Uint8Array(this.msgbuf), 0);
155 tmp.set(new Uint8Array(data), this.msgbuf.byteLength);
156 this.msgbuf = tmp.buffer;
160 var handler = this.recv_handlers[this.state];
162 console.log('no handler for state ' + this.state);
163 this.stop();
167 var consumed = handler(this.msgbuf);
170 'handler[state=' + this.state + '] returned error ' + consumed);
171 this.stop();
180 if (consumed == this.msgbuf.byteLength) {
181 this.msgbuf = null;
184 this.msgbuf = this.msgbuf.slice(consumed);
189 this._negotiate = function() {
204 this.state = NBD_STATE_WAIT_CFLAGS;
205 this.ws.send(buf);
209 this._handle_cflags = function(buf) {
215 this.client.flags = data.getUint32(0);
217 this.state = NBD_STATE_WAIT_OPTION;
221 this._handle_option = function(buf) {
241 if (!(this.client.flags & NBD_FLAG_NO_ZEROES)) n += 124;
245 var size = this.file.size;
250 this.ws.send(resp);
252 this.state = NBD_STATE_TRANSMISSION;
265 this.ws.send(resp);
271 this._create_cmd_response = function(req, rc, data = null) {
284 this._handle_cmd = function(buf) {
318 err = this._handle_cmd_read(req);
322 err = this._handle_cmd_disconnect(req);
346 var resp = this._create_cmd_response(req, err);
347 this.ws.send(resp);
353 this._handle_cmd_read = function(req) {
364 var blob = this.file.slice(offset, offset + req.length);
371 this._create_cmd_response(req, 0, reader.result);
372 this.ws.send(resp);
373 }).bind(this);
378 var resp = this._create_cmd_response(req, EIO);
379 this.ws.send(resp);
380 }).bind(this);
386 this._handle_cmd_disconnect = function(req) {
387 this.stop();
391 this.recv_handlers = Object.freeze({
392 [NBD_STATE_WAIT_CFLAGS]: this._handle_cflags.bind(this),
393 [NBD_STATE_WAIT_OPTION]: this._handle_option.bind(this),
394 [NBD_STATE_TRANSMISSION]: this._handle_cmd.bind(this),