예제 #1
0
static void vm_preload_do_connection(vm_preload_ctx_t * ctx_p, VMINT n)
{

    vm_apn_info_ext info = {0};
    VMUINT dtacct_id;
    vm_get_encoded_dtacct_id(VM_TCP_APN_CMWAP, &dtacct_id);
    
    if (vm_wifi_is_connected())
    {
        ctx_p->soc_id = vm_tcp_connect(ctx_p->host, ctx_p->port, ctx_p->apn, _vm_preload_cb); 
        MMI_PRINT(MOD_MRE, MMI_MRE_TRC_MOD_VMSOCK,"preload cnt wifi1[%s, %d] npx[%d]", 
            ctx_p->host, ctx_p->port, n);
    }
    else
    {
        if (0 == vm_get_apn_info(&info)) // px
        {
            memset(&info, 0, sizeof(info));
            if (0 == vm_get_default_apn_info(&info))
            {
                if (info.apn_info_id)
                {
                    //ctx_p->apn = 2;
                    ctx_p->soc_id = vm_tcp_connect(info.proxy_ip, info.proxy_port, VM_TCP_APN_CMWAP, _vm_preload_cb);
                    MMI_PRINT(MOD_MRE, MMI_MRE_TRC_MOD_VMSOCK,"preload cnt [%s, %d] px[%d]", 
                        info.proxy_ip, info.proxy_port, n);
                }
                else
                {
                    ctx_p->soc_id = vm_tcp_connect(ctx_p->host, ctx_p->port, ctx_p->apn, _vm_preload_cb); 
                    MMI_PRINT(MOD_MRE, MMI_MRE_TRC_MOD_VMSOCK,"preload cnt [%s, %d] npx[%d]", 
                        info.proxy_ip, info.proxy_port, n);
                }
            }
            else // wifi without sim
            {
                ctx_p->soc_id = vm_tcp_connect(ctx_p->host, ctx_p->port, ctx_p->apn, _vm_preload_cb); 
                MMI_PRINT(MOD_MRE, MMI_MRE_TRC_MOD_VMSOCK,"preload cnt 1[%s, %d] npx[%d]", 
                    ctx_p->host, ctx_p->port, n);
            }
        }
        else // npx
        {
            ctx_p->soc_id = vm_tcp_connect(ctx_p->host, ctx_p->port, ctx_p->apn, _vm_preload_cb); 
            MMI_PRINT(MOD_MRE, MMI_MRE_TRC_MOD_VMSOCK,"preload cnt 2[%s, %d] npx[%d]", 
                ctx_p->host, ctx_p->port, n);
        }
    }

}
예제 #2
0
//===========================
int tcp_connect(lua_State* L)
{
    tcp_info_t* p;
    int ref;
    char* addr = luaL_checkstring(L, 1);
    unsigned port = luaL_checkinteger(L, 2);

    p = (tcp_info_t*)lua_newuserdata(L, sizeof(tcp_info_t));

    if ((lua_type(L, 3) == LUA_TFUNCTION) || (lua_type(L, 3) == LUA_TLIGHTFUNCTION)) {
		lua_pushvalue(L, 3);
		ref = luaL_ref(L, LUA_REGISTRYINDEX);
	    p->cb_ref = ref;
    }
    else {
    	p->cb_ref = LUA_NOREF;
        size_t sl;
        const char* pdata = luaL_checklstring(L, 3, &sl);
        if ((sl <= 0) || (pdata == NULL)) {
            return luaL_error(L, "wrong send data");
        }
        if (send_buf != NULL) {
        	vm_free(send_buf);
        }
        send_buf = vm_malloc(sl+1);
        if (send_buf == NULL) {
            return luaL_error(L, "buffer allocation error");
        }

        strncpy(send_buf, pdata, sl);
        send_buf[sl] = '\0';
    }

    luaL_getmetatable(L, LUA_TCP);
    lua_setmetatable(L, -2);

    p->L = L;
    p->handle = vm_tcp_connect(addr, port, gprs_bearer_type, p, __tcp_callback);

    return 1;
}