fix: 修复windows通信编码问题
This commit is contained in:
parent
4f5bf9d781
commit
b4b916fd9a
|
|
@ -1,5 +1,9 @@
|
|||
#include <exception>
|
||||
#include <iostream>
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#include "../provider/base/provider_registry.hpp"
|
||||
#include "./server.hpp"
|
||||
#include "./logger.hpp"
|
||||
|
|
@ -117,10 +121,24 @@ namespace lsp
|
|||
log::Debug("Response length: ", byte_length);
|
||||
log::Debug("Raw response content: [", response_str, "]");
|
||||
|
||||
std::cout << "Content-Length: " << byte_length << "\r\n\r\n";
|
||||
std::cout << response_str;
|
||||
// 在程序启动时设置stdout为二进制模式(只需设置一次)
|
||||
static bool binary_mode_set = false;
|
||||
if (!binary_mode_set) {
|
||||
#ifdef _WIN32
|
||||
_setmode(_fileno(stdout), _O_BINARY);
|
||||
#endif
|
||||
binary_mode_set = true;
|
||||
}
|
||||
|
||||
// 构建完整消息
|
||||
std::string header = "Content-Length: " + std::to_string(byte_length) + "\r\n\r\n";
|
||||
|
||||
// 使用 write 系统调用,绕过 C++ 流的缓冲和转换
|
||||
std::cout.write(header.c_str(), header.length());
|
||||
std::cout.write(response_str.c_str(), response_str.length());
|
||||
std::cout.flush();
|
||||
|
||||
log::Verbose("Response sent successfully");
|
||||
log::Verbose("Response sent successfully2");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue