private boolean send() throws IOException { try { return reply.send(cio); } catch (IOException x) { if (x.getMessage().startsWith("Resource temporarily")) { System.err.println("## RTA"); return true; } throw x; } }
public void handle(SelectionKey sk) throws IOException { try { if (request == null) { if (!receive(sk)) return; rbb.flip(); if (parse()) build(); try { reply.prepare(); } catch (IOException x) { reply.release(); reply = new Reply(Reply.Code.NOT_FOUND, new StringContent(x)); reply.prepare(); } if (send()) { // More bytes remain to be written sk.interestOps(SelectionKey.OP_WRITE); } else { // Reply completely written; we're done if (cio.shutdown()) { cio.close(); reply.release(); } } } else { if (!send()) { // Should be rp.send() if (cio.shutdown()) { cio.close(); reply.release(); } } } } catch (IOException x) { String m = x.getMessage(); if (!m.equals("Broken pipe") && !m.equals("Connection reset by peer")) { System.err.println("RequestHandler: " + x.toString()); } try { /* * We had a failure here, so we'll try to be nice * before closing down and send off a close_notify, * but if we can't get the message off with one try, * we'll just shutdown. */ cio.shutdown(); } catch (IOException e) { // ignore } cio.close(); if (reply != null) { reply.release(); } } }