예제 #1
0
파일: tcp.c 프로젝트: AitorATuin/luv
static int luv_tcp_connect(lua_State* L) {
  uv_tcp_t* handle = luv_check_tcp(L, 1);
  const char* host = luaL_checkstring(L, 2);
  int port = luaL_checkinteger(L, 3);
  struct sockaddr_storage addr;
  uv_connect_t* req;
  int ret, ref;
  if (uv_ip4_addr(host, port, (struct sockaddr_in*)&addr) &&
      uv_ip6_addr(host, port, (struct sockaddr_in6*)&addr)) {
    return luaL_error(L, "Invalid IP address or port [%s:%d]", host, port);
  }
  ref = luv_check_continuation(L, 4);

  req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  ret = uv_tcp_connect(req, handle, (struct sockaddr*)&addr, luv_connect_cb);
  if (ret < 0) {
    lua_pop(L, 1);
    return luv_error(L, ret);
  }
  return 1;
}
예제 #2
0
파일: tcp.c 프로젝트: senlinms/luv
static int luv_write_queue_size(lua_State* L) {
  uv_tcp_t* handle = luv_check_tcp(L, 1);
  lua_pushinteger(L, handle->write_queue_size);
  return 1;
}