提交 0a04addf authored 作者: Thomas Mueller's avatar Thomas Mueller

TCP server: when using the trace option ("-trace"), the trace output contained…

TCP server: when using the trace option ("-trace"), the trace output contained unnecessary stack traces when stopping the server.
上级 ebdae507
...@@ -199,8 +199,10 @@ public class TcpServerThread implements Runnable { ...@@ -199,8 +199,10 @@ public class TcpServerThread implements Runnable {
} }
transfer.writeInt(SessionRemote.STATUS_ERROR).writeString(e.getSQLState()).writeString(message) transfer.writeInt(SessionRemote.STATUS_ERROR).writeString(e.getSQLState()).writeString(message)
.writeString(sql).writeInt(e.getErrorCode()).writeString(trace).flush(); .writeString(sql).writeInt(e.getErrorCode()).writeString(trace).flush();
} catch (IOException e2) { } catch (Exception e2) {
if (!transfer.isClosed()) {
server.traceError(e2); server.traceError(e2);
}
// if writing the error does not work, close the connection // if writing the error does not work, close the connection
stop = true; stop = true;
} }
......
...@@ -73,10 +73,12 @@ public class Transfer { ...@@ -73,10 +73,12 @@ public class Transfer {
* Initialize the transfer object. This method will try to open an input and * Initialize the transfer object. This method will try to open an input and
* output stream. * output stream.
*/ */
public void init() throws IOException { public synchronized void init() throws IOException {
if (socket != null) {
in = new DataInputStream(new BufferedInputStream(socket.getInputStream(), Transfer.BUFFER_SIZE)); in = new DataInputStream(new BufferedInputStream(socket.getInputStream(), Transfer.BUFFER_SIZE));
out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream(), Transfer.BUFFER_SIZE)); out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream(), Transfer.BUFFER_SIZE));
} }
}
/** /**
* Write pending changes. * Write pending changes.
...@@ -277,10 +279,12 @@ public class Transfer { ...@@ -277,10 +279,12 @@ public class Transfer {
/** /**
* Close the transfer object and the socket. * Close the transfer object and the socket.
*/ */
public void close() { public synchronized void close() {
if (socket != null) { if (socket != null) {
try { try {
if (out != null) {
out.flush(); out.flush();
}
if (socket != null) { if (socket != null) {
socket.close(); socket.close();
} }
...@@ -613,4 +617,8 @@ public class Transfer { ...@@ -613,4 +617,8 @@ public class Transfer {
this.version = version; this.version = version;
} }
public synchronized boolean isClosed() {
return socket == null || socket.isClosed();
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论