MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / create_client

Method create_client

rust/src/websocket/provider.rs:43–62  ·  view source on GitHub ↗

Create a new instance of the websocket client.

(&self)

Source from the content-addressed store, hash-verified

41
42 /// Create a new instance of the websocket client.
43 fn create_client(&self) -> Result<Ref<CoreWebsocketClient>, ()> {
44 let client_uninit = MaybeUninit::uninit();
45 // SAFETY: Websocket client is freed by cb_destroy_client
46 let leaked_client = Box::leak(Box::new(client_uninit));
47 let mut callbacks = BNWebsocketClientCallbacks {
48 context: leaked_client as *mut _ as *mut c_void,
49 connect: Some(client::cb_connect::<Self::Client>),
50 destroyClient: Some(client::cb_destroy_client::<Self::Client>),
51 disconnect: Some(client::cb_disconnect::<Self::Client>),
52 write: Some(client::cb_write::<Self::Client>),
53 };
54 let client_ptr =
55 unsafe { BNInitWebsocketClient(self.handle().handle.as_ptr(), &mut callbacks) };
56 // TODO: If possible pass a sensible error back...
57 let client_ptr = NonNull::new(client_ptr).ok_or(())?;
58 let client_ref = unsafe { CoreWebsocketClient::ref_from_raw(client_ptr) };
59 // We now have the core client so we can actually construct the object.
60 leaked_client.write(Self::Client::from_core(client_ref.clone()));
61 Ok(client_ref)
62 }
63}
64
65#[derive(Clone, Copy, Hash, PartialEq, Eq)]

Callers 3

cb_create_clientFunction · 0.80
reg_websocket_providerFunction · 0.80

Implementers 1

websocket.rsrust/tests/websocket.rs

Calls 3

handleMethod · 0.45
writeMethod · 0.45
cloneMethod · 0.45

Tested by 2

reg_websocket_providerFunction · 0.64