MCPcopy Create free account
hub / github.com/Tencent/tgfx / worker

Method worker

src/inspect/FrameCapture.cpp:211–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211void FrameCapture::worker() {
212 std::string addr = "255.255.255.255";
213 auto dataPort = TCPPortProvider::Get().getValidPort();
214 if (dataPort == 0) {
215 return;
216 }
217 const auto procname = GetProcessName();
218 const auto pnsz = std::min<size_t>(strlen(procname), WelcomeMessageProgramNameSize - 1);
219
220 while (timeBegin.load(std::memory_order_relaxed) == 0) {
221 std::this_thread::sleep_for(std::chrono::milliseconds(10));
222 }
223
224 auto welcome = WelcomeMessage();
225 welcome.initBegin = GetInspector().initTime;
226 welcome.initEnd = timeBegin.load(std::memory_order_relaxed);
227
228 auto listen = ListenSocket{};
229 bool isListening = false;
230 for (uint16_t i = 0; i < 20; ++i) {
231 if (listen.listenSock(dataPort + i, 4)) {
232 dataPort += i;
233 isListening = true;
234 break;
235 }
236 }
237 if (!isListening) {
238 while (true) {
239 if (ShouldExit()) {
240 shutdown.store(true, std::memory_order_relaxed);
241 return;
242 }
243 std::this_thread::sleep_for(std::chrono::milliseconds(10));
244 }
245 }
246 for (uint16_t i = 0; i < BroadcastCount; i++) {
247 broadcast[i] = std::make_shared<UDPBroadcast>();
248 if (!broadcast[i]->openConnect(addr.c_str(), BroadcastPort + i)) {
249 broadcast[i].reset();
250 }
251 }
252
253 size_t broadcastLen = 0;
254 auto broadcastMessage =
255 GetBroadcastMessage(procname, pnsz, broadcastLen, dataPort, ToolType::FrameCapture);
256 long long lastBroadcast = 0;
257 while (true) {
258 welcome.refTime = refTimeThread;
259 while (true) {
260 if (ShouldExit()) {
261 for (uint16_t i = 0; i < BroadcastCount; i++) {
262 if (broadcast[i]) {
263 broadcastMessage.activeTime = -1;
264 broadcast[i]->sendData(BroadcastPort + i, &broadcastMessage, broadcastLen);
265 }
266 }
267 return;
268 }

Callers 1

LaunchWorkerMethod · 0.80

Calls 11

GetProcessNameFunction · 0.85
WelcomeMessageClass · 0.85
GetBroadcastMessageFunction · 0.85
getValidPortMethod · 0.80
listenSockMethod · 0.80
openConnectMethod · 0.80
c_strMethod · 0.80
acceptSockMethod · 0.80
unlockMethod · 0.80
resetMethod · 0.45
sendDataMethod · 0.45

Tested by

no test coverage detected