Skip to content

Commit

Permalink
operate ptr directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman committed Aug 21, 2023
1 parent 2887a2f commit 91acce0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ext-src/swoole_http_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ void php_swoole_http_request_minit(int module_number) {

// Notice: Do not change the order, see http_server_set_object_fd_property and http_server_init_array_property
zend_declare_property_long(swoole_http_request_ce, ZEND_STRL("fd"), 0, ZEND_ACC_PUBLIC);
zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("server"), ZEND_ACC_PUBLIC);
zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("header"), ZEND_ACC_PUBLIC);
zend_declare_property_long(swoole_http_request_ce, ZEND_STRL("streamId"), 0, ZEND_ACC_PUBLIC);
zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("header"), ZEND_ACC_PUBLIC);
zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("server"), ZEND_ACC_PUBLIC);
zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("cookie"), ZEND_ACC_PUBLIC);
zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("get"), ZEND_ACC_PUBLIC);
zend_declare_property_null(swoole_http_request_ce, ZEND_STRL("files"), ZEND_ACC_PUBLIC);
Expand Down
12 changes: 10 additions & 2 deletions ext-src/swoole_http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,20 @@ HttpContext *swoole_http_context_new(SessionId fd) {
object_init_ex(zresponse_object, swoole_http_response_ce);
php_swoole_http_response_set_context(zresponse_object, ctx);

/**
* see the order in the php_swoole_http_request_minit function.
* assign values based on the sorting position of property directly.
* Swoole\Http\Request::fd is the zero property.
* Swoole\Http\Response::fd is the zero property.
* Swoole\Http\Request::header is the second property.
* Swoole\Http\Request::server is the third property.
*/
http_server_set_object_fd_property(SW_Z8_OBJ_P(zrequest_object), swoole_http_request_ce, fd);
http_server_set_object_fd_property(SW_Z8_OBJ_P(zresponse_object), swoole_http_response_ce, fd);
http_server_init_array_property(
swoole_http_request_ce, SW_Z8_OBJ_P(zrequest_object), &ctx->request.zserver, 1, HT_MIN_SIZE << 1);
http_server_init_array_property(
swoole_http_request_ce, SW_Z8_OBJ_P(zrequest_object), &ctx->request.zheader, 2, HT_MIN_SIZE);
http_server_init_array_property(
swoole_http_request_ce, SW_Z8_OBJ_P(zrequest_object), &ctx->request.zserver, 3, HT_MIN_SIZE << 1);
ctx->fd = fd;

return ctx;
Expand Down

0 comments on commit 91acce0

Please sign in to comment.