ObjFW
OFDatagramSocket.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2023 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 #import "OFSocket.h"
20 
21 OF_ASSUME_NONNULL_BEGIN
22 
25 @class OFData;
26 @class OFDatagramSocket;
27 
28 #ifdef OF_HAVE_BLOCKS
38 typedef bool (^OFDatagramSocketAsyncReceiveBlock)(size_t length,
39  const OFSocketAddress *_Nonnull sender, id _Nullable exception);
40 
49  id _Nullable exception);
50 #endif
51 
59 @optional
71 - (bool)socket: (OFDatagramSocket *)socket
72  didReceiveIntoBuffer: (void *)buffer
73  length: (size_t)length
74  sender: (const OFSocketAddress *_Nonnull)sender
75  exception: (nullable id)exception;
76 
86 - (nullable OFData *)socket: (OFDatagramSocket *)socket
87  didSendData: (OFData *)data
88  receiver: (const OFSocketAddress *_Nonnull)receiver
89  exception: (nullable id)exception;
90 @end
91 
106 {
107  OFSocketHandle _socket;
108 #ifdef OF_AMIGAOS
109  LONG _socketID;
110  int _family; /* unused, reserved for ABI stability */
111 #endif
112  bool _canBlock;
113 #ifdef OF_WII
114  bool _canSendToBroadcastAddresses;
115 #endif
116  id <OFDatagramSocketDelegate> _Nullable _delegate;
117  OF_RESERVE_IVARS(OFDatagramSocket, 4)
118 }
119 
128 @property (nonatomic) bool canBlock;
129 
136 @property (nonatomic) bool canSendToBroadcastAddresses;
137 
144 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
145  id <OFDatagramSocketDelegate> delegate;
146 
152 + (instancetype)socket;
153 
167 - (size_t)receiveIntoBuffer: (void *)buffer
168  length: (size_t)length
169  sender: (nullable OFSocketAddress *)sender;
170 
180 - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length;
181 
192 - (void)asyncReceiveIntoBuffer: (void *)buffer
193  length: (size_t)length
194  runLoopMode: (OFRunLoopMode)runLoopMode;
195 
196 #ifdef OF_HAVE_BLOCKS
212 - (void)asyncReceiveIntoBuffer: (void *)buffer
213  length: (size_t)length
214  block: (OFDatagramSocketAsyncReceiveBlock)block;
215 
232 - (void)asyncReceiveIntoBuffer: (void *)buffer
233  length: (size_t)length
234  runLoopMode: (OFRunLoopMode)runLoopMode
235  block: (OFDatagramSocketAsyncReceiveBlock)block;
236 #endif
237 
248 - (void)sendBuffer: (const void *)buffer
249  length: (size_t)length
250  receiver: (const OFSocketAddress *)receiver;
251 
259 - (void)asyncSendData: (OFData *)data
260  receiver: (const OFSocketAddress *)receiver;
261 
270 - (void)asyncSendData: (OFData *)data
271  receiver: (const OFSocketAddress *)receiver
272  runLoopMode: (OFRunLoopMode)runLoopMode;
273 
274 #ifdef OF_HAVE_BLOCKS
285 - (void)asyncSendData: (OFData *)data
286  receiver: (const OFSocketAddress *)receiver
288 
300 - (void)asyncSendData: (OFData *)data
301  receiver: (const OFSocketAddress *)receiver
302  runLoopMode: (OFRunLoopMode)runLoopMode
304 #endif
305 
316 - (void)releaseSocketFromCurrentThread;
317 
328 - (void)obtainSocketForCurrentThread;
329 
333 - (void)cancelAsyncRequests;
334 
341 - (void)close;
342 @end
343 
344 OF_ASSUME_NONNULL_END
bool(^ OFDatagramSocketAsyncReceiveBlock)(size_t length, const OFSocketAddress *sender, id exception)
A block which is called when a packet has been received.
Definition: OFDatagramSocket.h:38
OFData *(^ OFDatagramSocketAsyncSendDataBlock)(id exception)
A block which is called when a packet has been sent.
Definition: OFDatagramSocket.h:48
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:38
A class for storing arbitrary data in an array.
Definition: OFData.h:42
A base class for datagram sockets.
Definition: OFDatagramSocket.h:107
The root class for all other classes inside ObjFW.
Definition: OFObject.h:688
A protocol for the creation of copies.
Definition: OFObject.h:1346
A delegate for OFDatagramSocket.
Definition: OFDatagramSocket.h:58
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition: OFKernelEventObserver.h:84
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition: OFKernelEventObserver.h:99
A struct which represents a host / port pair for a socket.
Definition: OFSocket.h:182