Skip to content

Commit e213ab9

Browse files
committed
improve code; add distribution to pom
1 parent 5af814d commit e213ab9

File tree

7 files changed

+131
-30
lines changed

7 files changed

+131
-30
lines changed

kcp-example/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
6-
<artifactId>kcp-parent</artifactId>
76
<groupId>io.jpower.kcp</groupId>
8-
<version>1.1.0-SNAPSHOT</version>
7+
<artifactId>kcp-parent</artifactId>
8+
<version>1.1.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

kcp-netty/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
6-
<artifactId>kcp-parent</artifactId>
76
<groupId>io.jpower.kcp</groupId>
8-
<version>1.1.0-SNAPSHOT</version>
7+
<artifactId>kcp-parent</artifactId>
8+
<version>1.1.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

kcp-netty/src/main/java/io/jpower/kcp/netty/Kcp.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.ListIterator;
1313

1414
/**
15-
* Java implementation of <a href=" https://github.com/skywind3000/kcp">KCP</a>
15+
* Java implementation of <a href="https://github.com/skywind3000/kcp">KCP</a>
1616
*
1717
* @author <a href="mailto:[email protected]">szh</a>
1818
*/

kcp-netty/src/main/java/io/jpower/kcp/netty/Ukcp.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,15 @@ public boolean canRecv() {
6868
return kcp.canRecv();
6969
}
7070

