ObjFW
OFDatagramSocket.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #import "OFKernelEventObserver.h"
18 #import "OFRunLoop.h"
19 
20 #import "socket.h"
21 
22 OF_ASSUME_NONNULL_BEGIN
23 
26 @class OFData;
27 @class OFDatagramSocket;
28 
29 #ifdef OF_HAVE_BLOCKS
40  size_t length, const of_socket_address_t *_Nonnull sender,
41  id _Nullable exception);
42 
53  OFData *_Nonnull data, const of_socket_address_t *_Nonnull receiver,
54  id _Nullable exception);
55 #endif
56 
64 @optional
76 - (bool)socket: (OFDatagramSocket *)socket
77  didReceiveIntoBuffer: (void *)buffer
78  length: (size_t)length
79  sender: (const of_socket_address_t *_Nonnull)sender
80  exception: (nullable id)exception;
81 
91 - (nullable OFData *)socket: (OFDatagramSocket *)socket
92  didSendData: (OFData *)data
93  receiver: (const of_socket_address_t *_Nonnull)receiver
94  exception: (nullable id)exception;
95 @end
96 
111 {
112  of_socket_t _socket;
113  bool _canBlock;
114 #ifdef OF_WII
115  bool _canSendToBroadcastAddresses;
116 #endif
117  id <OFDatagramSocketDelegate> _Nullable _delegate;
118  OF_RESERVE_IVARS(OFDatagramSocket, 4)
119 }
120 
126 @property (nonatomic) bool canBlock;
127 
131 @property (nonatomic) bool canSendToBroadcastAddresses;
132 
139 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
141 
147 + (instancetype)socket;
148 
160 - (size_t)receiveIntoBuffer: (void *)buffer
161  length: (size_t)length
162  sender: (of_socket_address_t *)sender;
163 
173 - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length;
174 
185 - (void)asyncReceiveIntoBuffer: (void *)buffer
186  length: (size_t)length
187  runLoopMode: (of_run_loop_mode_t)runLoopMode;
188 
189 #ifdef OF_HAVE_BLOCKS
205 - (void)asyncReceiveIntoBuffer: (void *)buffer
206  length: (size_t)length
208 
225 - (void)asyncReceiveIntoBuffer: (void *)buffer
226  length: (size_t)length
227  runLoopMode: (of_run_loop_mode_t)runLoopMode
229 #endif
230 
239 - (void)sendBuffer: (const void *)buffer
240  length: (size_t)length
241  receiver: (const of_socket_address_t *)receiver;
242 
250 - (void)asyncSendData: (OFData *)data
251  receiver: (const of_socket_address_t *)receiver;
252 
261 - (void)asyncSendData: (OFData *)data
262  receiver: (const of_socket_address_t *)receiver
263  runLoopMode: (of_run_loop_mode_t)runLoopMode;
264 
265 #ifdef OF_HAVE_BLOCKS
276 - (void)asyncSendData: (OFData *)data
277  receiver: (const of_socket_address_t *)receiver
279 
291 - (void)asyncSendData: (OFData *)data
292  receiver: (const of_socket_address_t *)receiver
293  runLoopMode: (of_run_loop_mode_t)runLoopMode
295 #endif
296 
300 - (void)cancelAsyncRequests;
301 
306 - (void)close;
307 @end
308 
309 OF_ASSUME_NONNULL_END
OFData *_Nullable(^ of_datagram_socket_async_send_data_block_t)(OFData *_Nonnull data, const of_socket_address_t *_Nonnull receiver, id _Nullable exception)
A block which is called when a packet has been sent.
Definition: OFDatagramSocket.h:52
bool(^ of_datagram_socket_async_receive_block_t)(size_t length, const of_socket_address_t *_Nonnull sender, id _Nullable exception)
A block which is called when a packet has been received.
Definition: OFDatagramSocket.h:39
struct objc_object * id
A pointer to any object.
Definition: ObjFWRT.h:90
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
A class for storing arbitrary data in an array.
Definition: OFData.h:40
A base class for datagram sockets.
Definition: OFDatagramSocket.h:112
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A protocol for the creation of copies.
Definition: OFObject.h:1187
A delegate for OFDatagramSocket.
Definition: OFDatagramSocket.h:63
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition: OFKernelEventObserver.h:85
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition: OFKernelEventObserver.h:100
A struct which represents a host / port pair for a socket.
Definition: socket.h:136