亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ctpmanager.cpp

?? funambol windows mobile plugin source code, the source code is taken from the funambol site
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
/*
 * Copyright (C) 2003-2007 Funambol, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */

#include <winsock2.h>
#include "Ws2tcpip.h"
#include "base/Log.h"
#include "base/util/utils.h"
#include "CTPManager.h"
#include "CTPParam.h"




// Init static pointer.
CTPManager* CTPManager::pinstance = NULL;


/**
 * Method to create the sole instance of CTPManager
 */
CTPManager* CTPManager::getInstance() {

    if (pinstance == NULL) {
        pinstance = new CTPManager;
    }
    return pinstance;
}


/**
 * Constructor: reads the CTPConfig from registry and init members.
 */
CTPManager::CTPManager() : config(APPLICATION_URI) {

    // Read config from registry
    config.readCTPConfig();
    LOG.debug("CTP config read");

    ctpSocket       = NULL;
    ctpThread       = NULL;
    receiveThread   = NULL;
    heartbeatThread = NULL;
    receivedMsg     = NULL;
}


CTPManager::~CTPManager() {
    
    stopThread(ctpThread);
    stopThread(receiveThread);
    stopThread(heartbeatThread);
    closeConnection();

    if (receivedMsg) {
        delete receivedMsg;
    }
}


/**
 * Creates the mai CTP thread, passing handle stpThread (NULL if not created)
 */
HANDLE CTPManager::startCTP(HANDLE stpThread) {

    if (ctpThread) {
        stopThread(ctpThread);
    }
    config.setLeavingState(false);

    ctpThread = CreateThread(NULL, 0, ctpWorker, (LPVOID*)stpThread, 0, NULL);
    if (!ctpThread) {
        LOG.error("Error creating CTP thread: code 0x%08x", GetLastError());
    }
    return ctpThread;
}




int CTPManager::stopCTP() {

    if (!ctpThread) {
        LOG.debug("No CTP thread available -> exiting.");
        return 1;
    }
    if (!ctpSocket) {
        LOG.debug("No socket connection -> exiting.");
        return 2;
    }

    int ret = 0;
    LOG.debug("Closing CTP connection...");


    // Terminate immediately the heartbeat thread to avoid sending 
    // any READY msg now. Keep receiveThread alive, to receive the last OK msg.
    if (stopThread(heartbeatThread)) {
        LOG.debug("heartbeatThread killed");
    }


    // Start thread to receive messages from Server if not running
    // If client authenticated, receiveThread is already running
    if (!receiveThread) {
        receiveThread = CreateThread(NULL, 0, receiveWorker, (LPVOID*)ctpSocket, 0, NULL);
        if (!receiveThread) {
            LOG.error("Error creating receive thread: code 0x%08x", GetLastError());
            return -1;
        }
        // Just to be sure the receiveWorker has reached the 'recv' state
        Sleep(1000);
    }


    // Set flag of leaving state, so receive thread will exit after the OK msg.
    config.setLeavingState(true);


    //
    // Send the BYE message
    //
    LOG.info("Sending [BYE] message...");
    if (sendByeMsg()) {
        LOG.error("Error sending the BYE message");
        goto finally;
    }


    //
    // Wait for OK msg: receive thread should exit after the last OK
    // message sent by Server.
    //
    DWORD waitResult = WaitForSingleObject(receiveThread, LEAVING_STATE_TIMEOUT * 1000);
    switch (waitResult) {

        // Thread exited normally or abandoned -> ok
        case WAIT_ABANDONED:
            LOG.debug("receiveThread abandoned");
        case WAIT_OBJECT_0: {
            DWORD exitcode = 0;
            GetExitCodeThread(receiveThread, &exitcode);
            LOG.debug("receiveThread ended with code %d", exitcode);
            ret = exitcode;
            break;
        }

        // Timeout: kill thread -> out.
        case WAIT_TIMEOUT: {
            LOG.debug("Timeout - receiveThread will now be terminated");
            TerminateThread(receiveThread, 1);
            ret = 1;
            break;
        }

        // Some error occurred (case WAIT_FAILED)
        default: {
            LOG.debug("Wait error on receiveThread");
            TerminateThread(receiveThread, 1);
            ret = 2;
            break;
        }
    }
    CloseHandle(receiveThread);
    receiveThread = NULL;


finally:

    // Close them if still running...
    if (stopThread(receiveThread)) {
        LOG.debug("receiveThread killed");
    }
    if (stopThread(ctpThread)) {
        LOG.debug("ctpThread killed");
    }

    //
    // Close socket connection
    //
    closeConnection();

    return ret;
}







