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

escape from getSomeData if there will never be data #2614

Merged
merged 2 commits into from
Nov 24, 2018

Conversation

ddyer0
Copy link
Contributor

@ddyer0 ddyer0 commented Nov 22, 2018

If the remote end closed the inputstream while the local thread is
in getSomeData, the local end hasn't been closed, and the thread
hangs forever.

If the remote end closed the inputstream while the local thread is
in getSomeData, the local end hasn't been closed, and the thread
hangs forever.
@ddyer0
Copy link
Contributor Author

ddyer0 commented Nov 22, 2018

I discovered this problem incidental to my other recent work on sockets.

@codenameone
Copy link
Collaborator

What about the case of buffer.length == 0 ?

@ddyer0
Copy link
Contributor Author

ddyer0 commented Nov 22, 2018

Buffer length=0 is a legal state, if a previous read exactly emptied the buffer and no more
data has arrived yet. This case never came up before because my previous networking
had reliable unix hosts as the server, which never closed connections unexpectedly. The
current cases involve peer-to-peer connections between tablets, which are much more
vulnerable to unexpected disconnection.

@codenameone
Copy link
Collaborator

Length 0 is valid but after this change it will no longer sleep in the loop

@ddyer0
Copy link
Contributor Author

ddyer0 commented Nov 23, 2018

you're right, add buffer.length==0 && to the if clause

@codenameone codenameone merged commit 29fc171 into codenameone:master Nov 24, 2018
@codenameone
Copy link
Collaborator

Thanks!

@ddyer0
Copy link
Contributor Author

ddyer0 commented Nov 30, 2018

Networking on IOS seems to be completely broken. Unless you changed something else,
this is the immediate suspect, though I probably shouldn't be fixed by simply reverting this.

@ddyer0
Copy link
Contributor Author

ddyer0 commented Nov 30, 2018

I think the proper fix is to make the IOS implementation conform the the same contract
as android, so in IOSImplementation.java

static final byte[]dummyval = new byte[0]; @Override public byte[] readFromSocketStream(Object socket) { byte []val = nativeInstance.readFromSocketStream(((Long)socket).longValue()); if(val==null) { return(dummyval); } return(val); }
The same problem may exist for javascript

codenameone pushed a commit that referenced this pull request Dec 1, 2018
This reverts commit 29fc171, reversing
changes made to d7a1a90.
@codenameone
Copy link
Collaborator

I reverted the PR for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants