Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
315577e
fix exeptions when RMI non-void method executed so long that 64 new m…
Jun 12, 2015
ba4cf39
fix exceptions when server reads messages some slower than client writes
Jun 14, 2015
7730430
Each Kryo instance now has separate methodCache
Jun 14, 2015
3d0112f
fix building remote methods cache, update kryo version, concurrent in…
Mar 14, 2018
3fcc194
Merge pull request #2 from EsotericSoftware/master
asoboll Mar 14, 2018
33a0052
add copyright
Mar 14, 2018
637937a
Merge branch 'merge_with_esoteric' to master
Mar 14, 2018
dbeabca
Merge branch 'master' into fix_multithreaded_invocations_exceptions
Mar 14, 2018
15e9c8f
simplified test
Mar 15, 2018
a4ffae8
response id possible collision fix
Apr 3, 2018
d8ed136
response id possible collision fix (2)
Apr 3, 2018
3f7e84c
64 parallel remote invocations allowed
Apr 3, 2018
4d88593
response id collision example test
Apr 3, 2018
219ba41
Merge branch 'responseId_collision_test' into responseId_collision_fix
Apr 3, 2018
4027172
style fix
Apr 3, 2018
6066d6e
fixed very rare bug when waiting for wrong responseId
asoboll Jul 3, 2018
3427a77
add dsx version suffix
pchertalev Jul 13, 2018
ef31e53
Check on connect that both client and server has equals registered cl…
Jun 10, 2019
f308dc9
Switch "Check on connect that both client and server has equals regis…
Jun 10, 2019
37435ee
Ignore unstable tests
Jun 10, 2019
f492ba8
Set deploy dsx-2 to nexus
Jun 10, 2019
222365b
Set deploy "dsx" master to nexus
Jun 10, 2019
f8c2dcf
Merge branch 'master' into dsx-2
ai-dsxt Jun 19, 2019
a4b2eda
Merge pull request #3 from dsx-tech/dsx-2
ai-dsxt Jun 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@

<dependencies>
<dependency>
<groupId>com.esotericsoftware.kryo</groupId>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>2.24.0</version>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
Expand Down
21 changes: 19 additions & 2 deletions src/com/esotericsoftware/kryonet/TcpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ class TcpConnection {
private volatile long lastWriteTime, lastReadTime;
private int currentObjectLength;
private final Object writeLock = new Object();
private final int objectBufferSize;
private final int lengthLength;

public TcpConnection (Serialization serialization, int writeBufferSize, int objectBufferSize) {
this.serialization = serialization;
writeBuffer = ByteBuffer.allocate(writeBufferSize);
this.objectBufferSize = objectBufferSize;
lengthLength = serialization.getLengthLength();
writeBuffer = ByteBuffer.allocate(Math.max(writeBufferSize, lengthLength + objectBufferSize));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the write buffer size that was passed in?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because bufferSize >= lengthLength + objectSize must be true in all cases.
If it is not so, user has entered incorrect values. We can react on that two ways:
first - throw an exception, second - use max(bufferSize, lengthLength + objectSize).
We have chosen second one, but we can change to exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I prefer an exception to using a buffer size other than what was specified.

readBuffer = ByteBuffer.allocate(objectBufferSize);
readBuffer.flip();
}
Expand Down Expand Up @@ -199,8 +203,21 @@ public int send (Connection connection, Object object) throws IOException {
SocketChannel socketChannel = this.socketChannel;
if (socketChannel == null) throw new SocketException("Connection is closed.");
synchronized (writeLock) {
int start = writeBuffer.position();
int lengthLength = serialization.getLengthLength();

//wait while buffer has enough free space.
//thats because message length will be put only after the whole message will be serialized
while (writeBuffer.capacity() < writeBuffer.position() + lengthLength + objectBufferSize) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
break;
}
writeToSocket();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't just sleep the writing thread, this would have to be a feature, disabled by default. The right way to handle this is to not send data so fast or to use a larger buffer.

Comment should be "wait until buffer".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pass 0 as value of objectSize, feature will be disabled. We can set 0 as default value.

Concerning "The right way", it's the matter of dispute. If so user should select unique buffer size for each system installation on different computers, in different configurations and so on. Or make buffer too large to avoid problems that are very rare.


// Leave room for length.
int start = writeBuffer.position();
try {
// Leave room for length.
writeBuffer.position(writeBuffer.position() + lengthLength);
Expand Down
Loading