Skip to content

Commit 636d585

Browse files
committed
Refactor write-readiness logic into the session itself too
1 parent 2fa0a2f commit 636d585

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@ public boolean isDataForSendingReady() {
321321
public void setDataForSendingReady(boolean isDataForSendingReady) {
322322
this.isDataForSendingReady = isDataForSendingReady;
323323
}
324+
325+
public boolean isReadyToWrite() {
326+
ProxyProtocolHandler handler = this.getProxySetupHandler();
327+
328+
if (handler != null) {
329+
return handler.hasHandshakeDataToSend();
330+
} else {
331+
return this.hasDataToSend() && this.isDataForSendingReady();
332+
}
333+
}
334+
324335
public void setUnackData(byte[] unackData) {
325336
this.unackData = unackData;
326337
}

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ public class SocketChannelWriter {
3737
this.writer = writer;
3838
}
3939

40-
public boolean isReadyToWrite(@NonNull Session session) {
41-
ProxyProtocolHandler handler = session.getProxySetupHandler();
42-
43-
if (handler != null) {
44-
return handler.hasHandshakeDataToSend();
45-
} else {
46-
return session.hasDataToSend() && session.isDataForSendingReady();
47-
}
48-
}
49-
5040
public void write(@NonNull Session session) {
5141
if (session.isAbortingConnection()) {
5242
Log.d(TAG,"shutting down aborted connection on write -> "+ session);
@@ -166,7 +156,7 @@ private void writeProxySetupData(ProxyProtocolHandler proxyProtocolHandler, Sess
166156

167157
proxyProtocolHandler.confirmHandshakeDataWritten();
168158

169-
if (this.isReadyToWrite(session)) {
159+
if (session.isReadyToWrite()) {
170160
// It's possible that this finishes the proxy protocol, and the session is now ready to write.
171161
// If so, we make sure to resubscribe, so this will fire again shortly:
172162
session.subscribeKey(SelectionKey.OP_WRITE);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private void processSelectorRead(SelectionKey selectionKey, Session session) {
233233

234234
private void processPendingWrite(SelectionKey selectionKey, Session session) {
235235
// Nothing to write? Skip this entirely, and make sure we're not subscribed
236-
if (!writer.isReadyToWrite(session)) {
236+
if (!session.isReadyToWrite()) {
237237
session.unsubscribeKey(SelectionKey.OP_WRITE);
238238
return;
239239
}

0 commit comments

Comments
 (0)