rendered paste bodypackage org.jofix.ls;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import org.jofix.Server;
import com.sun.grizzly.Context;
import com.sun.grizzly.ProtocolFilter;
import com.sun.grizzly.util.WorkerThread;
public class LSProtocolFilter implements ProtocolFilter {
@Override
public boolean execute(Context context) throws IOException {
SocketChannel socket = (SocketChannel) context.getSelectionKey().channel();
LSConnection connection = Server.getLoginServer().getConnection(socket);
if(connection == null) {
socket.close();
return false;
}
WorkerThread workerThread = (WorkerThread) Thread.currentThread();
ByteBuffer buffer = workerThread.getByteBuffer();
buffer.flip();
if(buffer.hasRemaining()) {
byte[] data = new byte[buffer.remaining()];
int position = buffer.position();
buffer.get(data);
buffer.position(position);
}
connection.handleData(buffer);
buffer.clear();
return false;
}
@Override
public boolean postExecute(Context context) throws IOException {
//sent data
return false;
}
}