| 11 | } |
| 12 | |
| 13 | int SocketIOSession::Run(LanguageServer &server) { |
| 14 | auto &ioc = server.GetIOContext(); |
| 15 | IOSession::Run(server); |
| 16 | while (true) { |
| 17 | do { |
| 18 | asio::error_code code; |
| 19 | |
| 20 | char *writableCursor = _protocolBuffer.GetWritableCursor(); |
| 21 | std::size_t capacity = _protocolBuffer.GetRestCapacity(); |
| 22 | |
| 23 | std::size_t readSize = _socket.read_some(asio::buffer(writableCursor, capacity), code); |
| 24 | if (code == asio::error::eof || code) { |
| 25 | goto endLoop; |
| 26 | } |
| 27 | |
| 28 | _protocolBuffer.SetWriteSize(readSize); |
| 29 | |
| 30 | if (_protocolBuffer.CanReadOneProtocol()) { |
| 31 | break; |
| 32 | } |
| 33 | |
| 34 | _protocolBuffer.FitCapacity(); |
| 35 | } while (true); |
| 36 | |
| 37 | do { |
| 38 | auto content = _protocolBuffer.ReadOneProtocol(); |
| 39 | auto parser = std::make_shared<ProtocolParser>(); |
| 40 | parser->Parse(content); |
| 41 | _protocolBuffer.Reset(); |
| 42 | asio::post(ioc, [this, parser, &server]() { |
| 43 | std::string result = Handle(server, parser); |
| 44 | |
| 45 | if (!result.empty()) { |
| 46 | Send(result); |
| 47 | } |
| 48 | }); |
| 49 | } while (_protocolBuffer.CanReadOneProtocol()); |
| 50 | } |
| 51 | endLoop: |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | void SocketIOSession::Send(std::string_view content) { |
| 56 | asio::write(_socket, asio::buffer(content)); |
nothing calls this directly
no test coverage detected