Skip to content

Commit

Permalink
Adds status detection for an httpRequest (libgdx#7305)
Browse files Browse the repository at this point in the history
  • Loading branch information
supermaximus80 authored Dec 27, 2023
1 parent 60f0743 commit 2b691f7
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void cancelHttpRequest (HttpRequest httpRequest) {
netJavaImpl.cancelHttpRequest(httpRequest);
}

@Override
public boolean isHttpRequestPending (HttpRequest httpRequest) {
return netJavaImpl.isHttpRequestPending(httpRequest);
}

@Override
public ServerSocket newServerSocket (Protocol protocol, String hostname, int port, ServerSocketHints hints) {
return new NetJavaServerSocketImpl(protocol, hostname, port, hints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public void cancelHttpRequest (HttpRequest httpRequest) {
netJavaImpl.cancelHttpRequest(httpRequest);
}

@Override
public boolean isHttpRequestPending (HttpRequest httpRequest) {
return netJavaImpl.isHttpRequestPending(httpRequest);
}

@Override
public ServerSocket newServerSocket (Protocol protocol, String hostname, int port, ServerSocketHints hints) {
return new NetJavaServerSocketImpl(protocol, hostname, port, hints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public void cancelHttpRequest (HttpRequest httpRequest) {
netJavaImpl.cancelHttpRequest(httpRequest);
}

@Override
public boolean isHttpRequestPending (HttpRequest httpRequest) {
return netJavaImpl.isHttpRequestPending(httpRequest);
}

@Override
public ServerSocket newServerSocket (Protocol protocol, String ipAddress, int port, ServerSocketHints hints) {
return new NetJavaServerSocketImpl(protocol, ipAddress, port, hints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public void cancelHttpRequest (HttpRequest httpRequest) {
netJavaImpl.cancelHttpRequest(httpRequest);
}

@Override
public boolean isHttpRequestPending (HttpRequest httpRequest) {
return netJavaImpl.isHttpRequestPending(httpRequest);
}

@Override
public ServerSocket newServerSocket (Protocol protocol, String ipAddress, int port, ServerSocketHints hints) {
return new NetJavaServerSocketImpl(protocol, ipAddress, port, hints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public void cancelHttpRequest (HttpRequest httpRequest) {
netJavaImpl.cancelHttpRequest(httpRequest);
}

@Override
public boolean isHttpRequestPending (HttpRequest httpRequest) {
return netJavaImpl.isHttpRequestPending(httpRequest);
}

@Override
public ServerSocket newServerSocket (Protocol protocol, String hostname, int port, ServerSocketHints hints) {
return new NetJavaServerSocketImpl(protocol, hostname, port, hints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public void cancelHttpRequest (HttpRequest httpRequest) {
netJavaImpl.cancelHttpRequest(httpRequest);
}

@Override
public boolean isHttpRequestPending (HttpRequest httpRequest) {
return netJavaImpl.isHttpRequestPending(httpRequest);
}

@Override
public ServerSocket newServerSocket (Protocol protocol, String hostname, int port, ServerSocketHints hints) {
return new NetJavaServerSocketImpl(protocol, hostname, port, hints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ public void cancelHttpRequest (HttpRequest httpRequest) {
}
}

@Override
public boolean isHttpRequestPending (HttpRequest httpRequest) {
return listeners.get(httpRequest) != null && requests.get(httpRequest) != null;
}

@Override
public ServerSocket newServerSocket (Protocol protocol, String hostname, int port, ServerSocketHints hints) {
throw new UnsupportedOperationException("Not implemented");
Expand Down
2 changes: 2 additions & 0 deletions gdx/src/com/badlogic/gdx/Net.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ public static interface HttpResponseListener {

public void cancelHttpRequest (HttpRequest httpRequest);

public boolean isHttpRequestPending (HttpRequest httpRequest);

/** Protocol used by {@link Net#newServerSocket(Protocol, int, ServerSocketHints)} and
* {@link Net#newClientSocket(Protocol, String, int, SocketHints)}.
* @author mzechner */
Expand Down
4 changes: 4 additions & 0 deletions gdx/src/com/badlogic/gdx/net/NetJavaImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public void cancelHttpRequest (HttpRequest httpRequest) {
}
}

public boolean isHttpRequestPending (HttpRequest httpRequest) {
return getFromListeners(httpRequest) != null;
}

private void cancelTask (HttpRequest httpRequest) {
Future<?> task = tasks.get(httpRequest);

Expand Down

0 comments on commit 2b691f7

Please sign in to comment.