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 program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFObject.h"
21#import "OFKernelEventObserver.h"
22#import "OFRunLoop.h"
23#import "OFSocket.h"
24
25OF_ASSUME_NONNULL_BEGIN
26
29@class OFData;
31
32#ifdef OF_HAVE_BLOCKS
41typedef bool (^OFSequencedPacketSocketAsyncReceiveBlock)(size_t length,
42 id _Nullable exception);
43
52 id _Nullable exception);
53
64 OFSequencedPacketSocket *acceptedSocket, id _Nullable exception);
65#endif
66
73@protocol OFSequencedPacketSocketDelegate <OFObject>
74@optional
85- (bool)socket: (OFSequencedPacketSocket *)socket
86 didReceiveIntoBuffer: (void *)buffer
87 length: (size_t)length
88 exception: (nullable id)exception;
89
98- (nullable OFData *)socket: (OFSequencedPacketSocket *)socket
99 didSendData: (OFData *)data
100 exception: (nullable id)exception;
101
111- (bool)socket: (OFSequencedPacketSocket *)socket
112 didAcceptSocket: (OFSequencedPacketSocket *)acceptedSocket
113 exception: (nullable id)exception;
114@end
115
131{
132 OFSocketHandle _socket;
133#ifdef OF_AMIGAOS
134 LONG _socketID; /* unused, reserved for ABI stability */
135 int _family; /* unused, reserved for ABI stability */
136#endif
137 bool _canBlock, _listening;
138 OFSocketAddress _remoteAddress;
139 id _Nullable _delegate;
140 OF_RESERVE_IVARS(OFSequencedPacketSocket, 4)
141}
142
151@property (nonatomic) bool canBlock;
156@property (readonly, nonatomic, getter=isListening) bool listening;
166@property (readonly, nonatomic) const OFSocketAddress *remoteAddress;
174@property OF_NULLABLE_PROPERTY (assign, nonatomic)
175 id <OFSequencedPacketSocketDelegate> delegate;
182+ (instancetype)socket;
183
195- (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length;
196
206- (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length;
207
219- (void)asyncReceiveIntoBuffer: (void *)buffer
220 length: (size_t)length
221 runLoopMode: (OFRunLoopMode)runLoopMode;
222
223#ifdef OF_HAVE_BLOCKS
238- (void)asyncReceiveIntoBuffer: (void *)buffer
239 length: (size_t)length
241
258- (void)asyncReceiveIntoBuffer: (void *)buffer
259 length: (size_t)length
260 runLoopMode: (OFRunLoopMode)runLoopMode
262#endif
263
272- (void)sendBuffer: (const void *)buffer length: (size_t)length;
273
279- (void)asyncSendData: (OFData *)data;
280
288- (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode;
289
290#ifdef OF_HAVE_BLOCKS
299- (void)asyncSendData: (OFData *)data
301
312- (void)asyncSendData: (OFData *)data
313 runLoopMode: (OFRunLoopMode)runLoopMode
315#endif
316
324- (void)listenWithBacklog: (int)backlog;
325
332- (void)listen;
333
341- (instancetype)accept;
342
346- (void)asyncAccept;
347
354- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode;
355
356#ifdef OF_HAVE_BLOCKS
364- (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block;
365
375- (void)
376 asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
378#endif
379
383- (void)cancelAsyncRequests;
384
395- (void)releaseSocketFromCurrentThread;
396
407- (void)obtainSocketForCurrentThread;
408
415- (void)close;
416@end
417
418OF_ASSUME_NONNULL_END
bool(^ OFSequencedPacketSocketAsyncReceiveBlock)(size_t length, id exception)
A block which is called when a packet has been received.
Definition OFSequencedPacketSocket.h:41
OFData *(^ OFSequencedPacketSocketAsyncSendDataBlock)(id exception)
A block which is called when a packet has been sent.
Definition OFSequencedPacketSocket.h:51
bool(^ OFSequencedPacketSocketAsyncAcceptBlock)(OFSequencedPacketSocket *acceptedSocket, id exception)
A block which is called when the socket accepted a connection.
Definition OFSequencedPacketSocket.h:63
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:46
The root class for all other classes inside ObjFW.
Definition OFObject.h:692
A base class for sequenced packet sockets.
Definition OFSequencedPacketSocket.h:132
A protocol for the creation of copies.
Definition OFObject.h:1350
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition OFKernelEventObserver.h:88
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition OFKernelEventObserver.h:103
A struct which represents a host / port pair for a socket.
Definition OFSocket.h:186