Skip to content

Commit a74ccf9

Browse files
committed
Рабочий вариант, совместимый с веткой 1
1 parent 196ae54 commit a74ccf9

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

src/VSCode.DebugAdapter/Transport/ConnectionFactory.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ public static TcpClient Connect(int port)
2424

2525
var client = new TcpClient();
2626
TryConnect(client, debuggerUri);
27-
var waitSec = 15;
28-
Log.Information("Waiting {waitSec} seconds", waitSec);
29-
Thread.Sleep(waitSec * 1000);
30-
Log.Information("Waiting completed");
31-
27+
3228
return client;
3329
}
3430

src/VSCode.DebugAdapter/Transport/DebugClientFactory.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,33 @@ private void ReconcileDataFormat(TcpClient client)
132132

133133
private void EmptyIncomingBuffer(TcpClient client)
134134
{
135-
if (client.Available == 0)
136-
return;
135+
Log.Verbose("Reading out all incoming buffer");
136+
const int waitForDataInterval = 300;
137+
const int gotNothingAttempts = 3;
138+
139+
int gotNothingCount = 0;
137140

138141
var buf = new byte[1024];
139142
do
140143
{
141144
var hasBytes = client.Available;
142-
var bytesRead = client.GetStream().Read(buf, 0, Math.Min(hasBytes, buf.Length));
143-
if (bytesRead == 0)
144-
return;
145+
if (hasBytes > 0)
146+
{
147+
gotNothingCount = 0;
148+
var bytesRead = client.GetStream().Read(buf, 0, Math.Min(hasBytes, buf.Length));
149+
if (bytesRead == 0)
150+
return;
151+
}
152+
else
153+
{
154+
gotNothingCount++;
155+
}
156+
157+
Log.Verbose("We have {Bytes} incoming bytes ({Attempt}). Waiting for more", hasBytes, gotNothingCount);
158+
Thread.Sleep(waitForDataInterval);
145159

146-
} while (client.Available > 0);
160+
} while (gotNothingCount < gotNothingAttempts);
161+
Log.Verbose("Reading out completed");
147162
}
148163

149164
private void ReadStream(BinaryReader reader, byte[] buffer, int length)

0 commit comments

Comments
 (0)