Skip to content

Commit cd7440e

Browse files
committed
try to solve hang issue
1 parent cb1029a commit cd7440e

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#Author Xingen Wang ([email protected])
22
3+
Release 2.6.5:
4+
since nio doesn't support soTimeout, solve this issue in com.schooner.MemCached.SockInputStream.readFromChannel().
5+
36
Release 2.6.4:
47
add storeCounter with expiry support.
58

build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ build.dir=classes
3333
test.build.dir=testclasses
3434
build.instr.dir=classesinstr
3535
project=java_memcached-release
36-
ver=2.6.4
36+
ver=2.6.5
3737
junit.jar=lib/junit.jar
3838
slf4japi.jar=lib/slf4j-api-1.6.1.jar
3939
slf4jsimple.jar=lib/slf4j-simple-1.6.1.jar

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.danga</groupId>
66
<artifactId>Memcached-Java-Client</artifactId>
7-
<version>2.6.4</version>
7+
<version>2.6.5</version>
88
<packaging>jar</packaging>
99

1010
<name>Memcached-Java-Client</name>

src/main/java/com/schooner/MemCached/SockInputStream.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.io.IOException;
3333
import java.io.InputStream;
3434
import java.nio.BufferUnderflowException;
35+
import java.nio.channels.Channels;
36+
import java.nio.channels.ReadableByteChannel;
3537

3638
/**
3739
* {@link SockInputStream} is a inputstream based on a socket. Due to memcached
@@ -46,6 +48,8 @@ public final class SockInputStream extends InputStream {
4648
private SchoonerSockIO sock;
4749
private int limit;
4850
private int count = 0;
51+
private byte b;
52+
private ByteArrayOutputStream bos = new ByteArrayOutputStream();
4953

5054
/**
5155
* get length of to-be-read.
@@ -102,7 +106,7 @@ public final int read() throws IOException {
102106
if (count >= limit) {
103107
return -1;
104108
}
105-
byte b = 0;
109+
b = 0;
106110
try {
107111
b = sock.readBuf.get();
108112
} catch (BufferUnderflowException e) {
@@ -124,7 +128,9 @@ public final int read() throws IOException {
124128
*/
125129
private final void readFromChannel() throws IOException {
126130
sock.readBuf.clear();
127-
sock.getChannel().read(sock.readBuf);
131+
// sock.getChannel().read(sock.readBuf);
132+
ReadableByteChannel wrappedChannel = Channels.newChannel(sock.getChannel().socket().getInputStream());
133+
wrappedChannel.read(sock.readBuf);
128134
sock.readBuf.flip();
129135
}
130136

@@ -171,7 +177,7 @@ public final byte[] getBuffer() throws IOException {
171177
* @since 2.5.1
172178
*/
173179
public final String getLine() throws IOException {
174-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
180+
bos.reset();
175181
int b;
176182
while ((b = read()) != -1) {
177183
bos.write(b);

0 commit comments

Comments
 (0)