I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 23417935 authored by BlubMail's avatar BlubMail
Browse files

writeString(String str): synchronize using socket write lock to prevent split SAM messages

parent 1f1d089f
No related branches found
No related tags found
No related merge requests found
...@@ -102,8 +102,8 @@ public abstract class SAMHandler implements Runnable { ...@@ -102,8 +102,8 @@ public abstract class SAMHandler implements Runnable {
} }
static public void writeBytes(ByteBuffer data, SocketChannel out) throws IOException { static public void writeBytes(ByteBuffer data, SocketChannel out) throws IOException {
while (data.hasRemaining()) out.write(data); while (data.hasRemaining()) out.write(data);
out.socket().getOutputStream().flush(); out.socket().getOutputStream().flush();
} }
/** /**
...@@ -124,9 +124,13 @@ public abstract class SAMHandler implements Runnable { ...@@ -124,9 +124,13 @@ public abstract class SAMHandler implements Runnable {
* @return True if the string was successfully written, false otherwise * @return True if the string was successfully written, false otherwise
*/ */
protected final boolean writeString(String str) { protected final boolean writeString(String str) {
boolean success;
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Sending the client: [" + str + "]"); _log.debug("Sending the client: [" + str + "]");
return writeString(str, socket); synchronized (socketWLock) {
success = writeString(str, socket);
}
return success;
} }
public static boolean writeString(String str, SocketChannel out) public static boolean writeString(String str, SocketChannel out)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment