MCPcopy Create free account
hub / github.com/MisterTea/EternalTerminal / writePacket

Method writePacket

src/base/Connection.cpp:45–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45void Connection::writePacket(const Packet& packet) {
46 while (true) {
47 {
48 lock_guard<std::recursive_mutex> guard(connectionMutex);
49 if (shuttingDown) {
50 break;
51 }
52 }
53 bool success = write(packet);
54 if (success) {
55 return;
56 }
57 bool hasConnection;
58 {
59 lock_guard<std::recursive_mutex> guard(connectionMutex);
60 hasConnection = (socketFd != -1);
61 }
62
63 // Yield the processor
64 if (hasConnection) {
65 // Have a connection, sleep for 1ms
66 std::this_thread::sleep_for(std::chrono::microseconds(1000));
67 } else {
68 // No connection, sleep for 100ms
69 std::this_thread::sleep_for(std::chrono::microseconds(100 * 1000));
70 }
71 LOG_EVERY_N(1000, INFO) << "Waiting to write...";
72 }
73}
74
75void Connection::closeSocket() {
76 lock_guard<std::recursive_mutex> guard(connectionMutex);

Callers 9

runMethod · 0.45
writeMethod · 0.45
TerminalClientMethod · 0.45
runMethod · 0.45
UserTerminalHandlerMethod · 0.45
runMethod · 0.45
runJumpHostMethod · 0.45
runTerminalMethod · 0.45
handlePacketMethod · 0.45

Calls 1

writeFunction · 0.50

Tested by 2

runMethod · 0.36
writeMethod · 0.36