예제 #1
0
uint32_t pnClient::nextTransId() {
    static uint32_t s_transId = 0;
    static hsMutex s_tidMutex;

    s_tidMutex.lock();
    uint32_t tid = ++s_transId;
    s_tidMutex.unlock();
    return tid;
}
예제 #2
0
unsigned long pnSocket::GetAddress(const char* addrName)
{
    static hsMutex addrMutex;
    addrMutex.lock();
    hostent* host = gethostbyname(addrName);
    unsigned long numAddr = 0;
    if (host != NULL && host->h_addr_list != NULL)
        numAddr = ntohl(*(unsigned long*)host->h_addr_list[0]);
    addrMutex.unlock();
    return numAddr;
}
예제 #3
0
ST::string pnSocket::getRemoteIpStr() const
{
    static hsMutex ipStrMutex;

    sockaddr_in addr;
    socklen_t slen = sizeof(addr);
    ipStrMutex.lock();
    const char* str = "???.???.???.???";
    if (getpeername(fSockHandle, (sockaddr*)&addr, &slen) >= 0)
        str = inet_ntoa(addr.sin_addr);
    ST::string result(str);
    ipStrMutex.unlock();
    return result;
}