Fix port-forward example (#309)
This commit is contained in:
committed by
Kubernetes Prow Robot
parent
239125a85d
commit
d9bca19e77
@@ -24,7 +24,7 @@ namespace portforward
|
|||||||
private async static Task Forward(IKubernetes client, V1Pod pod) {
|
private async static Task Forward(IKubernetes client, V1Pod pod) {
|
||||||
// Note this is single-threaded, it won't handle concurrent requests well...
|
// Note this is single-threaded, it won't handle concurrent requests well...
|
||||||
var webSocket = await client.WebSocketNamespacedPodPortForwardAsync(pod.Metadata.Name, "default", new int[] {80}, "v4.channel.k8s.io");
|
var webSocket = await client.WebSocketNamespacedPodPortForwardAsync(pod.Metadata.Name, "default", new int[] {80}, "v4.channel.k8s.io");
|
||||||
var demux = new StreamDemuxer(webSocket);
|
var demux = new StreamDemuxer(webSocket, StreamType.PortForward);
|
||||||
demux.Start();
|
demux.Start();
|
||||||
|
|
||||||
var stream = demux.GetStream((byte?)0, (byte?)0);
|
var stream = demux.GetStream((byte?)0, (byte?)0);
|
||||||
@@ -37,6 +37,7 @@ namespace portforward
|
|||||||
|
|
||||||
Socket handler = null;
|
Socket handler = null;
|
||||||
|
|
||||||
|
// Note this will only accept a single connection
|
||||||
var accept = Task.Run(() => {
|
var accept = Task.Run(() => {
|
||||||
while (true) {
|
while (true) {
|
||||||
handler = listener.Accept();
|
handler = listener.Accept();
|
||||||
@@ -61,6 +62,10 @@ namespace portforward
|
|||||||
|
|
||||||
await accept;
|
await accept;
|
||||||
await copy;
|
await copy;
|
||||||
|
if (handler != null) {
|
||||||
|
handler.Close();
|
||||||
|
}
|
||||||
|
listener.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user