}
private Buffer buffer = new Buffer();
public int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException {
Buffer incoming = new Buffer(buf, start, len);
// If we already have partial data, we need to append it to the buffer and use it
if (buffer.available() > 0) {
buffer.putBuffer(incoming);
incoming = buffer;
}
// Process commands
int rpos = incoming.rpos();
while (receive(incoming));
int read = incoming.rpos() - rpos;
// Compact and add remaining data
buffer.compact();
if (buffer != incoming && incoming.available() > 0) {
buffer.putBuffer(incoming);
}
return read;
}