ObjFW
Loading...
Searching...
No Matches
OFSequencedPacketSocket.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
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
214- (void)asyncReceiveIntoBuffer: (void *)buffer
215 length: (size_t)length
216 runLoopMode: (OFRunLoopMode)runLoopMode;
217
218#ifdef OF_HAVE_BLOCKS
233- (void)asyncReceiveIntoBuffer: (void *)buffer
234 length: (size_t)length
236
252- (void)asyncReceiveIntoBuffer: (void *)buffer
253 length: (size_t)length
254 runLoopMode: (OFRunLoopMode)runLoopMode
256#endif
257
266- (void)sendBuffer: (const void *)buffer length: (size_t)length;
267
273- (void)asyncSendData: (OFData *)data;
274
281- (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode;
282
283#ifdef OF_HAVE_BLOCKS
292- (void)asyncSendData: (OFData *)data
294
304- (void)asyncSendData: (OFData *)data
305 runLoopMode: (OFRunLoopMode)runLoopMode
307#endif
308
316- (void)listenWithBacklog: (int)backlog;
317
324- (void)listen;
325
333- (instancetype)accept;
334
338- (void)asyncAccept;
339
345- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode;
346
347#ifdef OF_HAVE_BLOCKS
355- (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block;
356
365- (void)
366 asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
368#endif
369
373- (void)cancelAsyncRequests;
374
385- (void)releaseSocketFromCurrentThread;
386
397- (void)obtainSocketForCurrentThread;
398
405- (void)close;
406@end
407
408OF_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