(&self, socket: WebKitSocket)
| 254 | } |
| 255 | |
| 256 | async fn run_connection(&self, socket: WebKitSocket) -> Result<(), AppError> { |
| 257 | let mut stream = timeout(WEBKIT_IO_TIMEOUT, UnixStream::connect(&socket.path)) |
| 258 | .await |
| 259 | .map_err(|_| AppError::native("Timed out connecting to simulator webinspectord."))? |
| 260 | .map_err(|error| { |
| 261 | AppError::native(format!( |
| 262 | "Unable to connect to simulator webinspectord at {}: {error}", |
| 263 | socket.path |
| 264 | )) |
| 265 | })?; |
| 266 | |
| 267 | let connection_id = new_remote_inspector_id(); |
| 268 | send_rpc( |
| 269 | &mut stream, |
| 270 | "_rpc_reportIdentifier:", |
| 271 | rpc_args(&connection_id), |
| 272 | ) |
| 273 | .await?; |
| 274 | sleep(WEBKIT_SOCKET_ACTIVATION_DELAY).await; |
| 275 | send_get_connected_applications(&mut stream, &connection_id).await?; |
| 276 | |
| 277 | let mut next_listing_refresh = Instant::now() + WEBKIT_DISCOVERY_REFRESH_INTERVAL; |
| 278 | let mut applications: BTreeMap<String, WebKitApplication> = BTreeMap::new(); |
| 279 | let mut requested_listings: HashSet<String> = HashSet::new(); |
| 280 | let mut pages: BTreeMap<(String, u64), WebKitPage> = BTreeMap::new(); |
| 281 | |
| 282 | loop { |
| 283 | let read_timeout = Duration::from_millis(500); |
| 284 | let packet = match timeout(read_timeout, read_packet(&mut stream)).await { |
| 285 | Ok(Ok(packet)) => packet, |
| 286 | Ok(Err(error)) => return Err(error), |
| 287 | Err(_) => { |
| 288 | if Instant::now() >= next_listing_refresh { |
| 289 | send_get_connected_applications(&mut stream, &connection_id).await?; |
| 290 | for app_id in applications.keys() { |
| 291 | send_forward_get_listing(&mut stream, &connection_id, app_id).await?; |
| 292 | } |
| 293 | next_listing_refresh = Instant::now() + WEBKIT_DISCOVERY_REFRESH_INTERVAL; |
| 294 | } |
| 295 | continue; |
| 296 | } |
| 297 | }; |
| 298 | |
| 299 | let message = match parse_rpc_message(&packet) { |
| 300 | Ok(message) => message, |
| 301 | Err(error) => { |
| 302 | debug!("Ignoring malformed WebKit discovery packet: {error}"); |
| 303 | continue; |
| 304 | } |
| 305 | }; |
| 306 | debug!( |
| 307 | selector = %message.selector, |
| 308 | "Received WebKit discovery selector" |
| 309 | ); |
| 310 | |
| 311 | match message.selector.as_str() { |
| 312 | "_rpc_reportConnectedApplicationList:" => { |
| 313 | let live_apps = parse_application_list(&message.args); |
no test coverage detected