pub struct NWUDPSession { /* private fields */ }nw_connection_t in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>Expand description
Open UDP datagram sessions to an endpoint, and send and receive datagrams.
See also Apple’s documentation
Implementations§
Source§impl NWUDPSession
impl NWUDPSession
Sourcepub unsafe fn initWithUpgradeForSession(
this: Allocated<Self>,
session: &NWUDPSession,
) -> Retained<Self>
👎Deprecated: Use nw_connection_create in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>
pub unsafe fn initWithUpgradeForSession( this: Allocated<Self>, session: &NWUDPSession, ) -> Retained<Self>
nw_connection_create in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>This convenience initializer can be used to create a new session based on the original session’s endpoint and parameters.
The application should create an NWUDPSession and watch the “hasBetterPath” property. When this property is YES, it should call initWithUpgradeForSession: to create a new session, with the goal to start transferring data on the new better path as soon as possible to reduce power and potentially monetary cost. When the new “upgrade” session becomes ready and when the application wraps up the previous application session on the original session, the application can start using the new “upgrade” session and tear down the original one.
Parameter session: The original session from which the application will upgrade
Returns: An initialized NWUDPSession object.
Sourcepub unsafe fn state(&self) -> NWUDPSessionState
👎Deprecated: Use nw_connection_set_state_changed_handler in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>
pub unsafe fn state(&self) -> NWUDPSessionState
nw_connection_set_state_changed_handler in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>The current state of the UDP session. If the state is NWUDPSessionStateReady, then the connection is eligible for reading and writing. The state will be NWUDPSessionStateFailed if the endpoint could not be resolved, or all endpoints have been rejected. Use KVO to watch for changes.
Sourcepub unsafe fn endpoint(&self) -> Retained<NWEndpoint>
👎Deprecated: Use nw_connection_copy_endpoint in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>
pub unsafe fn endpoint(&self) -> Retained<NWEndpoint>
nw_connection_copy_endpoint in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>The provided endpoint.
Sourcepub unsafe fn resolvedEndpoint(&self) -> Option<Retained<NWEndpoint>>
👎Deprecated: Use nw_connection_copy_current_path in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>
pub unsafe fn resolvedEndpoint(&self) -> Option<Retained<NWEndpoint>>
nw_connection_copy_current_path in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>The currently targeted remote endpoint. Use KVO to watch for changes.
Sourcepub unsafe fn isViable(&self) -> bool
👎Deprecated: Use nw_connection_set_viability_changed_handler in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>
pub unsafe fn isViable(&self) -> bool
nw_connection_set_viability_changed_handler in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>YES if the connection can read and write data, NO otherwise. Use KVO to watch this property.
Sourcepub unsafe fn hasBetterPath(&self) -> bool
👎Deprecated: Use nw_connection_set_better_path_available_handler in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>
pub unsafe fn hasBetterPath(&self) -> bool
nw_connection_set_better_path_available_handler in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>YES if there is another path available that is preferred over the currentPath. To take advantage of this path, create a new UDPSession. Use KVO to watch for changes.
Sourcepub unsafe fn currentPath(&self) -> Option<Retained<NWPath>>
👎Deprecated: Use nw_connection_copy_current_path in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>
pub unsafe fn currentPath(&self) -> Option<Retained<NWPath>>
nw_connection_copy_current_path in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>The current evaluated path for the resolvedEndpoint. Use KVO to watch for changes.
Sourcepub unsafe fn tryNextResolvedEndpoint(&self)
👎Deprecated: Use nw_connection_cancel_current_endpoint in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>
pub unsafe fn tryNextResolvedEndpoint(&self)
nw_connection_cancel_current_endpoint in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>Mark the current value of resolvedEndpoint as unusable, and try to switch to the next available endpoint. This should be used when the caller has attempted to communicate with the current resolvedEndpoint, and the caller has determined that it is unusable. If there are no other resolved endpoints, the session will move to the failed state.
Sourcepub unsafe fn maximumDatagramLength(&self) -> NSUInteger
👎Deprecated: Use nw_connection_get_maximum_datagram_size in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>
pub unsafe fn maximumDatagramLength(&self) -> NSUInteger
nw_connection_get_maximum_datagram_size in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>The maximum size of a datagram to be written currently. If a datagram is written with a longer length, the datagram may be fragmented or encounter an error. Note that this value is not guaranteed to be the maximum datagram length for end-to-end communication across the network. Use KVO to watch for changes.
Sourcepub unsafe fn setReadHandler_maxDatagrams(
&self,
handler: &DynBlock<dyn Fn(*mut NSArray<NSData>, *mut NSError)>,
max_datagrams: NSUInteger,
)
👎Deprecated: Use nw_connection_receive in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>Available on crate feature block2 only.
pub unsafe fn setReadHandler_maxDatagrams( &self, handler: &DynBlock<dyn Fn(*mut NSArray<NSData>, *mut NSError)>, max_datagrams: NSUInteger, )
nw_connection_receive in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>block2 only.Set a read handler for datagrams. Reads will be scheduled by the system, so this method only needs to be called once for a session.
Parameter handler: A handler called when datagrams have been read, or when an error has occurred.
Parameter maxDatagrams: The maximum number of datagrams to send to the handler.
Sourcepub unsafe fn writeMultipleDatagrams_completionHandler(
&self,
datagram_array: &NSArray<NSData>,
completion_handler: &DynBlock<dyn Fn(*mut NSError)>,
)
👎Deprecated: Use nw_connection_send in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>Available on crate feature block2 only.
pub unsafe fn writeMultipleDatagrams_completionHandler( &self, datagram_array: &NSArray<NSData>, completion_handler: &DynBlock<dyn Fn(*mut NSError)>, )
nw_connection_send in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>block2 only.Write multiple datagrams. Callers should wait until the completionHandler is executed before issuing another write.
Parameter datagramArray: An NSArray of NSData objects, containing the ordered list datagrams to write.
Parameter completionHandler: A handler called when the write request has either succeeded or failed.
Sourcepub unsafe fn writeDatagram_completionHandler(
&self,
datagram: &NSData,
completion_handler: &DynBlock<dyn Fn(*mut NSError)>,
)
👎Deprecated: Use nw_connection_send in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>Available on crate feature block2 only.
pub unsafe fn writeDatagram_completionHandler( &self, datagram: &NSData, completion_handler: &DynBlock<dyn Fn(*mut NSError)>, )
nw_connection_send in Network framework instead, see deprecation notice in <NetworkExtension/NWUDPSession.h>block2 only.Write a single datagram. Callers should wait until the completionHandler is executed before issuing another write.
Parameter datagram: An NSData containing the datagram to write.
Parameter completionHandler: A handler called when the write request has either succeeded or failed.
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load instead.Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AnyObject> for NWUDPSession
impl AsRef<AnyObject> for NWUDPSession
Source§impl AsRef<NSObject> for NWUDPSession
impl AsRef<NSObject> for NWUDPSession
Source§impl AsRef<NWUDPSession> for NWUDPSession
impl AsRef<NWUDPSession> for NWUDPSession
Source§impl Borrow<AnyObject> for NWUDPSession
impl Borrow<AnyObject> for NWUDPSession
Source§impl Borrow<NSObject> for NWUDPSession
impl Borrow<NSObject> for NWUDPSession
Source§impl ClassType for NWUDPSession
impl ClassType for NWUDPSession
Source§const NAME: &'static str = "NWUDPSession"
const NAME: &'static str = "NWUDPSession"
Source§type ThreadKind = <<NWUDPSession as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NWUDPSession as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for NWUDPSession
impl Debug for NWUDPSession
Source§impl Deref for NWUDPSession
impl Deref for NWUDPSession
Source§impl Hash for NWUDPSession
impl Hash for NWUDPSession
Source§impl Message for NWUDPSession
impl Message for NWUDPSession
Source§impl NSObjectProtocol for NWUDPSession
impl NSObjectProtocol for NWUDPSession
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_ref