ObjFW
OFRunLoop+Private.h
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 "OFRunLoop.h"
17 #import "OFStream.h"
18 #ifdef OF_HAVE_SOCKETS
19 # import "OFDatagramSocket.h"
21 # import "OFStreamSocket.h"
22 #endif
23 
24 OF_ASSUME_NONNULL_BEGIN
25 
26 #ifdef OF_HAVE_SOCKETS
27 @protocol OFRunLoopConnectDelegate <OFObject>
28 - (void)of_socketDidConnect: (id)socket
29  exception: (nullable id)exception;
30 - (id)of_connectionFailedExceptionForErrNo: (int)errNo;
31 @end
32 #endif
33 
34 OF_DIRECT_MEMBERS
35 @interface OFRunLoop ()
36 + (void)of_setMainRunLoop: (OFRunLoop *)runLoop;
37 #ifdef OF_HAVE_SOCKETS
38 + (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *)
39  stream
40  buffer: (void *)buffer
41  length: (size_t)length
42  mode: (OFRunLoopMode)mode
43 # ifdef OF_HAVE_BLOCKS
44  block: (nullable OFStreamAsyncReadBlock)block
45 # endif
46  delegate: (nullable id <OFStreamDelegate>)delegate;
47 + (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *)
48  stream
49  buffer: (void *)buffer
50  exactLength: (size_t)length
51  mode: (OFRunLoopMode)mode
52 # ifdef OF_HAVE_BLOCKS
53  block: (nullable OFStreamAsyncReadBlock)block
54 # endif
55  delegate: (nullable id <OFStreamDelegate>)delegate;
56 + (void)of_addAsyncReadLineForStream: (OFStream <OFReadyForReadingObserving> *)
57  stream
58  encoding: (OFStringEncoding)encoding
59  mode: (OFRunLoopMode)mode
60 # ifdef OF_HAVE_BLOCKS
61  block: (nullable OFStreamAsyncReadLineBlock)block
62 # endif
63  delegate: (nullable id <OFStreamDelegate>)delegate;
64 + (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *)
65  stream
66  data: (OFData *)data
67  mode: (OFRunLoopMode)mode
68 # ifdef OF_HAVE_BLOCKS
69  block: (nullable OFStreamAsyncWriteDataBlock)block
70 # endif
71  delegate: (nullable id <OFStreamDelegate>)delegate;
72 + (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *)
73  stream
74  string: (OFString *)string
75  encoding: (OFStringEncoding)encoding
76  mode: (OFRunLoopMode)mode
77 # ifdef OF_HAVE_BLOCKS
78  block: (nullable OFStreamAsyncWriteStringBlock)block
79 # endif
80  delegate: (nullable id <OFStreamDelegate>)delegate;
81 # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
82 + (void)of_addAsyncConnectForSocket: (id)socket
83  mode: (OFRunLoopMode)mode
84  delegate: (id <OFRunLoopConnectDelegate>)delegate;
85 # endif
86 + (void)of_addAsyncAcceptForSocket: (id)socket
87  mode: (OFRunLoopMode)mode
88  block: (nullable id)block
89  delegate: (nullable id)delegate;
90 + (void)of_addAsyncReceiveForDatagramSocket: (OFDatagramSocket *)socket
91  buffer: (void *)buffer
92  length: (size_t)length
93  mode: (OFRunLoopMode)mode
94 # ifdef OF_HAVE_BLOCKS
95  block: (nullable OFDatagramSocketAsyncReceiveBlock)block
96 # endif
97  delegate: (nullable id <OFDatagramSocketDelegate>) delegate;
98 + (void)of_addAsyncSendForDatagramSocket: (OFDatagramSocket *)socket
99  data: (OFData *)data
100  receiver: (const OFSocketAddress *)receiver
101  mode: (OFRunLoopMode)mode
102 # ifdef OF_HAVE_BLOCKS
103  block: (nullable OFDatagramSocketAsyncSendDataBlock)block
104 # endif
105  delegate: (nullable id <OFDatagramSocketDelegate>)delegate;
106 + (void)of_addAsyncReceiveForSequencedPacketSocket:
107  (OFSequencedPacketSocket *)socket
108  buffer: (void *)buffer
109  length: (size_t)length
110  mode: (OFRunLoopMode)mode
111 # ifdef OF_HAVE_BLOCKS
112  block: (nullable OFSequencedPacketSocketAsyncReceiveBlock)block
113 # endif
114  delegate: (nullable id <OFSequencedPacketSocketDelegate>) delegate;
115 + (void)of_addAsyncSendForSequencedPacketSocket:
116  (OFSequencedPacketSocket *)socket
117  data: (OFData *)data
118  mode: (OFRunLoopMode)mode
119 # ifdef OF_HAVE_BLOCKS
120  block: (nullable OFSequencedPacketSocketAsyncSendDataBlock)block
121 # endif
122  delegate: (nullable id <OFSequencedPacketSocketDelegate>)delegate;
123 + (void)of_cancelAsyncRequestsForObject: (id)object mode: (OFRunLoopMode)mode;
124 #endif
125 - (void)of_removeTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode;
126 @end
127 
128 OF_ASSUME_NONNULL_END
bool(^ OFDatagramSocketAsyncReceiveBlock)(size_t length, const OFSocketAddress *sender, id exception)
A block which is called when a packet has been received.
Definition: OFDatagramSocket.h:38
OFData *(^ OFDatagramSocketAsyncSendDataBlock)(id exception)
A block which is called when a packet has been sent.
Definition: OFDatagramSocket.h:48
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(^ OFStreamAsyncReadBlock)(size_t length, id exception)
A block which is called when data was read asynchronously from a stream.
Definition: OFStream.h:49
OFString *(^ OFStreamAsyncWriteStringBlock)(size_t bytesWritten, id exception)
A block which is called when a string was written asynchronously to a stream.
Definition: OFStream.h:89
bool(^ OFStreamAsyncReadLineBlock)(OFString *line, id exception)
A block which is called when a line was read asynchronously from a stream.
Definition: OFStream.h:61
OFData *(^ OFStreamAsyncWriteDataBlock)(size_t bytesWritten, id exception)
A block which is called when data was written asynchronously to a stream.
Definition: OFStream.h:75
OFStringEncoding
The encoding of a string.
Definition: OFString.h:61
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
A base class for datagram sockets.
Definition: OFDatagramSocket.h:107
The root class for all other classes inside ObjFW.
Definition: OFObject.h:688
A class providing a run loop for the application and its processes.
Definition: OFRunLoop.h:62
A base class for sequenced packet sockets.
Definition: OFSequencedPacketSocket.h:128
A base class for different types of streams.
Definition: OFStream.h:188
A class for handling strings.
Definition: OFString.h:135
A class for creating and firing timers.
Definition: OFTimer.h:46
A delegate for OFDatagramSocket.
Definition: OFDatagramSocket.h:58
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 delegate for OFSequencedPacketSocket.
Definition: OFSequencedPacketSocket.h:69
Definition: OFStream.h:98
A struct which represents a host / port pair for a socket.
Definition: OFSocket.h:182