int CTPManager::openConnection(){

    DWORD errorCode = 0;
    int ret = 0;

    if (ctpSocket) {
        closeConnection();
    }
    LOG.debug("--- Starting a new SOCKET connection ---");

    //
    // Initialize Winsock
    //
    WORD versionRequested = MAKEWORD(1, 1);
	WSADATA wsaData;
    ret = WSAStartup(versionRequested, &wsaData);
    if (ret != NO_ERROR) {
        errorCode = WSAGetLastError();
        LOG.error("SOCKET WSAStartup() error %d: %s", errorCode, createErrorMsg(errorCode));
        return -1;
    }

    // Check if version is correct 
    if (wsaData.wVersion != versionRequested) {
        LOG.error("WinSock version not supported: %d (%d expected)", wsaData.wVersion, versionRequested);
        return -1;
	}


    //
    // Find the server
    //
    LOG.debug("Find the server address...");
    struct addrinfo aiHints;
    struct addrinfo *aiList = NULL;
    
    // Setup the hints address info structure
    // which is passed to the getaddrinfo() function
    memset(&aiHints, 0, sizeof(aiHints));
    aiHints.ai_family   = AF_INET;				// Address family
    aiHints.ai_socktype = SOCK_STREAM;			// Socket type
    aiHints.ai_protocol = IPPROTO_TCP;		    // Protocol
    aiHints.ai_flags    = AI_CANONNAME;         // To get the canonical name

    const char* hostName = config.getUrlTo().c_str();
    char port[10];
    sprintf(port, "%d", config.getCtpPort());
    LOG.info("HOSTNAME = '%s'  PORT = '%s'", hostName, port);

    // Resolve the host name.
    ret = getaddrinfo(hostName, port, &aiHints, &aiList);
    if (ret) {
		lastErrorCode = ERR_HOST_NOT_FOUND;
        LOG.error("getaddrinfo() failed: %s", gai_strerror(ret));
        ret = -2;
        goto finally;
    }

    struct addrinfo *addr = aiList;

    // Loop on possible addresses
    while (addr != NULL) {
        //
        // Create a TCP/IP stream socket
        //
        LOG.debug("Create SOCKET connection...");
        ctpSocket = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
        if (ctpSocket == INVALID_SOCKET) {
            if (addr->ai_next != NULL) {
                addr=addr->ai_next;        // take next address
                continue;
            }
            else {
                errorCode = WSAGetLastError();
                LOG.error("SOCKET socket() error %d: %s", errorCode, createErrorMsg(errorCode));
                ret = -3;
                goto finally;
            }
        }

        //
        // Connect to the server
        //
        LOG.debug("Connecting to '%s'...", hostName);
        ret = connect(ctpSocket, addr->ai_addr, addr->ai_addrlen);
        if (ret == SOCKET_ERROR) {
            if (addr->ai_next != NULL) {
                addr=addr->ai_next;        // take next address
                closesocket(ctpSocket);
                continue;
            }
            else {
                errorCode = WSAGetLastError();
                if (errorCode == WSAECONNREFUSED) {
                    LOG.error("SOCKET connect() error: Server not responding at %s:%s", hostName, port);
                }
                else {
                    LOG.error("SOCKET connect() error %d: %s", errorCode, createErrorMsg(errorCode));
                }
                ret = -4;
                goto finally;
            }
        }
        LOG.info("Succesfully connected to %s!", addr->ai_canonname);
        break;
    }

finally:
    if (aiList) {
        freeaddrinfo(aiList);
    }
    return ret;
}




