@@ -93,20 +93,17 @@ Iouring::Iouring(Reactor *_reactor) {
9393 int ret =
9494 io_uring_queue_init (entries, &ring, (SwooleG.iouring_flag == IORING_SETUP_SQPOLL ? IORING_SETUP_SQPOLL : 0 ));
9595 if (ret < 0 ) {
96- swoole_error_log (
97- SW_LOG_WARNING , SW_ERROR_SYSTEM_CALL_FAIL , " Create io_uring failed, the error code is %d " , -ret );
96+ errno = -ret;
97+ swoole_sys_error ( " Failed to initialize io_uring instance " );
9898 return ;
9999 }
100100
101101 if (SwooleG.iouring_workers > 0 ) {
102102 uint32_t workers[2 ] = {SwooleG.iouring_workers , SwooleG.iouring_workers };
103103 ret = io_uring_register_iowq_max_workers (&ring, workers);
104-
105104 if (ret < 0 ) {
106- swoole_error_log (SW_LOG_WARNING ,
107- SW_ERROR_SYSTEM_CALL_FAIL ,
108- " Failed to increase io_uring async workers, the error code is %d" ,
109- -ret);
105+ errno = -ret;
106+ swoole_sys_error (" Failed to set the maximum of io_uring async workers" );
110107 return ;
111108 }
112109 }
@@ -116,17 +113,13 @@ Iouring::Iouring(Reactor *_reactor) {
116113
117114#ifdef HAVE_IOURING_FUTEX
118115 if (!(major >= 6 && minor >= 7 )) {
119- swoole_error_log (SW_LOG_WARNING ,
120- SW_ERROR_OPERATION_NOT_SUPPORT ,
121- " The Iouring::futex_wait()/Iouring::futex_wakeup() requires `6.7` or higher Linux kernel" );
116+ swoole_error (" The Iouring::futex_wait()/Iouring::futex_wakeup() requires `6.7` or higher Linux kernel" );
122117 }
123118#endif
124119
125120#ifdef HAVE_IOURING_FTRUNCATE
126121 if (!(major >= 6 && minor >= 9 )) {
127- swoole_error_log (SW_LOG_WARNING ,
128- SW_ERROR_OPERATION_NOT_SUPPORT ,
129- " The Iouring::ftruncate() requires `6.9` or higher Linux kernel" );
122+ swoole_error (" The Iouring::ftruncate() requires `6.9` or higher Linux kernel" );
130123 }
131124#endif
132125
@@ -155,9 +148,11 @@ Iouring::Iouring(Reactor *_reactor) {
155148 SwooleTG.iouring ->submit (true );
156149 });
157150
158- reactor->add (ring_socket, SW_EVENT_READ );
159-
160151 reactor->iouring_interrupt_handler = [this ](Reactor *reactor) { wakeup (); };
152+
153+ if (reactor->add (ring_socket, SW_EVENT_READ ) == SW_ERR ) {
154+ swoole_sys_error (" Failed to add io_uring ring fd to the event loop" );
155+ }
161156}
162157
163158Iouring::~Iouring () {
@@ -350,15 +345,9 @@ void Iouring::submit(bool immediately) {
350345Iouring *Iouring::get_instance () {
351346 if (sw_unlikely (!SwooleTG.iouring )) {
352347 if (!swoole_event_is_available ()) {
353- swoole_warning (" no event loop, cannot initialized" );
354- throw Exception (SW_ERROR_WRONG_OPERATION );
355- }
356- auto iouring = new Iouring (sw_reactor ());
357- if (!iouring->ready ()) {
358- delete iouring;
359- return nullptr ;
348+ swoole_error (" The event loop is unavailable, unable to create io_uring instance." );
360349 }
361- SwooleTG.iouring = iouring ;
350+ SwooleTG.iouring = new Iouring ( sw_reactor ()) ;
362351 }
363352 return SwooleTG.iouring ;
364353}
0 commit comments