Skip to content

Commit 15eb972

Browse files
committed
Avoid hot looping on the selector for initially disconnected channels
1 parent a5184e6 commit 15eb972

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

app/src/main/java/tech/httptoolkit/android/vpn/SessionManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public Session createNewUDPSession(int ip, int port, int srcIp, int srcPort){
203203
SelectionKey selectionKey = channel.register(selector,
204204
channel.isConnected()
205205
? SelectionKey.OP_READ | SelectionKey.OP_WRITE
206-
: SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE
206+
: SelectionKey.OP_CONNECT
207207
);
208208
session.setSelectionKey(selectionKey);
209209
Log.d(TAG,"Registered udp selector successfully");
@@ -289,7 +289,7 @@ public Session createNewSession(int ip, int port, int srcIp, int srcPort){
289289
SelectionKey selectionKey = channel.register(selector,
290290
channel.isConnected()
291291
? SelectionKey.OP_READ | SelectionKey.OP_WRITE
292-
: SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE
292+
: SelectionKey.OP_CONNECT
293293
);
294294
session.setSelectionKey(selectionKey);
295295
Log.d(TAG,"Registered tcp selector successfully");

app/src/main/java/tech/httptoolkit/android/vpn/socket/SocketNIODataService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ private void processTCPSelectionKey(SelectionKey key) throws IOException{
195195
session.setConnected(connected);
196196
Log.d(TAG,"connected immediately to remote tcp server: "+ips+":"+port);
197197
} else {
198-
if(channel.isConnectionPending()){
198+
if (channel.isConnectionPending()) {
199199
connected = channel.finishConnect();
200200
session.setConnected(connected);
201201
Log.d(TAG,"connected to remote tcp server: "+ips+":"+port);
202202
}
203203
}
204204
}
205-
if(channel.isConnected()){
205+
if (channel.isConnected()) {
206206
// Once connected, we no longer want connect events; we want read events instead.
207207
session.unsubscribeKey(SelectionKey.OP_CONNECT);
208208
session.subscribeKey(SelectionKey.OP_READ);

0 commit comments

Comments
 (0)