int CTPManager::closeConnection(){

    int ret = 0;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美不卡一区二区| 国产一区 二区| 综合亚洲深深色噜噜狠狠网站| 91精品国产乱| 欧美高清激情brazzers| 91精品国产色综合久久不卡电影 | 亚洲精品一区二区三区四区高清 | 人人狠狠综合久久亚洲| 偷拍一区二区三区四区| 三级影片在线观看欧美日韩一区二区| 亚洲天堂成人在线观看| 一区二区三区 在线观看视频| 亚洲精选视频在线| 午夜精品视频一区| 日本va欧美va瓶| 国产精品12区| 99精品久久99久久久久| 欧美日韩一区二区三区在线 | 亚洲欧美欧美一区二区三区| 亚洲在线视频一区| 日韩一区二区精品| 99精品偷自拍| 国产精品综合一区二区| 国产精品一卡二卡在线观看| aaa亚洲精品| 欧美三区免费完整视频在线观看| 91精品国产91久久综合桃花 | 天天色天天操综合| 国产原创一区二区三区| 99久久99久久免费精品蜜臀| 欧美群妇大交群中文字幕| 精品国精品国产尤物美女| 亚洲欧洲精品天堂一级| 视频一区中文字幕| 春色校园综合激情亚洲| 欧美精品粉嫩高潮一区二区| 国产嫩草影院久久久久| 天堂蜜桃91精品| 99精品国产99久久久久久白柏| 午夜影院在线观看欧美| 亚洲综合精品自拍| 视频一区国产视频| 成人av网在线| 日韩一区二区免费电影| 亚洲免费资源在线播放| 国产一区欧美二区| 欧美日韩美少妇| 亚洲人一二三区| 国产大片一区二区| 欧美精品在线观看播放| 136国产福利精品导航| 国产一区在线不卡| 欧美肥大bbwbbw高潮| 亚洲免费观看高清完整版在线| 国产精华液一区二区三区| 欧美不卡一区二区| 免费国产亚洲视频| 9191久久久久久久久久久| 亚洲男人电影天堂| 91丨国产丨九色丨pron| 亚洲国产成人午夜在线一区| 国产专区欧美精品| 日韩欧美在线观看一区二区三区| 亚洲欧洲美洲综合色网| eeuss鲁一区二区三区| 欧美国产一区视频在线观看| 精品一区二区在线视频| 日韩欧美国产综合在线一区二区三区| 亚洲va国产天堂va久久en| 色94色欧美sute亚洲线路二 | 欧美日韩视频在线第一区| 亚洲欧洲制服丝袜| 92精品国产成人观看免费| 国产精品黄色在线观看| 不卡一区中文字幕| 日韩一区中文字幕| 91蝌蚪国产九色| 亚洲三级电影网站| 在线观看免费成人| 亚洲成年人网站在线观看| 欧美视频中文字幕| 日本伊人色综合网| 久久蜜桃av一区精品变态类天堂 | 国产精品初高中害羞小美女文| 午夜婷婷国产麻豆精品| 日韩视频不卡中文| 日本不卡视频在线观看| 久久综合久久综合久久| 波多野结衣精品在线| 欧美国产日本视频| 91视频91自| 亚洲成av人片在www色猫咪| 欧美另类高清zo欧美| 日韩高清一区在线| 久久久美女毛片| 99久免费精品视频在线观看| 亚洲成人免费视频| 欧美大黄免费观看| aaa亚洲精品| 免费人成精品欧美精品| 久久综合九色综合97婷婷女人| 国产成人精品www牛牛影视| 亚洲激情五月婷婷| 精品久久久久久久人人人人传媒 | 亚洲欧美日韩系列| 亚洲激情成人在线| 亚洲成人免费视| 欧美一区二区播放| 成人av资源在线| 亚洲韩国精品一区| 精品久久久久久综合日本欧美| 丁香激情综合国产| 亚洲午夜久久久| 久久久国产一区二区三区四区小说| 一本一本大道香蕉久在线精品| 午夜精品影院在线观看| 国产亚洲成aⅴ人片在线观看 | 中文乱码免费一区二区| 一本大道综合伊人精品热热| 毛片av一区二区三区| 亚洲精品老司机| 2024国产精品| 欧美放荡的少妇| 久久精品视频在线看| 亚洲一区二区四区蜜桃| 久久99精品网久久| 国产偷v国产偷v亚洲高清| 欧美日韩成人综合天天影院 | 欧美日韩高清在线播放| 成人在线视频一区二区| 美女一区二区视频| 亚洲高清在线视频| 亚洲欧洲性图库| 日本一区二区久久| 欧美mv日韩mv| 欧美一卡2卡三卡4卡5免费| 91极品美女在线| 不卡的av电影| 国产精品1区2区3区| 麻豆精品视频在线观看| 亚洲国产欧美在线| 亚洲精品你懂的| 中文字幕一区二区视频| 国产三区在线成人av| 在线不卡中文字幕| 日本亚洲免费观看| 在线视频中文字幕一区二区| 亚洲一卡二卡三卡四卡五卡| 1区2区3区欧美| 亚洲欧美国产高清| 中文字幕一区二区5566日韩| 欧美国产一区二区| 国产精品亲子乱子伦xxxx裸| 国产亲近乱来精品视频| 精品久久一区二区| 91黄色免费看| 欧美三区免费完整视频在线观看| 色哟哟一区二区在线观看| 成人国产精品免费观看动漫| 成人激情免费网站| 99精品欧美一区二区蜜桃免费| 99久免费精品视频在线观看| 99精品桃花视频在线观看| 欧美日韩在线三区| 欧美挠脚心视频网站| 51精品秘密在线观看| 欧美不卡一区二区三区| 国产午夜亚洲精品羞羞网站| 国产蜜臀av在线一区二区三区| 国产精品久久久久影视| 亚洲精品水蜜桃| 视频在线观看国产精品| 精品中文字幕一区二区| 懂色av一区二区夜夜嗨| 97久久超碰精品国产| 欧美日韩久久久| 亚洲精品一区二区三区影院| 国产日韩欧美麻豆| 亚洲精品免费电影| 日韩电影免费在线看| 国产精品一区免费视频| 一本大道久久a久久综合婷婷| 欧美三区在线观看| 国产日韩欧美一区二区三区综合 | 亚洲乱码日产精品bd| 亚洲成av人影院在线观看网| 久久99精品久久久久久国产越南| 成人国产视频在线观看| 5月丁香婷婷综合| 欧美激情在线一区二区| 天天综合色天天综合色h| 国产在线一区二区| 欧美在线综合视频| 精品女同一区二区| 亚洲精品中文在线观看| 日韩精品五月天| 99re成人在线| 精品久久久久久无| 午夜精品一区二区三区电影天堂 | 欧美一区二区三区啪啪|