switch (state) {
case TCP_STATE_ACCEPTING: {
long time_left;
MultiTimerData mtd = null, omtd = null;
ERef monitor;
if ((monitor = driver_monitor_process(caller)) == null) {
return ctl_xerror(NOPROC);
}
AsyncOp op = deq_async_w_tmo();
if (op.timeout != INET_INFINITY) {
time_left = driver_read_timer();
driver_cancel_timer();
if (time_left <= 0) {
time_left = 1;
}
omtd = add_multi_timer(op.caller, time_left);
}
enq_old_multi_op(op, omtd);
if (timeout != INET_INFINITY) {
mtd = add_multi_timer(caller, timeout);
}
short id = enq_multi_op(TCP_REQ_ACCEPT, caller, mtd, monitor);
byte[] data = new byte[2];
data[0] = (byte) (id >>> 8);
data[1] = (byte) (id & 0xff);
state = TCP_STATE_MULTI_ACCEPTING;
return ctl_reply(INET_REP_OK, data);
}
// break;
case TCP_STATE_MULTI_ACCEPTING:
{
MultiTimerData mtd = null, omtd = null;
ERef monitor;
if ((monitor = driver_monitor_process(caller)) == null) {
return ctl_xerror(NOPROC);
}
if (timeout != INET_INFINITY) {
mtd = add_multi_timer(caller, timeout);
}
short id = enq_multi_op(TCP_REQ_ACCEPT, caller, mtd, monitor);
byte[] data = new byte[2];
data[0] = (byte) (id >>> 8);
data[1] = (byte) (id & 0xff);
return ctl_reply(INET_REP_OK, data);
}
// break;
case TCP_STATE_LISTEN:
ByteBuffer reply = ByteBuffer.allocate(2);
InetSocket sock;
try {
sock = fd.accept();
} catch (IOException e) {
return ctl_error(IO.exception_to_posix_code(e));
}
if (sock == null) {
// async ...
ERef monitor = driver_monitor_process(caller);
if (monitor == null) {
return ctl_xerror(NOPROC);
}
enq_async_w_tmo(caller, reply, TCP_REQ_ACCEPT, timeout, monitor);
state = TCP_STATE_ACCEPTING;