Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL hang / timeout fix #73

Merged
merged 2 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group = org.threadly
version = 4.13
threadlyVersion = 5.41
threadlyVersion = 5.42
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public AbstractMergedByteBuffers(boolean readOnly) {
}

protected abstract void doAppend(final ByteBuffer bb);
protected abstract void addToFront(final ByteBuffer bb);
protected abstract byte get(int pos);
public abstract AbstractMergedByteBuffers duplicate();
public abstract AbstractMergedByteBuffers duplicateAndClean();
Expand All @@ -58,20 +57,15 @@ public void add(final byte[] ...bas) {
@Override
public void add(final ByteBuffer ...buffers) {
for(ByteBuffer buffer: buffers) {
if(buffer.hasRemaining()) {
lwahlmeier marked this conversation as resolved.
Show resolved Hide resolved
doAppend(buffer.duplicate());
}
doAppend(buffer);
}
}

@Override
public void add(final MergedByteBuffers ...mbbs) {
for(MergedByteBuffers mbb: mbbs) {
while(mbb.hasRemaining()) {
ByteBuffer bb = mbb.popBuffer();
if(bb.hasRemaining()) {
doAppend(bb);
}
doAppend(mbb.popBuffer());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ public ReuseableMergedByteBuffers(boolean readOnly, ByteBuffer ...bbs) {

@Override
protected void doAppend(final ByteBuffer bb) {
availableBuffers.add(bb);
currentSize+=bb.remaining();
if (bb.hasRemaining()) {
availableBuffers.add(bb.duplicate());
currentSize+=bb.remaining();
}
}

@Override
public ReuseableMergedByteBuffers duplicate() {
final ReuseableMergedByteBuffers mbb = new ReuseableMergedByteBuffers(markReadOnly);
for(final ByteBuffer bb: this.availableBuffers) {
mbb.add(bb.duplicate());
mbb.doAppend(bb);
}
return mbb;
}
Expand All @@ -59,12 +61,6 @@ public ReuseableMergedByteBuffers duplicateAndClean() {
return mbb;
}

@Override
protected void addToFront(ByteBuffer bb) {
this.availableBuffers.addFirst(bb.duplicate());
this.currentSize+=bb.remaining();
}

@Override
public int remaining() {
return currentSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
public class SimpleMergedByteBuffers extends AbstractMergedByteBuffers {
private static final ByteBuffer[] EMPTY_BUFFER_ARRAY = new ByteBuffer[] {};


private final ByteBuffer[] bba;
private int currentBuffer = 0;
protected long consumedSize = 0;

public SimpleMergedByteBuffers(boolean readOnly, ByteBuffer ...bbs) {
super(readOnly);
for(ByteBuffer bb: bbs) {
if(bb == null) {

for (int i = 0; i < bbs.length; i++) {
if(bbs[i] == null) {
throw new IllegalArgumentException("Can not add null buffers!");
}
bbs[i] = bbs[i].duplicate();
}
if(bbs.length > 0) {
bba = bbs;
Expand All @@ -50,10 +51,6 @@ public SimpleMergedByteBuffers(boolean readOnly, SimpleMergedByteBuffers smbb, B
}
}

private void doGet(final byte[] destBytes) {
doGet(destBytes, 0, destBytes.length);
}

private void doGet(final byte[] destBytes, int start, int len) {
int remainingToCopy = len;

Expand All @@ -79,16 +76,11 @@ protected void doAppend(ByteBuffer bb) {
throw new UnsupportedOperationException("Can not add to this buffer!");
}

@Override
protected void addToFront(ByteBuffer bb) {
throw new UnsupportedOperationException("Can not add to this buffer!");
}

@Override
public SimpleMergedByteBuffers duplicate() {
ByteBuffer[] bba2 = new ByteBuffer[bba.length-currentBuffer];
for(int i=currentBuffer; i<bba.length; i++) {
bba2[i-currentBuffer] = bba[i].duplicate();
bba2[i-currentBuffer] = bba[i];
}
return new SimpleMergedByteBuffers(markReadOnly, bba2);
}
Expand All @@ -97,7 +89,7 @@ public SimpleMergedByteBuffers duplicate() {
public SimpleMergedByteBuffers duplicateAndClean() {
SimpleMergedByteBuffers smbb = duplicate();
currentBuffer = bba.length;
for(int i=0; i<bba.length; i++) {
for(int i=currentBuffer; i<bba.length; i++) {
bba[i] = null;
}
return smbb;
Expand Down Expand Up @@ -170,15 +162,15 @@ public ByteBuffer pullBuffer(int size) {
final ByteBuffer first = getNextBuffer();
if(first.remaining() == size) {
currentBuffer++;
return first.duplicate();
return first;
} else if(first.remaining() > size) {
final ByteBuffer bb = first.duplicate();
bb.limit(bb.position()+size);
first.position(first.position()+size);
return bb;
} else {
final byte[] result = new byte[size];
doGet(result);
doGet(result, 0, size);
return ByteBuffer.wrap(result);
}
}
Expand Down