Skip to content

Commit 4443a87

Browse files
committed
修改ioc定义的位置
1 parent fa5c478 commit 4443a87

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

CodeFormatServer/src/CodeFormatServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using namespace asio::ip;
1616

1717
int main(int argc, char** argv)
1818
{
19-
auto ioc = std::make_shared<asio::io_context>(1);
19+
auto& ioc = LanguageClient::GetInstance().GetIOContext();
2020
if (argc > 1)
2121
{
2222
int port = std::stoi(argv[1]);

CodeFormatServer/src/LanguageClient.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LanguageClient& LanguageClient::GetInstance()
2121
LanguageClient::LanguageClient()
2222
: _defaultOptions(std::make_shared<LuaCodeStyleOptions>()),
2323
_idCounter(0),
24-
_ioc(nullptr)
24+
_ioc(1)
2525
{
2626
}
2727

@@ -203,12 +203,11 @@ std::shared_ptr<LuaParser> LanguageClient::GetFileParser(std::string_view uri)
203203
return nullptr;
204204
}
205205

206-
int LanguageClient::Run(std::shared_ptr<asio::io_context> ioc)
206+
int LanguageClient::Run()
207207
{
208-
_ioc = ioc;
209208
if (_session)
210209
{
211-
int ret = _session->Run(*ioc);
210+
int ret = _session->Run(_ioc);
212211
_session = nullptr;
213212
return ret;
214213
}
@@ -309,7 +308,7 @@ void LanguageClient::SetRoot(std::string_view root)
309308

310309
asio::io_context& LanguageClient::GetIOContext()
311310
{
312-
return *_ioc;
311+
return _ioc;
313312
}
314313

315314
uint64_t LanguageClient::GetRequestId()

include/CodeFormatServer/LanguageClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class LanguageClient : public std::enable_shared_from_this<LanguageClient>
5050

5151
std::shared_ptr<LuaParser> GetFileParser(std::string_view uri);
5252

53-
int Run(std::shared_ptr<asio::io_context> ioc);
53+
int Run();
5454

5555
std::shared_ptr<LuaCodeStyleOptions> GetOptions(std::string_view uriOrFilename);
5656

@@ -88,7 +88,7 @@ class LanguageClient : public std::enable_shared_from_this<LanguageClient>
8888

8989
std::string _root;
9090

91-
std::shared_ptr<asio::io_context> _ioc;
91+
asio::io_context _ioc;
9292

9393
std::array<std::shared_ptr<Service>, static_cast<std::size_t>(ServiceType::ServiceCount)> _services;
9494
};

0 commit comments

Comments
 (0)