ObjFW
OFDatagramSocket.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2024 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 
193 - (void)asyncReceiveIntoBuffer: (void *)buffer
194  length: (size_t)length
195  runLoopMode: (OFRunLoopMode)runLoopMode;
196 
197 #ifdef OF_HAVE_BLOCKS
213 - (void)asyncReceiveIntoBuffer: (void *)buffer
214  length: (size_t)length
215  block: (OFDatagramSocketAsyncReceiveBlock)block;
216 
234 - (void)asyncReceiveIntoBuffer: (void *)buffer
235  length: (size_t)length
236  runLoopMode: (OFRunLoopMode)runLoopMode
237  block: (OFDatagramSocketAsyncReceiveBlock)block;
238 #endif
239 
250 - (void)sendBuffer: (const void *)buffer
251  length: (size_t)length
252  receiver: (const OFSocketAddress *)receiver;
253 
261 - (void)asyncSendData: (OFData *)data
262  receiver: (const OFSocketAddress *)receiver;
263 
273 - (void)asyncSendData: (OFData *)data
274  receiver: (const OFSocketAddress *)receiver
275  runLoopMode: (OFRunLoopMode)runLoopMode;
276 
277 #ifdef OF_HAVE_BLOCKS
288 - (void)asyncSendData: (OFData *)data
289  receiver: (const OFSocketAddress *)receiver
291 
304 - (void)asyncSendData: (OFData *)data
305  receiver: (const OFSocketAddress *)receiver
306  runLoopMode: (OFRunLoopMode)runLoopMode
308 #endif
309 
320 - (void)releaseSocketFromCurrentThread;
321 
332 - (void)obtainSocketForCurrentThread;
333 
337 - (void)cancelAsyncRequests;
338 
345 - (void)close;
346 @end
347 
348 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