- Notifications
You must be signed in to change notification settings - Fork548
[Network] Improve bindings for NWProtocolMetadata.#6389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
rolfbjarne merged 5 commits intodotnet:xcode11fromrolfbjarne:xcode11-network-protocol-metadataJun 21, 2019
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
d1a100f [Network] Improve bindings for NWProtocolMetadata.
rolfbjarne606f66f Fix casing in exception message.
rolfbjarneb68f485 [tests] Adjust the SecProtocolMetadataTest according to new knowledge…
rolfbjarneb45f2e0 Merge remote-tracking branch 'origin/xcode11' into xcode11-network-pr…
rolfbjarneb747872 Fix alternative property name in obsolete attribute.
rolfbjarneFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
[Network] Improve bindings for NWProtocolMetadata.
It turns out the NWProtocolMetadata can contain metadata for differentprotocols (Ip/Tls/Tcp). This is important; if someone tries to get a value forone protocol and the metadata is for another protocol, then they invoke thewrath of superior beings who will smite that poor someone with uninitializedmemory.At that point there's not much left but to pray.I don't like to depend on divine intervention, so I've modified the API hereto check if the metadata's protocol is the required type for the native APIwe're calling, and if the check fails, we throw a nice and dependable managedexception.This is a functional breaking change; but if there are any lost souls wholikes to pray, they can always re-implement the P/Invokes themselves and skipthe sanity checks.In addition I've renamed a few properties whose name didn't clearly specifywhich protocol type they operate on.Ref: Apple feedback FB6155967.Ref:https://trello.com/c/1TW0BSKJ/145-fb6155967-nwipcreatemetadata-returns-uninitialized-metadata-in-ios-13
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commitd1a100fefb298df4806f6ac84429156a969c01cb
There are no files selected for viewing
75 changes: 67 additions & 8 deletionssrc/Network/NWProtocolMetadata.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -87,7 +87,35 @@ public NWProtocolMetadata (IntPtr handle, bool owns) : base (handle, owns) {} | ||
| [DllImport (Constants.NetworkLibrary)] | ||
| static extern IntPtr nw_tls_copy_sec_protocol_metadata (IntPtr handle); | ||
| void CheckIsIP () | ||
| { | ||
| if (!IsIP) | ||
| throw new InvalidOperationException ("This metadata is not IP metadata."); | ||
| } | ||
| void CheckIsTcp () | ||
| { | ||
| if (!IsTcp) | ||
| throw new InvalidOperationException ("This metadata is not Tcp metadata."); | ||
| ||
| } | ||
| void CheckIsTls () | ||
| { | ||
| if (!IsTls) | ||
| throw new InvalidOperationException ("This metadata is not TLS metadata."); | ||
| } | ||
| #if !XAMCORE_4_0 | ||
| [Obsolete ("Use 'SecTlsProtocolMetadata' instead.")] | ||
| public SecProtocolMetadata SecProtocolMetadata => TlsSecProtocolMetadata; | ||
| #endif | ||
| public SecProtocolMetadata TlsSecProtocolMetadata { | ||
| get { | ||
| CheckIsTls (); | ||
| return new SecProtocolMetadata (nw_tls_copy_sec_protocol_metadata (GetCheckedHandle ()), owns: true); | ||
| } | ||
| } | ||
| [DllImport (Constants.NetworkLibrary)] | ||
| static extern void nw_ip_metadata_set_ecn_flag (OS_nw_protocol_metadata metadata, NWIPEcnFlag ecn_flag); | ||
| @@ -96,15 +124,24 @@ public NWProtocolMetadata (IntPtr handle, bool owns) : base (handle, owns) {} | ||
| static extern NWIPEcnFlag nw_ip_metadata_get_ecn_flag (OS_nw_protocol_metadata metadata); | ||
| public NWIPEcnFlag IPMetadataEcnFlag { | ||
| get { | ||
| CheckIsIP (); | ||
| return nw_ip_metadata_get_ecn_flag (GetCheckedHandle ()); | ||
| } | ||
| set { | ||
| CheckIsIP (); | ||
| nw_ip_metadata_set_ecn_flag (GetCheckedHandle (), value); | ||
| } | ||
| } | ||
| [DllImport (Constants.NetworkLibrary)] | ||
| static extern /* uint64_t */ ulong nw_ip_metadata_get_receive_time (OS_nw_protocol_metadata metadata); | ||
| public ulong IPMetadataReceiveTime { | ||
| get { | ||
| CheckIsIP (); | ||
| return nw_ip_metadata_get_receive_time (GetCheckedHandle ()); | ||
| } | ||
| } | ||
| [DllImport (Constants.NetworkLibrary)] | ||
| @@ -113,19 +150,41 @@ public ulong IPMetadataReceiveTime { | ||
| [DllImport (Constants.NetworkLibrary)] | ||
| static extern NWServiceClass nw_ip_metadata_get_service_class (OS_nw_protocol_metadata metadata); | ||
| #if !XAMCORE_4_0 | ||
| [Obsolete ("Use 'IPServiceClass' instead.")] | ||
| public NWServiceClass ServiceClass { | ||
| get => IPServiceClass; | ||
| set => IPServiceClass = value; | ||
| } | ||
| #endif | ||
| public NWServiceClass IPServiceClass { | ||
| get { | ||
| CheckIsIP (); | ||
| return nw_ip_metadata_get_service_class (GetCheckedHandle ()); | ||
| } | ||
| set { | ||
| CheckIsIP (); | ||
| nw_ip_metadata_set_service_class (GetCheckedHandle (), value); | ||
| } | ||
| } | ||
| [DllImport (Constants.NetworkLibrary)] | ||
| extern static /* uint32_t */ uint nw_tcp_get_available_receive_buffer (IntPtr handle); | ||
| public uint TcpGetAvailableReceiveBuffer () | ||
| { | ||
| CheckIsTcp (); | ||
| return nw_tcp_get_available_receive_buffer (GetCheckedHandle ()); | ||
| } | ||
| [DllImport (Constants.NetworkLibrary)] | ||
| extern static /* uint32_t */ uint nw_tcp_get_available_send_buffer (IntPtr handle); | ||
| public uint TcpGetAvailableSendBuffer () | ||
| { | ||
| CheckIsTcp (); | ||
| return nw_tcp_get_available_send_buffer (GetCheckedHandle ()); | ||
| } | ||
| } | ||
| } | ||
16 changes: 10 additions & 6 deletionstests/monotouch-test/Network/NWProtocolMetadataTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.