MCPcopy Create free account
hub / github.com/Tencent/Hardcoder / tryStartEngine

Method tryStartEngine

libapp2sys/src/main/cpp/client.h:359–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

357 int64_t m_lastConnect;
358
359 int tryStartEngine() {
360 if ((m_remote.length() == 0) || (m_port <= 0 && m_local.length() == 0)) { //param check
361 return -1;
362 }
363 if (m_pClientEngine && m_pClientEngine->isRunning()) { //running
364 return -2;
365 }
366
367 int64_t curr = getMillisecond();
368
369 pdbg("tryStartEngine, TimeDiff:%d, remote:%s, running:%d", TOINT(curr - m_lastConnect), m_remote.c_str(),
370 m_pClientEngine ? m_pClientEngine->isRunning() : -1);
371
372 if (curr - m_lastConnect < (int64_t)m_retryConnectInterval * 1000) {
373 return -3;
374 }
375 m_lastConnect = curr;
376
377 if (m_pClientEngine) { // disconnected
378 delete m_pClientEngine;
379 m_pClientEngine = NULL;
380 }
381 IClientEngine *pEngine = NULL;
382 if (m_port != 0) {
383 pEngine = new UdpClient();
384 if (static_cast<UdpClient *>(pEngine)->start(m_remote.c_str(), m_port, 500, this) > 0 && pEngine->isRunning()) {
385 m_pClientEngine = pEngine;
386 return 0;
387 } else {
388 delete pEngine;
389 }
390 } else {
391 pEngine = new LocalsocketClient();
392 if (static_cast<LocalsocketClient *>(pEngine)->start(m_remote.c_str(), m_local.c_str(), this) > 0 && pEngine->isRunning()) {
393 m_pClientEngine = pEngine;
394 m_pC2JavaCallback->callback(CALLBACK_TYPE_STATUS, 0, 0, ERR_CLIENT_CONNECT, 0, 0, NULL, 0);
395 return 0;
396 } else {
397 delete pEngine;
398 }
399 }
400 return -3;
401 }
402
403public:
404 Client() {

Callers

nothing calls this directly

Calls 4

getMillisecondFunction · 0.85
callbackMethod · 0.80
isRunningMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected