Skip to content

Commit

Permalink
Update code format
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeei authored Aug 22, 2024
1 parent f5e3de5 commit 0bd6cd6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/ngx_http_lua_socket_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,9 @@ ngx_http_lua_socket_udp_send(lua_State *L)
}



#define stack_diff 1


static int
ngx_http_lua_socket_udp_buff_send(lua_State *L)
{
Expand Down Expand Up @@ -1033,14 +1034,17 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L)
size_t start = luaL_checklong(L, -2);
size_t end = luaL_checklong(L, -1);
buff_str = luaL_checklstring(L, -3, &buf_len);

if (start < 1 || end > buf_len || start > end || start > buf_len)
{
lua_pushnil(L);
lua_pushliteral(L, "start or end index invalid");
return 2;
}

size = (end - start + 1);
buf_len = size;

if (stack_size > 3 + stack_diff)
{
for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++)
Expand All @@ -1049,21 +1053,24 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L)
size += head_len;
}
}

// copy msg
query.data = lua_newuserdata(L, size);
query.len = size;
msg_tmp = query.data;
lua_pop(L, 1);

if (stack_size > 3 + stack_diff)
{
for (int i = (-1 * stack_size) + stack_diff; i <= -4; i++)
{
header_str = lua_tolstring(L, i, &head_len);
msg_tmp = ngx_cpymem(msg_tmp, (u_char *)header_str, head_len);
msg_tmp = ngx_cpymem(msg_tmp, (u_char *) header_str, head_len);
}
}

buff_str = buff_str + start - 1;
ngx_memcpy(msg_tmp, (u_char *)buff_str, buf_len);
ngx_memcpy(msg_tmp, (u_char *) buff_str, buf_len);

u->ft_type = 0;

Expand Down Expand Up @@ -1098,6 +1105,7 @@ ngx_http_lua_socket_udp_buff_send(lua_State *L)
return 1;
}


static int
ngx_http_lua_socket_udp_receive(lua_State *L)
{
Expand Down

0 comments on commit 0bd6cd6

Please sign in to comment.