yy1717
2022-12-08 f7a18ec4494b9c5c9ef3fd440bbf68ffc6425e18
lib/src/main/cpp/common/net.cpp
@@ -12,7 +12,7 @@
#include <sys/select.h>
#include <arpa/inet.h>
#include <regex>
#include <pthread.h>
#include <thread>
#include <semaphore.h>
#include <string>
@@ -70,12 +70,7 @@
    m_sIp = ip;
    m_nPort = port;
    pthread_t platform_pid;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);//detached
    pthread_create(&platform_pid, &attr, TcpConnectThread, this);
    std::thread(TcpConnectThread, this).detach();
    return true;
}
@@ -317,7 +312,7 @@
    return( -1 );
}
void *CTcpPort::TcpConnectThread(void *p)
void CTcpPort::TcpConnectThread(void *p)
{
    CTcpPort *pCTcpPort = (CTcpPort *)p;
@@ -325,7 +320,7 @@
    if (pCTcpPort->is_domain_name(pCTcpPort->m_sIp.c_str())) {
        if (pCTcpPort->GetHostIP(pCTcpPort->m_sIp.c_str(), net_addr) != 0) {
            goto CONNECT_END;
            return;
        }
    } else {
        strcpy(net_addr, pCTcpPort->m_sIp.c_str());
@@ -338,22 +333,15 @@
            pCTcpPort->event_func(0, pCTcpPort, pCTcpPort->event_func_context);
        }
        pthread_t platform_pid;
        pthread_attr_t attr;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);//detached
        pthread_create(&platform_pid, &attr, TcpListenThread, p);
        std::thread(TcpListenThread, p).detach();
    } else {
        if (pCTcpPort->event_func != NULL) {
            pCTcpPort->event_func(-1, pCTcpPort, pCTcpPort->event_func_context);
        }
    }
CONNECT_END:
    pthread_exit(NULL);
}
void *CTcpPort::TcpListenThread(void *p)
void CTcpPort::TcpListenThread(void *p)
{
    int fds_ret;
    struct timeval tv;
@@ -403,8 +391,6 @@
    if (pCTcpPort->event_func) {
        pCTcpPort->event_func(-1, pCTcpPort, pCTcpPort->event_func_context);
    }
    pthread_exit(NULL);
}
void CTcpPort::set_event_callback(void (*callback)(int, void *, void *), void *context)