MCPcopy Create free account
hub / github.com/apache/trafficserver / ts_lua_fetch_multi

Function ts_lua_fetch_multi

plugins/lua/ts_lua_fetch.cc:114–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114static int
115ts_lua_fetch_multi(lua_State *L)
116{
117 int type, sz;
118 size_t i, n;
119 const char *url;
120 size_t url_len;
121 TSCont contp;
122 ts_lua_cont_info *ci;
123 ts_lua_async_item *ai;
124 ts_lua_fetch_info *fi;
125 ts_lua_fetch_multi_info *fmi;
126
127 ci = ts_lua_get_cont_info(L);
128 if (ci == nullptr) {
129 TSError("[ts_lua][%s] no cont info found", __FUNCTION__);
130 TSReleaseAssert(!"Unexpected fetch of cont info");
131 return 0;
132 }
133
134 if (lua_gettop(L) < 1) {
135 return luaL_error(L, "'ts.fetch_mutli' requires one parameter");
136 }
137
138 type = lua_type(L, 1);
139 if (type != LUA_TTABLE) {
140 return luaL_error(L, "'ts.fetch_mutli' requires table as parameter");
141 }
142
143 // main continuation handler
144 contp = TSContCreate(ts_lua_fetch_multi_handler, ci->mutex);
145
146 // Iterate the table
147 n = lua_objlen(L, 1);
148
149 sz = sizeof(ts_lua_fetch_multi_info) + n * sizeof(ts_lua_fetch_info);
150 fmi = (ts_lua_fetch_multi_info *)TSmalloc(sz);
151
152 memset(fmi, 0, sz);
153 fmi->total = n;
154 fmi->contp = contp;
155 fmi->multi = 1;
156
157 for (i = 0; i < n; i++) {
158 /* push fetch item */
159 lua_pushinteger(L, i + 1);
160 lua_gettable(L, -2);
161
162 if (lua_objlen(L, -1) < 1) {
163 ts_lua_destroy_fetch_multi_info(fmi);
164 TSContDestroy(contp);
165
166 return luaL_error(L, "'ts.fetch_mutli' got empty table item");
167 }
168
169 /* push url */
170 lua_pushnumber(L, 1);
171 lua_gettable(L, -2);

Callers

nothing calls this directly

Calls 12

ts_lua_get_cont_infoFunction · 0.85
TSContCreateFunction · 0.85
TSmallocFunction · 0.85
memsetFunction · 0.85
TSContDestroyFunction · 0.85
TSIOBufferCreateFunction · 0.85
TSIOBufferReaderAllocFunction · 0.85
ts_lua_fetch_one_itemFunction · 0.85
ts_lua_async_create_itemFunction · 0.85
TSContDataSetFunction · 0.85
TSErrorFunction · 0.50

Tested by

no test coverage detected