ObjFW
OFSequencedPacketSocket.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2021 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 
20 #import "socket.h"
21 
22 OF_ASSUME_NONNULL_BEGIN
23 
26 @class OFData;
28 
29 #ifdef OF_HAVE_BLOCKS
39  id _Nullable exception);
40 
50  OFData *_Nonnull data, id _Nullable exception);
51 
62  OFSequencedPacketSocket *acceptedSocket, id _Nullable exception);
63 #endif
64 
72 @optional
83 - (bool)socket: (OFSequencedPacketSocket *)socket
84  didReceiveIntoBuffer: (void *)buffer
85  length: (size_t)length
86  exception: (nullable id)exception;
87 
96 - (nullable OFData *)socket: (OFSequencedPacketSocket *)socket
97  didSendData: (OFData *)data
98  exception: (nullable id)exception;
99 
109 - (bool)socket: (OFSequencedPacketSocket *)socket
110  didAcceptSocket: (OFSequencedPacketSocket *)acceptedSocket
111  exception: (nullable id)exception;
112 @end
113 
129 {
130  of_socket_t _socket;
131  bool _canBlock, _listening;
132  of_socket_address_t _remoteAddress;
133  id _Nullable _delegate;
134  OF_RESERVE_IVARS(OFSequencedPacketSocket, 4)
135 }
136 
142 @property (nonatomic) bool canBlock;
143 
147 @property (readonly, nonatomic, getter=isListening) bool listening;
148 
154 @property (readonly, nonatomic) const of_socket_address_t *remoteAddress;
155 
162 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
164 
170 + (instancetype)socket;
171 
181 - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length;
182 
192 - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length;
193 
204 - (void)asyncReceiveIntoBuffer: (void *)buffer
205  length: (size_t)length
206  runLoopMode: (of_run_loop_mode_t)runLoopMode;
207 
208 #ifdef OF_HAVE_BLOCKS
223 - (void)
224  asyncReceiveIntoBuffer: (void *)buffer
225  length: (size_t)length
227  block;
228 
244 - (void)
245  asyncReceiveIntoBuffer: (void *)buffer
246  length: (size_t)length
247  runLoopMode: (of_run_loop_mode_t)runLoopMode
249  block;
250 #endif
251 
258 - (void)sendBuffer: (const void *)buffer length: (size_t)length;
259 
265 - (void)asyncSendData: (OFData *)data;
266 
273 - (void)asyncSendData: (OFData *)data
274  runLoopMode: (of_run_loop_mode_t)runLoopMode;
275 
276 #ifdef OF_HAVE_BLOCKS
285 - (void)asyncSendData: (OFData *)data
287  block;
288 
298 - (void)asyncSendData: (OFData *)data
299  runLoopMode: (of_run_loop_mode_t)runLoopMode
301  block;
302 #endif
303 
309 - (void)listenWithBacklog: (int)backlog;
310 
314 - (void)listen;
315 
321 - (instancetype)accept;
322 
326 - (void)asyncAccept;
327 
333 - (void)asyncAcceptWithRunLoopMode: (of_run_loop_mode_t)runLoopMode;
334 
335 #ifdef OF_HAVE_BLOCKS
343 - (void)asyncAcceptWithBlock:
345 
354 - (void)asyncAcceptWithRunLoopMode: (of_run_loop_mode_t)runLoopMode
356 #endif
357 
361 - (void)cancelAsyncRequests;
362 
367 - (void)close;
368 @end
369 
370 OF_ASSUME_NONNULL_END
OFData *_Nullable(^ of_sequenced_packet_socket_async_send_data_block_t)(OFData *_Nonnull data, id _Nullable exception)
A block which is called when a packet has been sent.
Definition: OFSequencedPacketSocket.h:49
bool(^ of_sequenced_packet_socket_async_receive_block_t)(size_t length, id _Nullable exception)
A block which is called when a packet has been received.
Definition: OFSequencedPacketSocket.h:38
bool(^ of_sequenced_packet_socket_async_accept_block_t)(OFSequencedPacketSocket *acceptedSocket, id _Nullable exception)
A block which is called when the socket accepted a connection.
Definition: OFSequencedPacketSocket.h:61
struct objc_object * id
A pointer to any object.
Definition: ObjFWRT.h:90
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:40
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A base class for sequenced packet sockets.
Definition: OFSequencedPacketSocket.h:130
A protocol for the creation of copies.
Definition: OFObject.h:1187
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition: OFKernelEventObserver.h:85
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition: OFKernelEventObserver.h:100
A delegate for OFSequencedPacketSocket.
Definition: OFSequencedPacketSocket.h:71
A struct which represents a host / port pair for a socket.
Definition: socket.h:136