Skip to content

Commit 08b1b52

Browse files
committed
[1.6.6] Fix bug with chunked data not being processed.
Signed-off-by: Jacob Glickman <[email protected]>
1 parent 2bf41e9 commit 08b1b52

File tree

8 files changed

+66
-60
lines changed

8 files changed

+66
-60
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ Maven:
1111
<dependency>
1212
<groupId>com.github.jhg023</groupId>
1313
<artifactId>SimpleNet</artifactId>
14-
<version>1.6.5</version>
14+
<version>1.6.6</version>
1515
</dependency>
1616
```
1717

1818
Gradle:
1919

2020
```groovy
21-
implementation 'com.github.jhg023:SimpleNet:1.6.5'
21+
implementation 'com.github.jhg023:SimpleNet:1.6.6'
2222
```
2323

2424
2. Because SimpleNet is compiled with Java 11, you must first require its module in your `module-info.java`:

pom.xml

+36-32
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.jhg023</groupId>
88
<artifactId>SimpleNet</artifactId>
9-
<version>1.6.5</version>
9+
<version>1.6.6</version>
1010

1111
<name>SimpleNet</name>
1212
<description>An easy-to-use, event-driven, asynchronous, network application framework compiled with Java 11.</description>
@@ -48,14 +48,14 @@
4848
<properties>
4949
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5050
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
51-
<junit.jupiter.version>5.6.0</junit.jupiter.version>
51+
<junit.jupiter.version>5.6.2</junit.jupiter.version>
5252
</properties>
5353

5454
<dependencies>
5555
<dependency>
5656
<groupId>com.github.jhg023</groupId>
5757
<artifactId>Pbbl</artifactId>
58-
<version>1.0.1</version>
58+
<version>1.0.2</version>
5959
</dependency>
6060
<dependency>
6161
<groupId>org.junit.jupiter</groupId>
@@ -86,17 +86,8 @@
8686
<plugins>
8787
<plugin>
8888
<groupId>org.apache.maven.plugins</groupId>
89-
<artifactId>maven-compiler-plugin</artifactId>
90-
<version>3.8.1</version>
91-
<configuration>
92-
<source>11</source>
93-
<target>11</target>
94-
<compilerArgument>-Xlint</compilerArgument>
95-
</configuration>
96-
</plugin>
97-
<plugin>
9889
<artifactId>maven-assembly-plugin</artifactId>
99-
<version>3.2.0</version>
90+
<version>3.3.0</version>
10091
<configuration>
10192
<descriptorRefs>
10293
<descriptorRef>jar-with-dependencies</descriptorRef>
@@ -115,33 +106,33 @@
115106
</executions>
116107
</plugin>
117108
<plugin>
118-
<groupId>org.sonatype.plugins</groupId>
119-
<artifactId>nexus-staging-maven-plugin</artifactId>
120-
<version>1.6.8</version>
121-
<extensions>true</extensions>
109+
<groupId>org.apache.maven.plugins</groupId>
110+
<artifactId>maven-compiler-plugin</artifactId>
111+
<version>3.8.1</version>
122112
<configuration>
123-
<serverId>ossrh</serverId>
124-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
125-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
113+
<source>11</source>
114+
<target>11</target>
115+
<compilerArgument>-Xlint</compilerArgument>
126116
</configuration>
127117
</plugin>
128118
<plugin>
129119
<groupId>org.apache.maven.plugins</groupId>
130-
<artifactId>maven-source-plugin</artifactId>
131-
<version>3.2.1</version>
120+
<artifactId>maven-gpg-plugin</artifactId>
121+
<version>1.6</version>
132122
<executions>
133123
<execution>
134-
<id>attach-sources</id>
124+
<id>sign-artifacts</id>
125+
<phase>verify</phase>
135126
<goals>
136-
<goal>jar-no-fork</goal>
127+
<goal>sign</goal>
137128
</goals>
138129
</execution>
139130
</executions>
140131
</plugin>
141132
<plugin>
142133
<groupId>org.apache.maven.plugins</groupId>
143134
<artifactId>maven-javadoc-plugin</artifactId>
144-
<version>3.1.1</version>
135+
<version>3.2.0</version>
145136
<executions>
146137
<execution>
147138
<id>attach-javadocs</id>
@@ -154,7 +145,7 @@
154145
<dependency>
155146
<groupId>org.ow2.asm</groupId>
156147
<artifactId>asm</artifactId>
157-
<version>7.3.1</version>
148+
<version>8.0.1</version>
158149
</dependency>
159150
</dependencies>
160151
<configuration>
@@ -163,22 +154,35 @@
163154
</plugin>
164155
<plugin>
165156
<groupId>org.apache.maven.plugins</groupId>
166-
<artifactId>maven-gpg-plugin</artifactId>
167-
<version>1.6</version>
157+
<artifactId>maven-source-plugin</artifactId>
158+
<version>3.2.1</version>
168159
<executions>
169160
<execution>
170-
<id>sign-artifacts</id>
171-
<phase>verify</phase>
161+
<id>attach-sources</id>
172162
<goals>
173-
<goal>sign</goal>
163+
<goal>jar-no-fork</goal>
174164
</goals>
175165
</execution>
176166
</executions>
177167
</plugin>
178168
<plugin>
179169
<groupId>org.apache.maven.plugins</groupId>
180170
<artifactId>maven-surefire-plugin</artifactId>
181-
<version>3.0.0-M4</version>
171+
<version>3.0.0-M5</version>
172+
<configuration>
173+
<argLine>--add-opens com.github.simplenet/com.github.simplenet=ALL-UNNAMED</argLine>
174+
</configuration>
175+
</plugin>
176+
<plugin>
177+
<groupId>org.sonatype.plugins</groupId>
178+
<artifactId>nexus-staging-maven-plugin</artifactId>
179+
<version>1.6.8</version>
180+
<extensions>true</extensions>
181+
<configuration>
182+
<serverId>ossrh</serverId>
183+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
184+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
185+
</configuration>
182186
</plugin>
183187
</plugins>
184188
</build>

src/main/java/com/github/simplenet/Client.java

+21-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
package com.github.simplenet;
2525

26+
import com.github.pbbl.AbstractBufferPool;
27+
import com.github.pbbl.direct.DirectByteBufferPool;
2628
import com.github.simplenet.packet.Packet;
2729
import com.github.simplenet.utility.IntPair;
2830
import com.github.simplenet.utility.MutableBoolean;
@@ -39,8 +41,6 @@
3941
import com.github.simplenet.utility.exposed.data.StringReader;
4042
import org.slf4j.Logger;
4143
import org.slf4j.LoggerFactory;
42-
import pbbl.ByteBufferPool;
43-
import pbbl.direct.DirectByteBufferPool;
4444

4545
import javax.crypto.Cipher;
4646
import java.io.IOException;
@@ -158,18 +158,24 @@ public void completed(Integer result, Pair<Client, ByteBuffer> pair) {
158158

159159
client.inCallback.set(false);
160160

161-
// The buffer that was used must be returned to the pool.
162-
DIRECT_BUFFER_POOL.give(buffer);
163-
164-
if (queueIsEmpty) {
165-
// Because the queue is empty, the client should not attempt to read more data until
166-
// more is requested by the user.
167-
client.readInProgress.set(false);
161+
// If the queue is not empty and there exists remaining data in the buffer, then that means
162+
// that we haven't received all of the requested data, and must re-use the same buffer.
163+
if (!queueIsEmpty && buffer.hasRemaining()) {
164+
client.channel.read(buffer.position(buffer.limit()).limit(key), pair, this);
168165
} else {
169-
// Because the queue is NOT empty and we don't have enough data to process the request,
170-
// we must read more data.
171-
var newBuffer = DIRECT_BUFFER_POOL.take(peek.getKey());
172-
client.channel.read(newBuffer, new Pair<>(client, newBuffer), this);
166+
// The buffer that was used must be returned to the pool.
167+
DIRECT_BUFFER_POOL.give(buffer);
168+
169+
if (queueIsEmpty) {
170+
// Because the queue is empty, the client should not attempt to read more data until
171+
// more is requested by the user.
172+
client.readInProgress.set(false);
173+
} else {
174+
// Because the queue is NOT empty and we don't have enough data to process the request,
175+
// we must read more data.
176+
var newBuffer = DIRECT_BUFFER_POOL.take(peek.getKey());
177+
client.channel.read(newBuffer, new Pair<>(client, newBuffer), this);
178+
}
173179
}
174180
}
175181
}
@@ -222,9 +228,9 @@ public void failed(Throwable t, ByteBuffer buffer) {
222228
};
223229

224230
/**
225-
* A {@link ByteBufferPool} that dispatches reusable {@code DirectByteBuffer}s.
231+
* An {@link AbstractBufferPool<ByteBuffer>} that dispatches reusable, direct {@code ByteBuffer} objects.
226232
*/
227-
private static final ByteBufferPool DIRECT_BUFFER_POOL = new DirectByteBufferPool();
233+
private static final AbstractBufferPool<ByteBuffer> DIRECT_BUFFER_POOL = new DirectByteBufferPool();
228234

229235
/**
230236
* A {@link MutableBoolean} that keeps track of whether or not the executing code is inside a callback.

src/main/java/module-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module com.github.simplenet {
22
requires org.slf4j;
3-
requires Pbbl;
3+
requires com.github.pbbl;
44

55
exports com.github.simplenet;
66
exports com.github.simplenet.packet;

src/test/java/ConnectionTest.java renamed to src/test/java/com/github/simplenet/ConnectionTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
package com.github.simplenet;/*
22
* MIT License
33
*
44
* Copyright (c) 2020 Jacob Glickman
@@ -21,8 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
import com.github.simplenet.Client;
25-
import com.github.simplenet.Server;
24+
2625
import org.junit.jupiter.api.AfterEach;
2726
import org.junit.jupiter.api.BeforeEach;
2827
import org.junit.jupiter.api.Test;

src/test/java/EncryptionTest.java renamed to src/test/java/com/github/simplenet/EncryptionTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
package com.github.simplenet;/*
22
* MIT License
33
*
44
* Copyright (c) 2020 Jacob Glickman
@@ -21,8 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
import com.github.simplenet.Client;
25-
import com.github.simplenet.Server;
24+
2625
import com.github.simplenet.packet.Packet;
2726
import com.github.simplenet.utility.exposed.cryptography.CryptographicFunction;
2827
import org.junit.jupiter.api.AfterEach;

src/test/java/PacketTest.java renamed to src/test/java/com/github/simplenet/PacketTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
package com.github.simplenet;/*
22
* MIT License
33
*
44
* Copyright (c) 2020 Jacob Glickman

src/test/java/ReadTest.java renamed to src/test/java/com/github/simplenet/ReadTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
package com.github.simplenet;/*
22
* MIT License
33
*
44
* Copyright (c) 2020 Jacob Glickman
@@ -22,8 +22,6 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import com.github.simplenet.Client;
26-
import com.github.simplenet.Server;
2725
import com.github.simplenet.packet.Packet;
2826
import org.junit.jupiter.api.AfterEach;
2927
import org.junit.jupiter.api.BeforeEach;

0 commit comments

Comments
 (0)