ObjFW
Loading...
Searching...
No Matches
OFSequencedPacketSocket.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
21OF_ASSUME_NONNULL_BEGIN
22
25@class OFData;
27
28#ifdef OF_HAVE_BLOCKS
37typedef bool (^OFSequencedPacketSocketAsyncReceiveBlock)(size_t length,
38 id _Nullable exception);
39
48 id _Nullable exception);
49
60 OFSequencedPacketSocket *acceptedSocket, id _Nullable exception);
61#endif
62
69@protocol OFSequencedPacketSocketDelegate <OFObject>
70@optional
81- (bool)socket: (OFSequencedPacketSocket *)socket
82 didReceiveIntoBuffer: (void *)buffer
83 length: (size_t)length
84 exception: (nullable id)exception;
85
94- (nullable OFData *)socket: (OFSequencedPacketSocket *)socket
95 didSendData: (OFData *)data
96 exception: (nullable id)exception;
97
107- (bool)socket: (OFSequencedPacketSocket *)socket
108 didAcceptSocket: (OFSequencedPacketSocket *)acceptedSocket
109 exception: (nullable id)exception;
110@end
111
127{
128 OFSocketHandle _socket;
129#ifdef OF_AMIGAOS
130 LONG _socketID; /* unused, reserved for ABI stability */
131 int _family; /* unused, reserved for ABI stability */
132#endif
133 bool _canBlock, _listening;
134 OFSocketAddress _remoteAddress;
135 id _Nullable _delegate;
136 OF_RESERVE_IVARS(OFSequencedPacketSocket, 4)
137}
138
147@property (nonatomic) bool canBlock;
152@property (readonly, nonatomic, getter=isListening) bool listening;
162@property (readonly, nonatomic) const OFSocketAddress *remoteAddress;
170@property OF_NULLABLE_PROPERTY (assign, nonatomic)
171 id <OFSequencedPacketSocketDelegate> delegate;
178+ (instancetype)socket;
179
191- (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length;
192
202- (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length;
203
215- (void)asyncReceiveIntoBuffer: (void *)buffer
216 length: (size_t)length
217 runLoopMode: (OFRunLoopMode)runLoopMode;
218
219#ifdef OF_HAVE_BLOCKS
234- (void)asyncReceiveIntoBuffer: (void *)buffer
235 length: (size_t)length
237
254- (void)asyncReceiveIntoBuffer: (void *)buffer
255 length: (size_t)length
256 runLoopMode: (OFRunLoopMode)runLoopMode
258#endif
259
268- (void)sendBuffer: (const void *)buffer length: (size_t)length;
269
275- (void)asyncSendData: (OFData *)data;
276
284- (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode;
285
286#ifdef OF_HAVE_BLOCKS
295- (void)asyncSendData: (OFData *)data
297
308- (void)asyncSendData: (OFData *)data
309 runLoopMode: (OFRunLoopMode)runLoopMode
311#endif
312
320- (void)listenWithBacklog: (int)backlog;
321
328- (void)listen;
329
337- (instancetype)accept;
338
342- (void)asyncAccept;
343
350- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode;
351
352#ifdef OF_HAVE_BLOCKS
360- (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block;
361
371- (void)
372 asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
374#endif
375
379- (void)cancelAsyncRequests;
380
391- (void)releaseSocketFromCurrentThread;
392
403- (void)obtainSocketForCurrentThread;
404
411- (void)close;
412@end
413
414OF_ASSUME_NONNULL_END
bool(^ OFSequencedPacketSocketAsyncReceiveBlock)(size_t length, id exception)
A block which is called when a packet has been received.
Definition OFSequencedPacketSocket.h:37
OFData *(^ OFSequencedPacketSocketAsyncSendDataBlock)(id exception)
A block which is called when a packet has been sent.
Definition OFSequencedPacketSocket.h:47
bool(^ OFSequencedPacketSocketAsyncAcceptBlock)(OFSequencedPacketSocket *acceptedSocket, id exception)
A block which is called when the socket accepted a connection.
Definition OFSequencedPacketSocket.h:59
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
The root class for all other classes inside ObjFW.
Definition OFObject.h:688
A base class for sequenced packet sockets.
Definition OFSequencedPacketSocket.h:128
A protocol for the creation of copies.
Definition OFObject.h:1346
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