-
Notifications
You must be signed in to change notification settings - Fork 0
/
Network.framework.h
8780 lines (8012 loc) · 271 KB
/
Network.framework.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ========== Network.framework/Headers/connection.h
//
// connection.h
// Network
//
// Copyright (c) 2015-2019 Apple Inc. All rights reserved.
//
#ifndef __NW_CONNECTION_H__
#define __NW_CONNECTION_H__
#ifndef __NW_INDIRECT__
#warning "Please include <Network/Network.h> instead of this file directly."
#endif // __NW_INDIRECT__
#include <Network/endpoint.h>
#include <Network/parameters.h>
#include <Network/path.h>
#include <Network/content_context.h>
#include <Network/error.h>
__BEGIN_DECLS
NW_ASSUME_NONNULL_BEGIN
/*!
* @typedef nw_connection_t
* @abstract
* A Network Connection is an object that represents a bi-directional data pipe between
* a local endpoint and a remote endpoint. A connection handles establishment of any
* transport, security, or application-level protocols required to transmit and receive
* user data. Multiple protocol instances may be attempted during the establishment phase
* of the connection. Multiple connections may be multiplexed over a single transport
* if they make use of a protocol that supports multiplexing.
*
* This type supports ARC and the -[description] method. In non-ARC files, use
* nw_retain() and nw_release() to retain and release the object.
*/
#ifndef NW_CONNECTION_IMPL
NW_OBJECT_DECL(nw_connection);
#endif // NW_CONNECTION_IMPL
/*!
* @typedef nw_connection_state_t
* @abstract
* Connection states sent by nw_connection_set_state_changed_handler.
* States generally progress forward and do not move backwards, with the
* exception of preparing and waiting, which may alternate before the connection
* becomes ready or failed.
*/
typedef enum {
/*!
* @const nw_connection_state_invalid The state of the connection is not valid. This state
* will never be delivered in the connection's state update handler, and can be treated as
* an unexpected value.
*/
nw_connection_state_invalid = 0,
/*! @const nw_connection_state_waiting The connection is waiting for a usable network before re-attempting */
nw_connection_state_waiting = 1,
/*! @const nw_connection_state_preparing The connection is in the process of establishing */
nw_connection_state_preparing = 2,
/*! @const nw_connection_state_ready The connection is established and ready to send and receive data upon */
nw_connection_state_ready = 3,
/*! @const nw_connection_state_failed The connection has irrecoverably closed or failed */
nw_connection_state_failed = 4,
/*! @const nw_connection_state_cancelled The connection has been cancelled by the caller */
nw_connection_state_cancelled = 5,
} nw_connection_state_t;
/*!
* @function nw_connection_create
*
* @abstract
* Creates a networking connection to an endpoint.
*
* @param endpoint
* The remote endpoint to connect to.
*
* @param parameters
* The parameters to use for the connection. The data mode,
* either datagram or stream, must be set.
*
* @result
* Returns an allocated nw_connection_t object on success.
* Callers are responsible for deallocating using nw_release(obj) or [obj release].
* These objects support ARC.
* Returns NULL on failure. Fails due to invalid parameters.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_RETURNS_RETAINED nw_connection_t
nw_connection_create(nw_endpoint_t endpoint,
nw_parameters_t parameters);
/*!
* @function nw_connection_copy_endpoint
*
* @abstract
* Retrieves the remote endpoint for a connection.
*
* @param connection
* The connection object.
*
* @result
* Returns an nw_endpoint_t object on success.
* Returns NULL on failure. Fails due to invalid parameters.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_RETURNS_RETAINED nw_endpoint_t
nw_connection_copy_endpoint(nw_connection_t connection);
/*!
* @function nw_connection_copy_parameters
*
* @abstract
* Retrieves the parameters for a connection.
*
* @param connection
* The connection object.
*
* @result
* Returns an nw_parameters_t object on success.
* Returns NULL on failure. Fails due to invalid parameters.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_RETURNS_RETAINED nw_parameters_t
nw_connection_copy_parameters(nw_connection_t connection);
#ifdef __BLOCKS__
typedef void (^nw_connection_state_changed_handler_t)(nw_connection_state_t state,
_Nullable nw_error_t error);
/*!
* @function nw_connection_set_state_changed_handler
*
* @abstract
* Sets the state change handler. For clients that need to perform cleanup when the
* connection has been cancelled, the nw_connection_state_cancelled state will
* be delivered last.
*
* @param connection
* The connection object.
*
* @param handler
* The state changed handler to call when the connection state changes.
* Pass NULL to remove the state changed handler.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_set_state_changed_handler(nw_connection_t connection,
_Nullable nw_connection_state_changed_handler_t handler);
typedef void (^nw_connection_boolean_event_handler_t)(bool value);
/*!
* @function nw_connection_set_viability_changed_handler
*
* @abstract
* Define a callback to be fired when the viability of the connection changes.
* This indicates whether or not read and write calls will succeed on a ready
* connection.
*
* @param connection
* The connection object.
*
* @param handler
* The event handler to call when the connection viability changes. The value will
* be true when the connection is viable, and false otherwise.
* Pass NULL to remove the event handler.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_set_viability_changed_handler(nw_connection_t connection,
_Nullable nw_connection_boolean_event_handler_t handler);
/*!
* @function nw_connection_set_better_path_available_handler
*
* @abstract
* Define a callback to be fired when a better path is available or not.
* This indicates whether or not a preferred path is available for the
* connection.
*
* @param connection
* The connection object.
*
* @param handler
* The event handler to call when the better path availability changes. The value
* will be true when a better path is available, and false otherwise.
* Pass NULL to remove the event handler.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_set_better_path_available_handler(nw_connection_t connection,
_Nullable nw_connection_boolean_event_handler_t handler);
typedef void (^nw_connection_path_event_handler_t)(nw_path_t path);
/*!
* @function nw_connection_set_path_changed_handler
*
* @abstract
* Define a callback to be fired when the connection's path changes.
*
* @param connection
* The connection object.
*
* @param handler
* The event handler to call when the connection's path changes.
* Pass NULL to remove the event handler.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_set_path_changed_handler(nw_connection_t connection,
_Nullable nw_connection_path_event_handler_t handler);
#endif // __BLOCKS__
/*!
* @function nw_connection_set_queue
*
* @abstract
* Sets the client callback queue, on which blocks for events will
* be scheduled. This must be done before calling nw_connection_start().
*
* @param connection
* The connection object.
*
* @param queue
* The client's dispatch queue.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_set_queue(nw_connection_t connection,
dispatch_queue_t queue);
/*!
* @function nw_connection_start
*
* @abstract
* Starts the connection, which will cause the connection
* to evaluate its path, do resolution, and try to become
* readable and writable.
*
* @param connection
* The connection object.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_start(nw_connection_t connection);
/*!
* @function nw_connection_restart
*
* @abstract
* Connections in the waiting state will normally re-attempt
* on network changes. Call nw_connection_restart() to force
* a connection in the waiting state to retry connection
* establishment even without a network change. Calls to restart
* for connections that are not in the waiting state will be
* ignored.
*
* @param connection
* The connection object.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_restart(nw_connection_t connection);
/*!
* @function nw_connection_cancel
*
* @abstract
* Cancel the connection. This will close the connection, and negotiate over the network
* if applicable for the protocol. The process of cancellation will be completed
* asynchronously, and the final callback event delivered to the caller will be a state
* update with a value of nw_listener_state_cancelled. Once this update is delivered, the
* caller may clean up any associated memory or objects.
*
* Outstanding sends and receives will receive errors before the state changes to cancelled.
* There is no guarantee that any outstanding sends that have not yet delivered send completion handlers
* will send data before the connection is closed.
*
* @param connection
* The connection object.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_cancel(nw_connection_t connection);
/*!
* @function nw_connection_force_cancel
*
* @abstract
* A variant of nw_connection_cancel() that indicates that the protocol stack should
* not close gracefully, but close as quickly as possible without negotiation. For example,
* a force close would lead to TCP RST packets being sent, as opposed to negotiating with
* FIN packets.
*
* @param connection
* The connection object.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_force_cancel(nw_connection_t connection);
/*!
* @function nw_connection_cancel_current_endpoint
*
* @abstract
* Cancel the currently connected endpoint, causing the connection
* to fall through to the next endpoint if available, or fail if no
* more endpoints are available. This is primarily useful for connections
* which do not have reliable handshakes, such as UDP. If data is sent
* on the connection with no response, canceling the current endpoint
* will allow another address or interface to be attempted.
*
* @param connection
* The connection object.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_cancel_current_endpoint(nw_connection_t connection);
#ifdef __BLOCKS__
/*!
* @typedef nw_connection_receive_completion_t
* @abstract
* A receive completion is invoked exactly once for a call to nw_connection_receive().
* The completion indicates that the requested content has been received (in which case
* the content is delivered), or else an error has occurred.
*
* @param content
* The received content, which has a length constrained by the call to nw_connection_receive().
* The content may be NULL in two cases: (1) the receive context (logical message) is now complete,
* and the callback is only delivering the completed event; or, (2) the connection encountered
* an error and there is no data to deliver. Note that the content may be non-NULL even in the
* case of an error if there was some data received before the error was encountered. The caller
* should process all content it receives, and not necessarily ignore data in case of errors.
*
* @param context
* The context (logical message) associated with the received content. This includes protocol metadata
* that lets the caller introspect information about the received content (such as flags on an IP packet).
* When the message has been completely received, the context will be delivered along with the
* is_complete flag.
*
* For datagram protocols such as UDP, the context represents the properties of a single received
* datagram.
*
* For protocols that only have a single context for the entire connection, such as stream protocols
* like TCP, the context will be marked as "final", which can be accessed with
* nw_content_context_get_is_final(). Once a final context is marked as complete, the recipient
* may assume that the connection has been closed in the receiving direction (a "read close"). For
* TCP, this represents receiving a FIN.
*
* @param is_complete
* An indication that this context (logical message) is now complete. Until this flag is
* set, the recipient should assume that there may be more bytes to read for this context.
* Note that even when reading datagrams, as from UDP, the context may be read in multiple
* chunks if the maximum_length was smaller than the full length of the message.
*
* If is_complete is marked and the received context is the final context for connection,
* the caller may assume that the connection has been closed in the receiving direction.
*
* @param error
* An error will be sent if an error was encountered while trying to receive on the connection.
* There may still be content delivered along with the error, but this content may be shorter
* than the requested ranges. An error will be sent for any outstanding receive calls when the
* connection is cancelled.
*/
typedef void (^nw_connection_receive_completion_t)(_Nullable dispatch_data_t content,
_Nullable nw_content_context_t context,
bool is_complete,
_Nullable nw_error_t error);
/*!
* @function nw_connection_receive
*
* @abstract
* Receive data from a connection. This may be called before the connection
* is ready, in which case the receive request will be queued until the
* connection is ready. The completion handler will be invoked exactly
* once for each call, so the client must call this function multiple
* times to receive multiple chunks of data. For protocols that
* support flow control, such as TCP, calling receive opens the receive
* window. If the client stops calling receive, the receive window will
* fill up and the remote peer will stop sending.
*
* @param connection
* The connection object on which to receive data. The connection should
* be in the ready state.
*
* @param minimum_incomplete_length
* The minimum length to receive from the connection, until the content
* is complete. Content will be delivered when at least the minimum is available,
* or the content is complete, whichever comes first.
*
* @param maximum_length
* The maximum length to receive from the connection.
*
* @param completion
* A callback to be called when content has been received.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_receive(nw_connection_t connection,
uint32_t minimum_incomplete_length,
uint32_t maximum_length,
nw_connection_receive_completion_t completion);
/*!
* @function nw_connection_receive_message
*
* @abstract
* Receive a single atomic message from a connection. The completion
* handler will be invoked exactly once for each call, so the client
* must call this function multiple times to receive multiple messages.
*
* @param connection
* The connection object on which to receive the message. The connection
* should be in the ready state.
*
* @param completion
* A callback to be called when the message has been received, or an error
* has occurred.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_receive_message(nw_connection_t connection,
nw_connection_receive_completion_t completion);
/*!
* @typedef nw_connection_send_completion_t
* @abstract
* A send completion is invoked exactly once for a call to nw_connection_send().
* The completion indicates that the sent content has been processed by the stack
* (not necessarily that it has left the host), or else an error has occurred during
* sending.
*
* @param error
* An error will be sent if the associated content could not be fully sent before an
* error occurred. An error will be sent for any outstanding sends when the connection
* is cancelled.
*/
typedef void (^nw_connection_send_completion_t)(_Nullable nw_error_t error);
#define NW_CONNECTION_SEND_TYPE_DECL(name) \
extern const nw_connection_send_completion_t _nw_connection_send_##name
/*!
* @const NW_CONNECTION_SEND_IDEMPOTENT_CONTENT
* @discussion A send callback override that causes the write call to
* be treated as idempotent. Idempotent content is allowed to be sent
* before the connection is ready, and may be replayed across parallel connection
* attempts. This content can be sent as part of fast-open protocols, which allows
* the data to be sent out sooner than if it were required to wait for
* connection establishment.
*
* This override intentionally disallows the client from receiving callbacks
* for the write calls, since the content may be sent multiple times internally.
* For any large content, or content that need to be sensitive to sending backpressure,
* an explicit callback should be used.
*/
#define NW_CONNECTION_SEND_IDEMPOTENT_CONTENT (_nw_connection_send_idempotent_content)
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_CONNECTION_SEND_TYPE_DECL(idempotent_content);
#define NW_CONTENT_CONTEXT_TYPE_DECL(name) \
extern const nw_content_context_t _nw_content_context_##name
/*!
* @const NW_CONNECTION_DEFAULT_MESSAGE_CONTEXT
* @discussion Use the default message context to send content with all default properties:
* default priority, no expiration, and not the final message. Marking this context
* as complete with a send indicates that the message content is now complete and any
* other messages that were blocked may be scheduled, but will not close the underlying
* connection. Use this context for any lightweight sends of datagrams or messages on
* top of a stream that do not require special properties.
*
* This context does not support overriding any properties.
*/
#define NW_CONNECTION_DEFAULT_MESSAGE_CONTEXT (_nw_content_context_default_message)
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_CONTENT_CONTEXT_TYPE_DECL(default_message);
/*!
* @const NW_CONNECTION_FINAL_MESSAGE_CONTEXT
* @discussion Use the final message context to indicate that no more sends are expected
* once this context is complete. Like NW_CONNECTION_DEFAULT_MESSAGE_CONTEXT, all
* properties are default. Marking a send as complete when using this context will close
* the sending side of the underlying connection. This is the equivalent of sending a FIN
* on a TCP stream.
*
* This context does not support overriding any properties.
*/
#define NW_CONNECTION_FINAL_MESSAGE_CONTEXT (_nw_content_context_final_send)
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_CONTENT_CONTEXT_TYPE_DECL(final_send);
/*!
* @const NW_CONNECTION_DEFAULT_STREAM_CONTEXT
* @discussion Use the default stream context to indicate that this sending context is
* the one that represents the entire connection. All context properties are default.
* This context behaves in the same way as NW_CONNECTION_FINAL_MESSAGE_CONTEXT, such
* that marking the context complete by sending is_complete will close the sending
* side of the underlying connection (a FIN for a TCP stream).
*
* Note that this context is a convenience for sending a single, final context.
* If the protocol used by the connection is a stream (such as TCP), the caller
* may still use NW_CONNECTION_DEFAULT_MESSAGE_CONTEXT, NW_CONNECTION_FINAL_MESSAGE_CONTEXT,
* or a custom context with priorities and metadata to set properties of a particular
* chunk of stream data relative to other data on the stream.
*
* This context does not support overriding any properties.
*/
#define NW_CONNECTION_DEFAULT_STREAM_CONTEXT (_nw_content_context_default_stream)
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_CONTENT_CONTEXT_TYPE_DECL(default_stream);
/*!
* @function nw_connection_send
*
* @abstract
* Send data on a connection. This may be called before the connection is ready,
* in which case the send will be enqueued until the connection is ready to send.
* This is an asynchronous send and the completion block can be used to
* determine when the send is complete. There is nothing preventing a client
* from issuing an excessive number of outstanding sends. To minmize memory
* footprint and excessive latency as a consequence of buffer bloat, it is
* advisable to keep a low number of outstanding sends. The completion block
* can be used to pace subsequent sends.
*
* @param connection
* The connection object on which to send data.
*
* @param content
* A data object to send. This may be NULL only if this send is marking a context
* (a message or complete connection) as complete in the sending direction.
*
* @param context
* The context associated with the content, which represents a logical message
* to be sent on the connection. All content sent within a single context will
* be sent as an in-order unit, up until the point that the context is marked
* complete (see is_complete). Once a context is marked complete, it may be re-used
* as a new logical message. Protocols like TCP that cannot send multiple
* independent messages at once (serial streams) will only start processing a new
* context once the prior context has been marked complete.
*
* The context can hold protocol metadata to define how to send content, such
* as flags for IP packets.
*
* The context also can define properties that allow a message to ordered relative
* to other messages if multiple messages are queued. These properties include
* relative priority, expiration, and antecedent relationships. Some protocols
* support re-ordering messages within a single connection. For other protocols
* that do not, like TCP, these properties still take effect when enqueuing data
* into the stream's send buffer. The ordering of messages applies to the first
* calls to send on a given context.
*
* In order to close a connection on the sending side (a "write close"), send
* a context that is marked as "final" and mark is_complete. The convenience definition
* NW_CONNECTION_FINAL_MESSAGE_CONTEXT may be used to define the default final context
* for a connection. If the caller wants to treat the entire connection as a single
* stream, with only one context, set NW_CONNECTION_FINAL_MESSAGE_CONTEXT for all
* sends; marking is_complete on the final send call will send a "write close".
* Using NW_CONNECTION_DEFAULT_STREAM_CONTEXT has the same behavior as sending
* NW_CONNECTION_FINAL_MESSAGE_CONTEXT.
*
* To send basic datagrams on a connection, use NW_CONNECTION_DEFAULT_MESSAGE_CONTEXT
* and pass is_complete as true for each datagram.
*
* To send data as a single stream on a connection, use NW_CONNECTION_DEFAULT_STREAM_CONTEXT
* and pass is_complete as true only to mark the end of the stream.
*
* @param is_complete
* A flag indicating if the caller's sending context (logical message) is now complete.
*
* Until a context is marked complete, content sent for other contexts may not
* be sent immediately (if the protocol requires sending bytes serially, like TCP).
*
* For datagram protocols, like UDP, is_complete indicates that the content represents
* a complete datagram.
*
* When sending directly on streaming protocols like TCP, is_complete can be used to
* indicate that the connection should send a "write close" (a TCP FIN) if the sending
* context is the final context on the connection. Specifically, to send a "write close",
* pass NW_CONNECTION_FINAL_MESSAGE_CONTEXT or NW_CONNECTION_DEFAULT_STREAM_CONTEXT for the
* context (or create a custom context and set nw_content_context_set_is_final()), and pass
* true for is_complete.
*
* @param completion
* A callback to be called when the data has been sent, or an error has occurred.
* This callback does not indicate that the remote side has acknowledged the data.
* This callback does indicate that the data has either been sent or it has been
* enqueued to be sent.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_send(nw_connection_t connection,
_Nullable dispatch_data_t content,
nw_content_context_t context,
bool is_complete,
nw_connection_send_completion_t completion);
/*!
* @function nw_connection_batch
*
* @abstract
* Batch several send and/or receive operations together, to hint to
* the connection that multiple send or recieve operations are expected
* in quick succession.
*
* @param connection
* The connection object.
*
* @param batch_block
* The batch block will be invoked immediately upon calling this function.
* The client may call nw_connection_send() or nw_connection_receive()
* multiple times within the block, and the connection will attempt to
* batch these operations when the block returns.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_connection_batch(nw_connection_t connection,
NW_NOESCAPE dispatch_block_t batch_block);
#endif // __BLOCKS__
/*!
* @function nw_connection_copy_description
*
* @abstract
* Copy a human-readable description of the connection.
*
* @param connection
* The connection object.
*
* @result
* Returns a human-readable string description of the connection.
* The caller must call free() on the string.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
char *
nw_connection_copy_description(nw_connection_t connection);
/*!
* @function nw_connection_copy_current_path
*
* @abstract
* Copy the current path for a connection. If a connection is
* established, this will reflect the connected path.
*
* @param connection
* The connection object.
*
* @result
* Returns a retained path object, or NULL if the connection
* has not been started or has been cancelled.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_RETURNS_RETAINED _Nullable nw_path_t
nw_connection_copy_current_path(nw_connection_t connection);
/*!
* @function nw_connection_copy_protocol_metadata
*
* @abstract
* Copy the connection-wide metadata for a specific protocol.
* This allows the caller to introspect per-protocol state,
* only once the connection has been established. This
* metadata is also available when receiving data through
* the content context.
*
* @param connection
* The connection object.
*
* @param definition
* The protocol definition for which metadata will be returned.
*
* @result
* Returns a retained protocol metadata object, or NULL if the connection
* has not been established yet, or is cancelled.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_RETURNS_RETAINED _Nullable nw_protocol_metadata_t
nw_connection_copy_protocol_metadata(nw_connection_t connection,
nw_protocol_definition_t definition);
/*!
* @function nw_connection_get_maximum_datagram_size
*
* @abstract
* Check for the maximum datagram size that can be written
* on the connection. Any datagrams written should be less
* than or equal to this size.
*
* @param connection
* The connection object.
*
* @result
* Returns a datagram size based on the current MTU and the
* overhead of the protocols being used.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
uint32_t
nw_connection_get_maximum_datagram_size(nw_connection_t connection);
NW_ASSUME_NONNULL_END
__END_DECLS
#endif /* __NW_CONNECTION_H__ */
// ========== Network.framework/Headers/error.h
//
// error.h
// Network
//
// Copyright (c) 2016-2019 Apple Inc. All rights reserved.
//
#ifndef __NW_ERROR_H__
#define __NW_ERROR_H__
#ifndef __NW_INDIRECT__
#warning "Please include <Network/Network.h> instead of this file directly."
#endif // __NW_INDIRECT__
#include <Network/nw_object.h>
#include <dns_sd.h>
#include <CoreFoundation/CoreFoundation.h>
__BEGIN_DECLS
NW_ASSUME_NONNULL_BEGIN
/*!
* @typedef nw_error_t
* @abstract
* A network error object with a domain and error code.
*
* This type supports ARC and the -[description] method. In non-ARC files, use
* nw_retain() and nw_release() to retain and release the object.
*/
#ifndef NW_ERROR_IMPL
NW_OBJECT_DECL(nw_error);
#endif // NW_ERROR_IMPL
/*!
* @typedef nw_error_domain_t
* @abstract
* The enumeration of network error domains.
*/
typedef enum {
/*! @const nw_error_domain_invalid */
nw_error_domain_invalid = 0,
/*! @const nw_error_domain_posix The error code will be a POSIX error as defined in <sys/errno.h> */
nw_error_domain_posix = 1,
/*! @const nw_error_domain_dns The error code will be a DNSServiceErrorType error as defined in <dns_sd.h> */
nw_error_domain_dns = 2,
/*! @const nw_error_domain_tls The error code will be a TLS error as defined in <Security/SecureTransport.h> */
nw_error_domain_tls = 3
} nw_error_domain_t;
/*!
* @function nw_error_get_error_domain
*
* @abstract
* Given a reference to a nw_error, returns the error domain.
*
* @param error
* A reference to the nw_error.
*
* @returns
* The error domain.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
nw_error_domain_t
nw_error_get_error_domain(nw_error_t error);
/*!
* @function nw_error_get_error_code
*
* @abstract
* Given a reference to a nw_error, returns the error code.
*
* @param error
* A reference to the nw_error.
*
* @returns
* The error code.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
int
nw_error_get_error_code(nw_error_t error);
/*!
* @const kNWErrorDomainPOSIX
* @abstract CFErrorRef domain corresponding to nw_error_domain_posix.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
extern const CFStringRef kNWErrorDomainPOSIX; // Values will be POSIX errors
/*!
* @const kNWErrorDomainDNS
* @abstract CFErrorRef domain corresponding to nw_error_domain_posix.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
extern const CFStringRef kNWErrorDomainDNS; // Values will be DNSServiceErrorType errors
/*!
* @const kNWErrorDomainTLS
* @abstract CFErrorRef domain corresponding to nw_error_domain_tls.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
extern const CFStringRef kNWErrorDomainTLS; // Values will be errSSL* errors
/*!
* @function nw_error_copy_cf_error
*
* @abstract
* Given a reference to nw_error, returns a CFErrorRef representing the same error.
*
* @param error
* A reference to the nw_error.
*
* @returns
* The CFErrorRef. The caller is responsible for calling CFRelease on the returned value.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
CFErrorRef
nw_error_copy_cf_error(nw_error_t error);
NW_ASSUME_NONNULL_END
__END_DECLS
#endif /* __NW_ERROR_H__ */
// ========== Network.framework/Headers/advertise_descriptor.h
//
// advertise_descriptor.h
// Network
//
// Copyright (c) 2016-2019 Apple Inc. All rights reserved.
//
#ifndef __NW_ADVERTISE_DESCRIPTOR_H__
#define __NW_ADVERTISE_DESCRIPTOR_H__
#ifndef __NW_INDIRECT__
#warning "Please include <Network/Network.h> instead of this file directly."
#endif // __NW_INDIRECT__
#include <Network/nw_object.h>
#include <Network/txt_record.h>
#include <sys/types.h>
#include <stdbool.h>
#include <stdint.h>
NW_ASSUME_NONNULL_BEGIN
__BEGIN_DECLS
/*!
* @typedef nw_advertise_descriptor_t
* @abstract
* An Advertise Descriptor is an abstract classification of properties
* that may be used to advertise a service, such as a Bonjour service type.
*/
#ifndef NW_SERVICE_DESCRIPTOR_IMPL
NW_OBJECT_DECL(nw_advertise_descriptor);
#endif // NW_SERVICE_DESCRIPTOR_IMPL
/*!
* @function nw_advertise_descriptor_create_bonjour_service
*
* @abstract
* Creates a new advertise descriptor object based on a Bonjour service type
* and optional domain. This object can be used with listener objects to
* specify the service the listener should advertise.
*
* If the name is unspecified, the default name for the device will be used.
* If the domain is unspecified, the default domains for registration will be
* used. If the listener is local only, the domain 'local.' will be used
* regardless of the parameter passed to domain.
*
* @param name
* An optional Bonjour service name.
*
* @param type
* A Bonjour service type.
*
* @param domain
* An optional Bonjour service domain.
*
* @result
* An instantiated browse descriptor object.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
NW_RETURNS_RETAINED nw_advertise_descriptor_t _Nullable
nw_advertise_descriptor_create_bonjour_service(const char * _Nullable name, const char * type, const char * _Nullable domain);
/*!
* @function nw_advertise_descriptor_set_txt_record
*
* @abstract
* Set the TXT record for the advertise descriptor's service. You must call
* nw_listener_set_advertise_descriptor to update the listener's advertising
* afterwards in order for these changes to take effect.
*
* @param advertise_descriptor
* The advertise descriptor to modify.
*
* @param txt_record
* A pointer to the TXT record.
*
* @param txt_length
* The length of the TXT record. The total size of a typical DNS-SD TXT record
* is intended to be small - 200 bytes or less. Using TXT records larger than
* 1300 bytes is not recommended at this time.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_advertise_descriptor_set_txt_record(nw_advertise_descriptor_t advertise_descriptor,
const void * _Nullable txt_record,
size_t txt_length);
/*!
* @function nw_advertise_descriptor_set_no_auto_rename
*
* @abstract
* Disable auto-rename for the Bonjour service registration.
* Auto-rename is enabled by default.
*
* @param advertise_descriptor
* The advertise descriptor to modify.
*
* @param no_auto_rename
* A boolean indicating if auto-rename should be disabled.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
void
nw_advertise_descriptor_set_no_auto_rename(nw_advertise_descriptor_t advertise_descriptor,
bool no_auto_rename);
/*!
* @function nw_advertise_descriptor_get_no_auto_rename
*
* @abstract
* Check if auto-rename has been disabled for the Bonjour service
* registration.
*
* @param advertise_descriptor
* The advertise descriptor object.
*
* @result A boolean indicating if auto-rename is disabled.
*/
API_AVAILABLE(macos(10.14), ios(12.0), watchos(5.0), tvos(12.0))
bool
nw_advertise_descriptor_get_no_auto_rename(nw_advertise_descriptor_t advertise_descriptor);
/*!
* @function nw_advertise_descriptor_set_txt_record_object
*
* @abstract
* Set the TXT record object on the advertise descriptor.
*
* @param advertise_descriptor
* The advertise descriptor object.
*
* @param txt_record
* The TXT record object. If txt_record is NULL, the advertise_descriptor's
* current TXT record object will be removed.
*/
API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
void
nw_advertise_descriptor_set_txt_record_object(nw_advertise_descriptor_t advertise_descriptor,
_Nullable nw_txt_record_t txt_record);
/*!
* @function nw_advertise_descriptor_copy_txt_record_object
*
* @abstract
* Copies the TXT record object from the advertise descriptor.
*
* @param advertise_descriptor
* The advertise descriptor object.
*
* @result
* A copy of the TXT record object, or NULL if the advertise descriptor
* does not have an associated TXT record.
*/
API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0))
NW_RETURNS_RETAINED _Nullable nw_txt_record_t
nw_advertise_descriptor_copy_txt_record_object(nw_advertise_descriptor_t advertise_descriptor);
__END_DECLS
NW_ASSUME_NONNULL_END