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
43typedef bool (^OFSequencedPacketSocketAsyncReceiveBlock)(size_t length,
44 id _Nullable exception)
45 OF_DEPRECATED(ObjFW, 1, 2,
46 "Use OFSequencedPacketSocketPacketReceivedHandler instead");
47
59 OFSequencedPacketSocket *socket, void *buffer, size_t length,
60 id _Nullable exception);
61
72 id _Nullable exception)
73 OF_DEPRECATED(ObjFW, 1, 2,
74 "Use OFSequencedPacketSocketDataSentHandler instead");
75
86 OFSequencedPacketSocket *socket, OFData *data, id _Nullable exception);
87
100 OFSequencedPacketSocket *acceptedSocket, id _Nullable exception)
101 OF_DEPRECATED(ObjFW, 1, 2,
102 "Use OFSequencedPacketSocketAcceptedHandler instead");
103
115 OFSequencedPacketSocket *socket, OFSequencedPacketSocket *acceptedSocket,
116 id _Nullable exception);
117#endif
118
125@protocol OFSequencedPacketSocketDelegate <OFObject>
126@optional
137- (bool)socket: (OFSequencedPacketSocket *)socket
138 didReceiveIntoBuffer: (void *)buffer
139 length: (size_t)length
140 exception: (nullable id)exception;
141
150- (nullable OFData *)socket: (OFSequencedPacketSocket *)socket
151 didSendData: (OFData *)data
152 exception: (nullable id)exception;
153
163- (bool)socket: (OFSequencedPacketSocket *)socket
164 didAcceptSocket: (OFSequencedPacketSocket *)acceptedSocket
165 exception: (nullable id)exception;
166@end
167
183{
184 OFSocketHandle _socket;
185#ifdef OF_AMIGAOS
186 LONG _socketID; /* unused, reserved for ABI stability */
187 int _family; /* unused, reserved for ABI stability */
188#endif
189 bool _canBlock, _listening;
190 OFSocketAddress _remoteAddress;
191 id _Nullable _delegate;
192 OF_RESERVE_IVARS(OFSequencedPacketSocket, 4)
193}
194
203@property (nonatomic) bool canBlock;
208@property (readonly, nonatomic, getter=isListening) bool listening;
218@property (readonly, nonatomic) const OFSocketAddress *remoteAddress;
226@property OF_NULLABLE_PROPERTY (assign, nonatomic)
227 id <OFSequencedPacketSocketDelegate> delegate;
234+ (instancetype)socket;
235
247- (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length;
248
258- (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length;
259
271- (void)asyncReceiveIntoBuffer: (void *)buffer
272 length: (size_t)length
273 runLoopMode: (OFRunLoopMode)runLoopMode;
274
275#ifdef OF_HAVE_BLOCKS
292- (void)asyncReceiveIntoBuffer: (void *)buffer
293 length: (size_t)length
295 OF_DEPRECATED(ObjFW, 1, 2,
296 "Use -[asyncReceiveIntoBuffer:length:handler:] instead");
297
313- (void)asyncReceiveIntoBuffer: (void *)buffer
314 length: (size_t)length
316 handler;
317
337- (void)asyncReceiveIntoBuffer: (void *)buffer
338 length: (size_t)length
339 runLoopMode: (OFRunLoopMode)runLoopMode
341 OF_DEPRECATED(ObjFW, 1, 2,
342 "Use -[asyncReceiveIntoBuffer:length:runLoopMode:handler:] instead");
343
361- (void)asyncReceiveIntoBuffer: (void *)buffer
362 length: (size_t)length
363 runLoopMode: (OFRunLoopMode)runLoopMode
365 handler;
366#endif
367
376- (void)sendBuffer: (const void *)buffer length: (size_t)length;
377
383- (void)asyncSendData: (OFData *)data;
384
392- (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode;
393
394#ifdef OF_HAVE_BLOCKS
405- (void)asyncSendData: (OFData *)data
407 OF_DEPRECATED(ObjFW, 1, 2, "Use -[asyncSendData:handler:] instead");
408
417- (void)asyncSendData: (OFData *)data
419
432- (void)asyncSendData: (OFData *)data
433 runLoopMode: (OFRunLoopMode)runLoopMode
435 OF_DEPRECATED(ObjFW, 1, 2,
436 "Use -[asyncSendData:runLoopMode:handler:] instead");
437
448- (void)asyncSendData: (OFData *)data
449 runLoopMode: (OFRunLoopMode)runLoopMode
451#endif
452
460- (void)listenWithBacklog: (int)backlog;
461
468- (void)listen;
469
477- (instancetype)accept;
478
482- (void)asyncAccept;
483
490- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode;
491
492#ifdef OF_HAVE_BLOCKS
502- (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block
503 OF_DEPRECATED(ObjFW, 1, 2, "Use -[asyncAcceptWithHandler:] instead");
504
512- (void)asyncAcceptWithHandler: (OFSequencedPacketSocketAcceptedHandler)handler;
513
525- (void)
526 asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
528 OF_DEPRECATED(ObjFW, 1, 2,
529 "Use -[asyncAcceptWithRunLoopMode:handler:] instead");
530
540- (void)
541 asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
543#endif
544
548- (void)cancelAsyncRequests;
549
560- (void)releaseSocketFromCurrentThread;
561
572- (void)obtainSocketForCurrentThread;
573
580- (void)close;
581@end
582
583OF_ASSUME_NONNULL_END
bool(^ OFSequencedPacketSocketAsyncReceiveBlock)(size_t length, id exception)
A block which is called when a packet has been received.
Definition OFSequencedPacketSocket.h:43
OFData *(^ OFSequencedPacketSocketAsyncSendDataBlock)(id exception)
A block which is called when a packet has been sent.
Definition OFSequencedPacketSocket.h:71
OFData *(^ OFSequencedPacketSocketDataSentHandler)(OFSequencedPacketSocket *socket, OFData *data, id exception)
A handler which is called when a packet has been sent.
Definition OFSequencedPacketSocket.h:85
bool(^ OFSequencedPacketSocketAcceptedHandler)(OFSequencedPacketSocket *socket, OFSequencedPacketSocket *acceptedSocket, id exception)
A handler which is called when the socket accepted a connection.
Definition OFSequencedPacketSocket.h:114
bool(^ OFSequencedPacketSocketPacketReceivedHandler)(OFSequencedPacketSocket *socket, void *buffer, size_t length, id exception)
A handler which is called when a packet has been received.
Definition OFSequencedPacketSocket.h:58
bool(^ OFSequencedPacketSocketAsyncAcceptBlock)(OFSequencedPacketSocket *acceptedSocket, id exception)
A block which is called when the socket accepted a connection.
Definition OFSequencedPacketSocket.h:99
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:184
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:83
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition OFKernelEventObserver.h:97
A struct which represents a host / port pair for a socket.
Definition OFSocket.h:189