InetSocketAddress remote = (InetSocketAddress)conn.getRemoteSocketAddress();
Log.info(this, "connection from "+remote.getHostName()+":"+remote.getPort()+" ("+remote.getAddress()+")");
conversation = new PrintWriter(new OutputStreamWriter(new FileOutputStream(convdir + File.separatorChar + cid + ".txt")));
- boolean ret = handleRequest();
- Log.setThreadAnnotation("");
- conversation.close();
+ boolean ret = false;
+ try {
+ ret = handleRequest();
+ Log.setThreadAnnotation("");
+ } finally {
+ conversation.close();
+ }
return ret;
}
protected void println(String s) throws IOException {
+ if (inbound.length() > 0) { conversation.println("C: " + inbound.toString()); inbound.setLength(0); }
conversation.println("S: " + s);
+ conversation.flush();
pw.print(s);
pw.print("\r\n");
pw.flush();
protected String readln() throws IOException {
String line = lr.readLine();
conversation.println("C: " + line);
+ conversation.flush();
return line;
}
public char getc() throws IOException {
int ret = r.read();
if (ret == -1) throw new EOFException();
- if (ret == '\n') { if (inbound.length() > 0) { conversation.println("C: " + inbound.toString()); inbound.setLength(0); } }
+ if (ret == '\n') {
+ if (inbound.length() > 0) { conversation.println("C: " + inbound.toString()); inbound.setLength(0); } }
else if (ret != '\r') inbound.append((char)ret);
+ conversation.flush();
return (char)ret;
}
public char peekc() throws IOException {