netcoredbg: Cannot receive request in VSCode mode

  1. Start netcoredbg with arg: “–interpreter=vscode --server”
  2. My DapClient like this: var endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1", 4711)); var socket = new Socket(AdressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connent(endPoint); var stream = new NetworkStream(socket); var options = new DebugAdapterClientOptions().WithInput(stream).Withoutput(stream); var client = DebugAdapterClinet.Create(options); await client.Initialize(System.Threading.CancellationToken.None); <----run to here and block !!!
  3. In server side(vscodeprotocol.cpp) at func std::string VSCodeProtocol::ReadData() { ... std::getline(cin, line); if(! cin.good()) { //Always run to here, even if DapClinet is just connected, before sending the initialization command。 } ... }

Is there anything I missed? I am not good at English, I hope my description clears up my problem. Thanks.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 29 (18 by maintainers)

Commits related to this issue

Most upvoted comments

From the very beginning, I modified the code according to kfrolov’s suggestion to solve the communication problem in VSCode mode, so far it is running well, but I don’t know if these modifications are the best practice.

Hereis my modifications:

// Function perform reading from the file: it may read up to `count' bytes to `buf'.
Class::IOResult Class::read(const FileHandle& fh, void *buf, size_t count)
{
    //DWORD dwRead = 0;
    //OVERLAPPED ov = {};
    //if (! ReadFile(fh.handle, buf, (DWORD)count, &dwRead, &ov))
        //return { (GetLastError() == ERROR_IO_PENDING ? IOResult::Pending : IOResult::Error), dwRead };
    //else
        //return { (dwRead == 0 ? IOResult::Eof : IOResult::Success), dwRead };

    DWORD dwRead = 0;
    OVERLAPPED ov = {};
    ov.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

    if (!ReadFile(fh.handle, buf, (DWORD)count, 0, &ov))
    {
	if (GetLastError() == ERROR_IO_PENDING)
	{
		WaitForSingleObject(ov.hEvent, INFINITE);

		CloseHandle(ov.hEvent);

		if (GetOverlappedResult(fh.handle, &ov, &dwRead, TRUE))
		{
			DWORD err = GetLastError();
			if ( err == ERROR_IO_PENDING
				|| err == WAIT_TIMEOUT
				|| err == ERROR_IO_INCOMPLETE)
			{
				return { dwRead == 0? IOResult::Pending : IOResult::Success, dwRead };
			}
			else
				return { (dwRead == 0 ? IOResult::Eof : IOResult::Success), dwRead };
		}
		else
		{
			DWORD error = GetLastError();

			return { ( error== ERROR_IO_PENDING || error == ERROR_IO_INCOMPLETE || error == WAIT_TIMEOUT ? IOResult::Pending : IOResult::Error), dwRead };
		}
	}
	else
	{
		return { IOResult::Eof, dwRead };
	}
}
else
{
	return { (ov.InternalHigh == 0 ? IOResult::Eof : IOResult::Success), ov.InternalHigh };
}	

}