71-
public boolean canSend() {
72-
return kcp.waitSnd() < kcp.getSndWnd() * 2;
71+
public boolean canSend(boolean curCanSend) {
72+
int max = kcp.getSndWnd() * 2;
73+
int waitSnd = kcp.waitSnd();
74+
if (curCanSend) {
75+
return waitSnd < max;
76+
} else {
77+
int threshold = Math.max(1, max / 2);
78+
return waitSnd < threshold;
79+
}
7380
}
7481

7582
public long update(long current) {

kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpClientChannel.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void kcpInput(ByteBuf buf) throws IOException {
226226
}
227227

228228
boolean kcpSend(ByteBuf buf) throws IOException {
229-
if (kcpCanSend()) {
229+
if (ukcp.canSend(true)) {
230230
ukcp.send(buf);
231231
return true;
232232
} else {
@@ -239,7 +239,7 @@ boolean kcpCanRecv() {
239239
}
240240

241241
boolean kcpCanSend() {
242-
return ukcp.canSend();
242+
return ukcp.canSend(!flushPending);
243243
}
244244

245245
int kcpPeekSize() {

kcp-netty/src/main/java/io/jpower/kcp/netty/UkcpServerChildChannel.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void kcpInput(ByteBuf buf) throws IOException {
193193
}
194194

195195
boolean kcpSend(ByteBuf buf) throws IOException {
196-
if (kcpCanSend()) {
196+
if (ukcp.canSend(true)) {
197197
ukcp.send(buf);
198198
return true;
199199
} else {
@@ -206,17 +206,14 @@ boolean kcpCanRecv() {
206206
}
207207

208208
boolean kcpCanSend() {
209-
return ukcp.canSend();
209+
return ukcp.canSend(!flushPending);
210210
}
211211

212212
int kcpPeekSize() {
213213
return ukcp.peekSize();
214214
}
215215

216216
long kcpUpdate(long current) {
217-
if (flushPending && ukcp.canSend()) {
218-
unsafe().forceFlush();
219-
}
220217
return ukcp.update(current);
221218
}
222219

pom.xml

+113-16
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,50 @@
66

77
<groupId>io.jpower.kcp</groupId>
88
<artifactId>kcp-parent</artifactId>
9-
<version>1.1.0-SNAPSHOT</version>
9+
<version>1.1.0</version>
1010
<packaging>pom</packaging>
1111

12+
<name>kcp-netty [Parent]</name>
13+
<url>http://kcp.jpower.io/</url>
14+
<description>
15+
Java implementation of KCP based on Netty
16+
</description>
17+
1218
<properties>
1319
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1420
</properties>
1521

22+
<licenses>
23+
<license>
24+
<name>The MIT License</name>
25+
<url>https://opensource.org/licenses/MIT</url>
26+
</license>
27+
</licenses>
28+
29+
<developers>
30+
<developer>
31+
<id>szhnet</id>
32+
<name>Zheng Sun</name>
33+
<email>[email protected]</email>
34+
</developer>
35+
</developers>
36+
37+
<scm>
38+
<url>https://github.com/szhnet/kcp-netty</url>
39+
<connection>scm:git:git://github.com/szhnet/kcp-netty.git</connection>
40+
</scm>
41+
42+
<distributionManagement>
43+
<snapshotRepository>
44+
<id>sonatype-nexus-staging</id>
45+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
46+
</snapshotRepository>
47+
<repository>
48+
<id>sonatype-nexus-staging</id>
49+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
50+
</repository>
51+
</distributionManagement>
52+
1653
<dependencyManagement>
1754
<dependencies>
1855
<dependency>
@@ -48,6 +85,21 @@
4885
<artifactId>maven-source-plugin</artifactId>
4986
<version>3.0.1</version>
5087
</plugin>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-javadoc-plugin</artifactId>
91+
<version>2.9.1</version>
92+
</plugin>
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-gpg-plugin</artifactId>
96+
<version>1.6</version>
97+
</plugin>
98+
<plugin>
99+
<groupId>org.sonatype.plugins</groupId>
100+
<artifactId>nexus-staging-maven-plugin</artifactId>
101+
<version>1.6.8</version>
102+
</plugin>
51103
</plugins>
52104
</pluginManagement>
53105

@@ -61,23 +113,68 @@
61113
<fork>true</fork>
62114
</configuration>
63115
</plugin>
64-
65-
<plugin>
66-
<groupId>org.apache.maven.plugins</groupId>
67-
<artifactId>maven-source-plugin</artifactId>
68-
<configuration>
69-
</configuration>
70-
<executions>
71-
<execution>
72-
<id>attach-sources</id>
73-
<goals>
74-
<goal>jar</goal>
75-
</goals>
76-
</execution>
77-
</executions>
78-
</plugin>
79116
</plugins>
80117
</build>
81118

119+
<profiles>
120+
<profile>
121+
<id>release</id>
122+
<build>
123+
<plugins>
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-source-plugin</artifactId>
127+
<configuration>
128+
</configuration>
129+
<executions>
130+
<execution>
131+
<id>attach-sources</id>
132+
<goals>
133+
<goal>jar-no-fork</goal>
134+
</goals>
135+
</execution>
136+
</executions>
137+
</plugin>
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-javadoc-plugin</artifactId>
141+
<configuration>
142+
</configuration>
143+
<executions>
144+
<execution>
145+
<id>attach-javadocs</id>
146+
<goals>
147+
<goal>jar</goal>
148+
</goals>
149+
</execution>
150+
</executions>
151+
</plugin>
152+
<plugin>
153+
<groupId>org.apache.maven.plugins</groupId>
154+
<artifactId>maven-gpg-plugin</artifactId>
155+
<executions>
156+
<execution>
157+
<id>sign-artifacts</id>
158+
<phase>verify</phase>
159+
<goals>
160+
<goal>sign</goal>
161+
</goals>
162+
</execution>
163+
</executions>
164+
</plugin>
165+
<plugin>
166+
<groupId>org.sonatype.plugins</groupId>
167+
<artifactId>nexus-staging-maven-plugin</artifactId>
168+
<extensions>true</extensions>
169+
<configuration>
170+
<serverId>sonatype-nexus-staging</serverId>
171+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
172+
<autoReleaseAfterClose>false</autoReleaseAfterClose>
173+
</configuration>
174+
</plugin>
175+
</plugins>
176+
</build>
177+
</profile>
178+
</profiles>
82179

83180
</project>

0 commit comments

Comments
 (0)