Commit 0419cef3 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Os.poll does not retry polling automatically when EINTR is thrown

parent 69544c2a
...@@ -157,7 +157,7 @@ public class DNSTCPProxy extends DNSProxy{ ...@@ -157,7 +157,7 @@ public class DNSTCPProxy extends DNSProxy{
pollingFd.fd = ParcelFileDescriptor.fromSocket(socket).getFileDescriptor(); pollingFd.fd = ParcelFileDescriptor.fromSocket(socket).getFileDescriptor();
pollingFd.events = (short)OsConstants.POLLIN; pollingFd.events = (short)OsConstants.POLLIN;
} }
Os.poll(polls, -1); poll(polls, -1);
} }
if(blockFd.revents != 0){ if(blockFd.revents != 0){
shouldRun = false; shouldRun = false;
...@@ -180,6 +180,22 @@ public class DNSTCPProxy extends DNSProxy{ ...@@ -180,6 +180,22 @@ public class DNSTCPProxy extends DNSProxy{
} }
} }
private int pollTries = 0;
private void poll(StructPollfd[] polls, int timeout) throws ErrnoException {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Build.VERSION.SDK_INT < Build.VERSION_CODES.M){
Os.poll(polls, timeout);
}else {
pollTries++;
try{
Os.poll(polls, timeout);
pollTries = 0;
} catch(ErrnoException ex){
if(pollTries < 3) poll(polls, timeout);
else throw ex;
}
}
}
private void handleDeviceDNSPacket(InputStream inputStream, byte[] packetBytes) throws IOException{ private void handleDeviceDNSPacket(InputStream inputStream, byte[] packetBytes) throws IOException{
packetBytes = Arrays.copyOfRange(packetBytes, 0, inputStream.read(packetBytes)); packetBytes = Arrays.copyOfRange(packetBytes, 0, inputStream.read(packetBytes));
IpPacket packet; IpPacket packet;
......
...@@ -148,7 +148,7 @@ public class DNSUDPProxy extends DNSProxy{ ...@@ -148,7 +148,7 @@ public class DNSUDPProxy extends DNSProxy{
pollingFd.fd = ParcelFileDescriptor.fromDatagramSocket(socket).getFileDescriptor(); pollingFd.fd = ParcelFileDescriptor.fromDatagramSocket(socket).getFileDescriptor();
pollingFd.events = (short)OsConstants.POLLIN; pollingFd.events = (short)OsConstants.POLLIN;
} }
Os.poll(polls, -1); poll(polls, -1);
} }
if(blockFd.revents != 0){ if(blockFd.revents != 0){
shouldRun = false; shouldRun = false;
...@@ -171,6 +171,22 @@ public class DNSUDPProxy extends DNSProxy{ ...@@ -171,6 +171,22 @@ public class DNSUDPProxy extends DNSProxy{
} }
} }
private int pollTries = 0;
private void poll(StructPollfd[] polls, int timeout) throws ErrnoException {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Build.VERSION.SDK_INT < Build.VERSION_CODES.M){
Os.poll(polls, timeout);
}else {
pollTries++;
try{
Os.poll(polls, timeout);
pollTries = 0;
} catch(ErrnoException ex){
if(pollTries < 3) poll(polls, timeout);
else throw ex;
}
}
}
private void handleDeviceDNSPacket(InputStream inputStream, byte[] packetBytes) throws IOException{ private void handleDeviceDNSPacket(InputStream inputStream, byte[] packetBytes) throws IOException{
packetBytes = Arrays.copyOfRange(packetBytes, 0, inputStream.read(packetBytes)); packetBytes = Arrays.copyOfRange(packetBytes, 0, inputStream.read(packetBytes));
IpPacket packet; IpPacket packet;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment