this._cb_update_state = cb_update_state;
this._debug_enabled = debug_enabled;
this._queue = ['init'];
+ this._recv_buffer = [];
+ this._recv_buffer_last = 0;
this.state = {};
}
Mpc.prototype.recv_msg = function(lines) {
curr = this._queue.shift();
this.log(0x2, 'recv: [' + curr + ']:', lines.join('\n'));
+ if (lines[0].substr(0, 4) == 'ACK ')
+ this.err(curr, lines.join('\n'));
curr = curr.split(' ');
switch (curr[0]) {
Mpc.prototype.recv = function(msg) {
/* We can get back a bunch of responses in a row, so parse them out */
- /* XXX: Do we have to handle partial reads ? like long playlists ... */
- lines = msg.split('\n');
+ var lines = this._recv_buffer = this._recv_buffer.concat(msg.split('\n'));
var i = 0;
while (i < lines.length) {
- if (lines[i] == 'OK' || lines[i].substr(0, 3) == 'OK ') {
+ if (lines[i] == 'OK' || lines[i].substr(0, 3) == 'OK ' ||
+ lines[i].substr(0, 4) == 'ACK ') {
this.recv_msg(lines.splice(0, i + 1));
i = 0;
} else
++i;
}
+
+ if (lines.length && this._recv_buffer_last != lines.length) {
+ // Keep sucking in data so long as more exists.
+ this._recv_buffer_last = lines.length;
+ this._socket.poll();
+ } else
+ this._recv_buffer_last = lines.length;
}
/*