“unconnected:sendto()”返回值是什么意思?

时间:2016-07-04 05:53:36

标签: lua udp return-value luasocket

LuaSocket文档说:

  

<company> <employees> <employee name="Dwight" id="e1000" department="sales"> </employee> <employee name="Toby" id="e1001" department="hr"> </employee> <employee name="Jim" id="e1002" department="sales"> </employee> <employee name="Pam" id="e1003" department="reception" /> </employees> </company>

     

如果成功,方法返回1.如果出错,则方法   返回nil后跟一条错误信息。

但是我的值为unconnected:sendto(datagram, ip, port)4的返回值是什么意思?

我的代码在这里:

4

2 个答案:

答案 0 :(得分:1)

仔细查看private void progressOrderProgress(JSONObject progressResponse) throws JSONException { JSONArray result = progressResponse.getJSONArray("orderdata"); for(int i=0; i<result.length(); i++){ OrderList orderListModule = new OrderList(); JSONObject orderData = null; try { orderData = result.getJSONObject(i); orderListModule.setPackage_name(orderData.getString("name")); orderListModule.setOrderdate(orderData.getString("date")); orderListModule.setServicedate(orderData.getString("service")); orderListModule.setServicetime(orderData.getString("time")); orderListModule.setOrderid(orderData.getString("id")); orderListModule.setOrdstatus(orderData.getString("status")); orderListModule.setOrderamount(orderData.getInt("ramount")); }catch (JSONException e) { e.printStackTrace(); } orderLists.add(orderListModule); } swipeRefreshLayout.setRefreshing(false); adapter = new ProgressOrderListAdapter(orderLists, getActivity()); recyclerView.setAdapter(adapter); } 方法<{1}}中的the source {/ 3}}

udp.c

基本上,文档&#34; 返回1 &#34;陈述是错的。代码中的sendo语句意味着实际函数返回一个值,该值实际上被压入堆栈中:

static int meth_sendto(lua_State *L) {
    p_udp udp = (p_udp) auxiliar_checkclass(L, "udp{unconnected}", 1);
    size_t count, sent = 0;
    const char *data = luaL_checklstring(L, 2, &count);
    const char *ip = luaL_checkstring(L, 3);
    const char *port = luaL_checkstring(L, 4);
    p_timeout tm = &udp->tm;
    int err;
    struct addrinfo aihint;
    struct addrinfo *ai;
    memset(&aihint, 0, sizeof(aihint));
    aihint.ai_family = udp->family;
    aihint.ai_socktype = SOCK_DGRAM;
    aihint.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
    err = getaddrinfo(ip, port, &aihint, &ai);
    if (err) {
        lua_pushnil(L);
        lua_pushstring(L, gai_strerror(err));
        return 2;
    }
    timeout_markstart(tm);
    err = socket_sendto(&udp->sock, data, count, &sent, ai->ai_addr,
        (socklen_t) ai->ai_addrlen, tm);
    freeaddrinfo(ai);
    if (err != IO_DONE) {
        lua_pushnil(L);
        lua_pushstring(L, udp_strerror(err));
        return 2;
    }
    lua_pushnumber(L, (lua_Number) sent);
    return 1;
}

其中变量return 1仅计算了上述几个语句(检查lua_pushnumber(L, (lua_Number) sent); 调用。

因此,返回的sent正好是@moteus commented发送的字节数

答案 1 :(得分:1)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul id="list1"> <li>list1 item 1</li> <li>list1 item 2</li> <li>list1 item 3</li> <li>list1 item 4</li> <li> <ul> <li>list2 item 1</li> </ul> </li> </ul>返回number of bytes sent