Skip to content

Commit

Permalink
[1.6.6] Fix bug with chunked data not being processed.
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Glickman <[email protected]>
  • Loading branch information
jhg023 committed Aug 28, 2020
1 parent 2bf41e9 commit 08b1b52
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 60 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Maven:
<dependency>
<groupId>com.github.jhg023</groupId>
<artifactId>SimpleNet</artifactId>
<version>1.6.5</version>
<version>1.6.6</version>
</dependency>
```

Gradle:

```groovy
implementation 'com.github.jhg023:SimpleNet:1.6.5'
implementation 'com.github.jhg023:SimpleNet:1.6.6'
```

2. Because SimpleNet is compiled with Java 11, you must first require its module in your `module-info.java`:
Expand Down
68 changes: 36 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.jhg023</groupId>
<artifactId>SimpleNet</artifactId>
<version>1.6.5</version>
<version>1.6.6</version>

<name>SimpleNet</name>
<description>An easy-to-use, event-driven, asynchronous, network application framework compiled with Java 11.</description>
Expand Down Expand Up @@ -48,14 +48,14 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<junit.jupiter.version>5.6.0</junit.jupiter.version>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
</properties>

<dependencies>
<dependency>
<groupId>com.github.jhg023</groupId>
<artifactId>Pbbl</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -86,17 +86,8 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<compilerArgument>-Xlint</compilerArgument>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
Expand All @@ -115,33 +106,33 @@
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
<source>11</source>
<target>11</target>
<compilerArgument>-Xlint</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>attach-sources</id>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -154,7 +145,7 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>7.3.1</version>
<version>8.0.1</version>
</dependency>
</dependencies>
<configuration>
Expand All @@ -163,22 +154,35 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<id>attach-sources</id>
<goals>
<goal>sign</goal>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<version>3.0.0-M5</version>
<configuration>
<argLine>--add-opens com.github.simplenet/com.github.simplenet=ALL-UNNAMED</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
36 changes: 21 additions & 15 deletions src/main/java/com/github/simplenet/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package com.github.simplenet;

import com.github.pbbl.AbstractBufferPool;
import com.github.pbbl.direct.DirectByteBufferPool;
import com.github.simplenet.packet.Packet;
import com.github.simplenet.utility.IntPair;
import com.github.simplenet.utility.MutableBoolean;
Expand All @@ -39,8 +41,6 @@
import com.github.simplenet.utility.exposed.data.StringReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pbbl.ByteBufferPool;
import pbbl.direct.DirectByteBufferPool;

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

client.inCallback.set(false);

// The buffer that was used must be returned to the pool.
DIRECT_BUFFER_POOL.give(buffer);

if (queueIsEmpty) {
// Because the queue is empty, the client should not attempt to read more data until
// more is requested by the user.
client.readInProgress.set(false);
// If the queue is not empty and there exists remaining data in the buffer, then that means
// that we haven't received all of the requested data, and must re-use the same buffer.
if (!queueIsEmpty && buffer.hasRemaining()) {
client.channel.read(buffer.position(buffer.limit()).limit(key), pair, this);
} else {
// Because the queue is NOT empty and we don't have enough data to process the request,
// we must read more data.
var newBuffer = DIRECT_BUFFER_POOL.take(peek.getKey());
client.channel.read(newBuffer, new Pair<>(client, newBuffer), this);
// The buffer that was used must be returned to the pool.
DIRECT_BUFFER_POOL.give(buffer);

if (queueIsEmpty) {
// Because the queue is empty, the client should not attempt to read more data until
// more is requested by the user.
client.readInProgress.set(false);
} else {
// Because the queue is NOT empty and we don't have enough data to process the request,
// we must read more data.
var newBuffer = DIRECT_BUFFER_POOL.take(peek.getKey());
client.channel.read(newBuffer, new Pair<>(client, newBuffer), this);
}
}
}
}
Expand Down Expand Up @@ -222,9 +228,9 @@ public void failed(Throwable t, ByteBuffer buffer) {
};

/**
* A {@link ByteBufferPool} that dispatches reusable {@code DirectByteBuffer}s.
* An {@link AbstractBufferPool<ByteBuffer>} that dispatches reusable, direct {@code ByteBuffer} objects.
*/
private static final ByteBufferPool DIRECT_BUFFER_POOL = new DirectByteBufferPool();
private static final AbstractBufferPool<ByteBuffer> DIRECT_BUFFER_POOL = new DirectByteBufferPool();

/**
* A {@link MutableBoolean} that keeps track of whether or not the executing code is inside a callback.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module com.github.simplenet {
requires org.slf4j;
requires Pbbl;
requires com.github.pbbl;

exports com.github.simplenet;
exports com.github.simplenet.packet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
package com.github.simplenet;/*
* MIT License
*
* Copyright (c) 2020 Jacob Glickman
Expand All @@ -21,8 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import com.github.simplenet.Client;
import com.github.simplenet.Server;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
package com.github.simplenet;/*
* MIT License
*
* Copyright (c) 2020 Jacob Glickman
Expand All @@ -21,8 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import com.github.simplenet.Client;
import com.github.simplenet.Server;

import com.github.simplenet.packet.Packet;
import com.github.simplenet.utility.exposed.cryptography.CryptographicFunction;
import org.junit.jupiter.api.AfterEach;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
package com.github.simplenet;/*
* MIT License
*
* Copyright (c) 2020 Jacob Glickman
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
package com.github.simplenet;/*
* MIT License
*
* Copyright (c) 2020 Jacob Glickman
Expand All @@ -22,8 +22,6 @@
* SOFTWARE.
*/

import com.github.simplenet.Client;
import com.github.simplenet.Server;
import com.github.simplenet.packet.Packet;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down

0 comments on commit 08b1b52

Please sign in to comment.