}
public static void handleRequest(IFunctionHandler handler, IRequestProtocol protocol, Socket socket, Session session) {
try {
XLoper nameOrVersion = protocol.receive(socket);
XLString name = null;
IFunctionContext context = null;
if (nameOrVersion.type == XLoper.xlTypeInt) {
int version = ((XLInt) nameOrVersion).w;
if (version == 20) {
XLBool b = (XLBool) protocol.receive(socket);
if (b.bool) {
XLoper caller = protocol.receive(socket);
XLoper sheetName = protocol.receive(socket);
XLSRef cref = null;
if (caller instanceof XLSRef)
cref = (XLSRef) caller;
String namestr = null;
if (sheetName instanceof XLString)
namestr = ((XLString) sheetName).str;
context = new FunctionContext(handler, session, cref, namestr);
}
} else {
protocol.send(socket, new XLString("#Unknown protocol version"));
socket.close();
return;
}
name = (XLString) protocol.receive(socket);
} else {
name = (XLString) nameOrVersion;
}
XLInt argCount = (XLInt) protocol.receive(socket);
XLoper[] args = new XLoper[argCount.w];
for (int i = 0; i < argCount.w; i++) {
args[i] = protocol.receive(socket);
}
if (!session.init && name.str.equals(INITIALIZE)) {
initializeSession(session, args);
}
if (session.init && context == null)
context = new FunctionContext(handler, session, null, null);
XLoper res = handler.execute(context, name.str, args);
if (res == null)
res = XLError.NULL;
protocol.send(socket, res);
} catch (RequestException e) {
try {
protocol.send(socket, new XLString(e.getMessage()));
} catch (IOException ex) {
System.err.println(e.getMessage());
try {
socket.close();
} catch (IOException iex) {