Skip to content

Commit 45d246d

Browse files
authored
Merge pull request #1321 from brendandburns/flush
Add a flush method to the websocket output stream.
2 parents b8ffd68 + aa17fac commit 45d246d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

util/src/main/java/io/kubernetes/client/util/WebSocketStreamHandler.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,24 @@ public WebSocketOutputStream(int stream) {
216216
this.stream = (byte) stream;
217217
}
218218

219+
@Override
220+
public void flush() throws IOException {
221+
if (state == State.CLOSED) {
222+
throw new IOException("Socket is closed!");
223+
}
224+
int i = 0;
225+
while (WebSocketStreamHandler.this.socket.queueSize() > 0) {
226+
try {
227+
Thread.sleep(100);
228+
} catch (InterruptedException ex) {
229+
}
230+
// Wait a maximum of 10 seconds.
231+
if (i++ > 100) {
232+
throw new IOException("Timed out waiting for web-socket to flush.");
233+
}
234+
}
235+
}
236+
219237
@Override
220238
public void write(int b) throws IOException {
221239
write(new byte[] {(byte) b});

0 commit comments

Comments
 (0)