@@ -1146,15 +1146,15 @@ ds_ipc_poll (
11461146 // check for hangup first because a closed socket
11471147 // will technically meet the requirements for POLLIN
11481148 // i.e., a call to recv/read won't block
1149- poll_handles_data [i ].events = (uint8_t )DS_IPC_POLL_EVENTS_HANGUP ;
1149+ poll_handles_data [i ].events = (uint8_t )EP_IPC_POLL_EVENTS_HANGUP ;
11501150 } else if ((poll_fds [i ].revents & (POLLERR |POLLNVAL ))) {
11511151 if (callback )
11521152 callback ("Poll error" , (uint32_t )poll_fds [i ].revents );
1153- poll_handles_data [i ].events = (uint8_t )DS_IPC_POLL_EVENTS_ERR ;
1153+ poll_handles_data [i ].events = (uint8_t )EP_IPC_POLL_EVENTS_ERR ;
11541154 } else if (poll_fds [i ].revents & (POLLIN |POLLPRI )) {
1155- poll_handles_data [i ].events = (uint8_t )DS_IPC_POLL_EVENTS_SIGNALED ;
1155+ poll_handles_data [i ].events = (uint8_t )EP_IPC_POLL_EVENTS_SIGNALED ;
11561156 } else {
1157- poll_handles_data [i ].events = (uint8_t )DS_IPC_POLL_EVENTS_UNKNOWN ;
1157+ poll_handles_data [i ].events = (uint8_t )EP_IPC_POLL_EVENTS_UNKNOWN ;
11581158 if (callback )
11591159 callback ("unknown poll response" , (uint32_t )poll_fds [i ].revents );
11601160 }
@@ -1489,12 +1489,24 @@ ipc_stream_close_func (void *object)
14891489 return ds_ipc_stream_close (ipc_stream , NULL );
14901490}
14911491
1492+ static
1493+ EventPipeIpcPollEvents
1494+ ipc_stream_poll_func (
1495+ void * object ,
1496+ uint32_t timeout_ms )
1497+ {
1498+ EP_ASSERT (object != NULL );
1499+ DiagnosticsIpcStream * ipc_stream = (DiagnosticsIpcStream * )object ;
1500+ return ds_ipc_stream_poll (ipc_stream , timeout_ms );
1501+ }
1502+
14921503static IpcStreamVtable ipc_stream_vtable = {
14931504 ipc_stream_free_func ,
14941505 ipc_stream_read_func ,
14951506 ipc_stream_write_func ,
14961507 ipc_stream_flush_func ,
1497- ipc_stream_close_func };
1508+ ipc_stream_close_func ,
1509+ ipc_stream_poll_func };
14981510
14991511static
15001512DiagnosticsIpcStream *
@@ -1668,6 +1680,44 @@ ds_ipc_stream_to_string (
16681680 return (result > 0 && result < (int32_t )buffer_len ) ? result : 0 ;
16691681}
16701682
1683+ EventPipeIpcPollEvents
1684+ ds_ipc_stream_poll (
1685+ DiagnosticsIpcStream * ipc_stream ,
1686+ uint32_t timeout_ms )
1687+ {
1688+ EP_ASSERT (ipc_stream != NULL );
1689+
1690+ if (ipc_stream -> client_socket == DS_IPC_INVALID_SOCKET )
1691+ return EP_IPC_POLL_EVENTS_HANGUP ;
1692+
1693+ ds_ipc_pollfd_t pfd ;
1694+ pfd .fd = ipc_stream -> client_socket ;
1695+ pfd .events = POLLIN | POLLPRI | POLLOUT ;
1696+
1697+ int result_poll ;
1698+ result_poll = ipc_poll_fds (& pfd , 1 , timeout_ms );
1699+
1700+ if (result_poll < 0 )
1701+ return EP_IPC_POLL_EVENTS_ERR ;
1702+
1703+ if (result_poll == 0 )
1704+ return EP_IPC_POLL_EVENTS_HANGUP ;
1705+
1706+ if (pfd .revents == 0 )
1707+ return EP_IPC_POLL_EVENTS_NONE ;
1708+
1709+ if (pfd .revents & POLLHUP )
1710+ return EP_IPC_POLL_EVENTS_HANGUP ;
1711+
1712+ if (pfd .revents & (POLLERR | POLLNVAL ))
1713+ return EP_IPC_POLL_EVENTS_ERR ;
1714+
1715+ if (pfd .revents & (POLLIN | POLLPRI | POLLOUT ))
1716+ return EP_IPC_POLL_EVENTS_SIGNALED ;
1717+
1718+ return EP_IPC_POLL_EVENTS_UNKNOWN ;
1719+ }
1720+
16711721#endif /* ENABLE_PERFTRACING */
16721722
16731723#ifndef DS_INCLUDE_SOURCE_FILES
0 commit comments