Skip to content

Commit

Permalink
refactor rpc_query_data
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Sadokhov committed Oct 12, 2023
1 parent 00f14a4 commit f2e9b7d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
10 changes: 5 additions & 5 deletions runtime/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,10 +1736,10 @@ static void init_superglobals_impl(const http_query_data &http_data, const rpc_q
if (rpc_data.header.qid) {
v$_SERVER.set_value(string("RPC_REQUEST_ID"), f$strval(static_cast<int64_t>(rpc_data.header.qid)));
save_rpc_query_headers(rpc_data.header);
v$_SERVER.set_value(string("RPC_REMOTE_IP"), static_cast<int>(rpc_data.ip));
v$_SERVER.set_value(string("RPC_REMOTE_PORT"), static_cast<int>(rpc_data.port));
v$_SERVER.set_value(string("RPC_REMOTE_PID"), static_cast<int>(rpc_data.pid));
v$_SERVER.set_value(string("RPC_REMOTE_UTIME"), rpc_data.utime);
v$_SERVER.set_value(string("RPC_REMOTE_IP"), static_cast<int>(rpc_data.remote_pid.ip));
v$_SERVER.set_value(string("RPC_REMOTE_PORT"), static_cast<int>(rpc_data.remote_pid.port));
v$_SERVER.set_value(string("RPC_REMOTE_PID"), static_cast<int>(rpc_data.remote_pid.pid));
v$_SERVER.set_value(string("RPC_REMOTE_UTIME"), rpc_data.remote_pid.utime);
}
is_head_query = false;
if (http_data.request_method_len) {
Expand Down Expand Up @@ -1799,7 +1799,7 @@ static void init_superglobals_impl(const http_query_data &http_data, const rpc_q
}

static http_query_data empty_http_data;
static rpc_query_data empty_rpc_data(tl_query_header_t(), {}, 0, 0, 0, 0);
static rpc_query_data empty_rpc_data{tl_query_header_t(), {}, {}};
static job_query_data empty_job_data;

void init_superglobals(const php_query_data_t &data) {
Expand Down
7 changes: 3 additions & 4 deletions server/php-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,17 +1010,16 @@ int rpcx_execute(connection *c, int op, raw_message *raw) {
double actual_script_timeout = custom_settings.has_timeout() ? normalize_script_timeout(custom_settings.php_timeout_ms / 1000.0) : script_timeout;
set_connection_timeout(c, actual_script_timeout);

std::vector<int> buffer(len / static_cast<int>(sizeof(int)));
std::vector<int> buffer((len + sizeof(int)) / sizeof(int));
auto fetched_bytes = tl_fetch_data(buffer.data(), len);
if (fetched_bytes == -1) {
client_rpc_error(c, req_id, tl_fetch_error_code(), tl_fetch_error_string());
return 0;
}
assert(fetched_bytes == len);
auto *D = TCP_RPC_DATA(c);
php_worker.emplace(run_once ? once_worker : rpc_worker, c,
rpc_query_data(std::move(header), std::move(buffer), D->remote_pid.ip, D->remote_pid.port, D->remote_pid.pid, D->remote_pid.utime)
, req_id, actual_script_timeout);
php_query_data_t rpc_data = rpc_query_data{std::move(header), std::move(buffer), D->remote_pid};
php_worker.emplace(run_once ? once_worker : rpc_worker, c, std::move(rpc_data), req_id, actual_script_timeout);
D->extra = &php_worker.value();

c->status = conn_wait_net;
Expand Down
10 changes: 1 addition & 9 deletions server/php-query-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@ struct http_query_data {
struct rpc_query_data {
tl_query_header_t header;
std::vector<int> data;
unsigned ip;
short port;
short pid;
int utime;

rpc_query_data(tl_query_header_t header, std::vector<int> src, unsigned ip, short port, short pid, int utime)
: header(std::move(header)), data(std::move(src)), ip(ip), port(port), pid(pid), utime(utime) {

}
process_id remote_pid;
};

namespace job_workers {
Expand Down

0 comments on commit f2e9b7d

Please sign in to comment.