Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jun 19, 2023
1 parent 7f2e0ea commit cc0a257
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions ext-src/php_swoole_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ struct Context {
size_t current_form_data_name_len;
zval *current_multipart_header;
String *form_data_buffer;
zend_string *addr_cache;

std::string upload_tmp_dir;

Expand Down
14 changes: 7 additions & 7 deletions ext-src/swoole_http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,11 @@ int php_swoole_http_server_onReceive(Server *serv, RecvData *req) {
ZVAL_LONG(&tmp, conn->info.get_port());
zend_hash_str_add(ht, ZEND_STRL("remote_port"), &tmp);

if (conn->socket_type == SW_SOCK_TCP || conn->socket_type == SW_SOCK_TCP6) {
if (!conn->addr_cache) {
conn->addr_cache = (char *) conn->info.get_ip();
}
ZVAL_STRING(&tmp, conn->addr_cache);
} else {
ZVAL_STRING(&tmp, (char *) conn->info.get_ip());
if (!ctx->addr_cache) {
auto addr = conn->info.get_ip();
ctx->addr_cache = zend_string_init(addr, strlen(addr), 0);
}
ZVAL_STR_COPY(&tmp, ctx->addr_cache);
zend_hash_str_add(ht, ZEND_STRL("remote_addr"), &tmp);

ZVAL_LONG(&tmp, (int) conn->last_recv_time);
Expand Down Expand Up @@ -309,6 +306,9 @@ void HttpContext::free() {
if (write_buffer) {
delete write_buffer;
}
if (addr_cache) {
zend_string_release(addr_cache);
}
delete this;
}

Expand Down
1 change: 0 additions & 1 deletion include/swoole_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ struct Connection {
pid_t ssl_client_cert_pid;
#endif
sw_atomic_t lock;
char *addr_cache;
};

//------------------------------------ReactorThread-------------------------------------------
Expand Down

0 comments on commit cc0a257

Please sign in to comment.