int swoole_websocket_onMessage(swEventData *req) { #if PHP_MAJOR_VERSION < 7 TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL); #endif int fd = req->info.fd; zval *zdata; SW_MAKE_STD_ZVAL(zdata); zdata = php_swoole_get_recv_data(zdata, req TSRMLS_CC); char *buf = Z_STRVAL_P(zdata); long finish = buf[0] ? 1 : 0; long opcode = buf[1] ? 1 : 0; zval *zframe; SW_MAKE_STD_ZVAL(zframe); object_init_ex(zframe, swoole_websocket_frame_class_entry_ptr); zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("fd"), fd TSRMLS_CC); zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("finish"), finish TSRMLS_CC); zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("opcode"), opcode TSRMLS_CC); zend_update_property_stringl(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("data"), buf + 2, (Z_STRLEN_P(zdata) - 2) TSRMLS_CC); swServer *serv = SwooleG.serv; zval *zserv = (zval *) serv->ptr2; zval **args[2]; args[0] = &zserv; args[1] = &zframe; zval *retval = NULL; if (sw_call_user_function_ex(EG(function_table), NULL, websocket_callbacks[WEBSOCKET_CALLBACK_onMessage], &retval, 2, args, 0, NULL TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "onMessage handler error"); } if (EG(exception)) { zend_exception_error(EG(exception), E_ERROR TSRMLS_CC); } if (retval) { sw_zval_ptr_dtor(&retval); } sw_zval_ptr_dtor(&zdata); sw_zval_ptr_dtor(&zframe); return SW_OK; }
int swoole_websocket_onMessage(swEventData *req) { #if PHP_MAJOR_VERSION < 7 TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL); #endif int fd = req->info.fd; zval *zdata; SW_MAKE_STD_ZVAL(zdata); char frame_header[2]; php_swoole_get_recv_data(zdata, req, frame_header, 2); long finish = frame_header[0] ? 1 : 0; long opcode = frame_header[1]; zval *zframe; SW_MAKE_STD_ZVAL(zframe); object_init_ex(zframe, swoole_websocket_frame_class_entry_ptr); zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("fd"), fd TSRMLS_CC); zend_update_property_bool(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("finish"), finish TSRMLS_CC); zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("opcode"), opcode TSRMLS_CC); zend_update_property(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("data"), zdata TSRMLS_CC); swServer *serv = SwooleG.serv; zval *zserv = (zval *) serv->ptr2; zval **args[2]; args[0] = &zserv; args[1] = &zframe; zval *retval = NULL; zval *zcallback = php_swoole_server_get_callback(serv, req->info.from_fd, SW_SERVER_CB_onMessage); if (sw_call_user_function_ex(EG(function_table), NULL, zcallback, &retval, 2, args, 0, NULL TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "onMessage handler error"); } if (EG(exception)) { zend_exception_error(EG(exception), E_ERROR TSRMLS_CC); } if (retval) { sw_zval_ptr_dtor(&retval); } sw_zval_ptr_dtor(&zdata); sw_zval_ptr_dtor(&zframe); return SW_OK; }
int swoole_websocket_onMessage(swEventData *req) { #if PHP_MAJOR_VERSION < 7 TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL); #endif int fd = req->info.fd; zval *zdata; SW_MAKE_STD_ZVAL(zdata); char frame_header[2]; php_swoole_get_recv_data(zdata, req, frame_header, 2); long finish = frame_header[0] ? 1 : 0; long opcode = frame_header[1]; zval *zframe; SW_MAKE_STD_ZVAL(zframe); object_init_ex(zframe, swoole_websocket_frame_class_entry_ptr); zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("fd"), fd TSRMLS_CC); zend_update_property_bool(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("finish"), finish TSRMLS_CC); zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("opcode"), opcode TSRMLS_CC); zend_update_property(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("data"), zdata TSRMLS_CC); swServer *serv = SwooleG.serv; zval *zserv = (zval *) serv->ptr2; #ifndef SW_COROUTINE zval **args[2]; args[0] = &zserv; args[1] = &zframe; #else zval *args[2]; args[0] = zserv; args[1] = zframe; #endif zval *retval = NULL; #ifndef SW_COROUTINE zend_fcall_info_cache *fci_cache = php_swoole_server_get_cache(serv, req->info.from_fd, SW_SERVER_CB_onMessage); zval *zcallback = php_swoole_server_get_callback(SwooleG.serv, req->info.from_fd, SW_SERVER_CB_onMessage); if (sw_call_user_function_fast(zcallback, fci_cache, &retval, 2, args TSRMLS_CC) == FAILURE) { swoole_php_error(E_WARNING, "onMessage handler error"); } #else zend_fcall_info_cache *cache = php_swoole_server_get_cache(serv, req->info.from_fd, SW_SERVER_CB_onMessage); int ret = coro_create(cache, args, 2, &retval, NULL, NULL); if (ret != 0) { sw_zval_ptr_dtor(&zdata); sw_zval_ptr_dtor(&zframe); if (ret == CORO_LIMIT) { SwooleG.serv->factory.end(&SwooleG.serv->factory, fd); } return SW_OK; } #endif if (EG(exception)) { zend_exception_error(EG(exception), E_ERROR TSRMLS_CC); } if (retval) { sw_zval_ptr_dtor(&retval); } sw_zval_ptr_dtor(&zdata); sw_zval_ptr_dtor(&zframe); return SW_OK; }