ObjFW
Loading...
Searching...
No Matches
OFRunLoop+Private.h
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 "OFRunLoop.h"
21#import "OFStream.h"
22#ifdef OF_HAVE_SOCKETS
23# import "OFDatagramSocket.h"
25# import "OFStreamSocket.h"
26# ifdef OF_HAVE_SCTP
27# import "OFSCTPSocket.h"
28# endif
29#endif
30
31OF_ASSUME_NONNULL_BEGIN
32
33#ifdef OF_HAVE_SOCKETS
34@protocol OFRunLoopConnectDelegate <OFObject>
35- (void)of_socketDidConnect: (id)socket
36 exception: (nullable id)exception;
37- (id)of_connectionFailedExceptionForErrNo: (int)errNo;
38@end
39#endif
40
41OF_DIRECT_MEMBERS
42@interface OFRunLoop ()
43+ (void)of_setMainRunLoop: (OFRunLoop *)runLoop;
44#ifdef OF_HAVE_SOCKETS
45+ (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *)
46 stream
47 buffer: (void *)buffer
48 length: (size_t)length
49 mode: (OFRunLoopMode)mode
50# ifdef OF_HAVE_BLOCKS
51 handler: (nullable OFStreamReadHandler)handler
52# endif
53 delegate: (nullable id <OFStreamDelegate>)delegate;
54+ (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *)
55 stream
56 buffer: (void *)buffer
57 exactLength: (size_t)length
58 mode: (OFRunLoopMode)mode
59# ifdef OF_HAVE_BLOCKS
60 handler: (nullable OFStreamReadHandler)handler
61# endif
62 delegate: (nullable id <OFStreamDelegate>)delegate;
63+ (void)of_addAsyncReadStringForStream: (OFStream <OFReadyForReadingObserving
64 > *)stream
65 encoding: (OFStringEncoding)encoding
66 mode: (OFRunLoopMode)mode
67# ifdef OF_HAVE_BLOCKS
68 handler: (nullable OFStreamStringReadHandler)
69 handler
70# endif
71 delegate: (nullable id <OFStreamDelegate>)
72 delegate;
73+ (void)of_addAsyncReadLineForStream: (OFStream <OFReadyForReadingObserving> *)
74 stream
75 encoding: (OFStringEncoding)encoding
76 mode: (OFRunLoopMode)mode
77# ifdef OF_HAVE_BLOCKS
78 handler: (nullable OFStreamStringReadHandler)
79 handler
80# endif
81 delegate: (nullable id <OFStreamDelegate>)delegate;
82+ (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *)
83 stream
84 data: (OFData *)data
85 mode: (OFRunLoopMode)mode
86# ifdef OF_HAVE_BLOCKS
87 handler: (nullable OFStreamDataWrittenHandler)handler
88# endif
89 delegate: (nullable id <OFStreamDelegate>)delegate;
90+ (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *)
91 stream
92 string: (OFString *)string
93 encoding: (OFStringEncoding)encoding
94 mode: (OFRunLoopMode)mode
95# ifdef OF_HAVE_BLOCKS
96 handler: (nullable OFStreamStringWrittenHandler)
97 handler
98# endif
99 delegate: (nullable id <OFStreamDelegate>)delegate;
100# if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
101+ (void)of_addAsyncConnectForSocket: (id)socket
102 mode: (OFRunLoopMode)mode
103 delegate: (id <OFRunLoopConnectDelegate>)delegate;
104# endif
105+ (void)of_addAsyncAcceptForSocket: (id)socket
106 mode: (OFRunLoopMode)mode
107 handler: (nullable id)handler
108 delegate: (nullable id)delegate;
109+ (void)of_addAsyncReceiveForDatagramSocket: (OFDatagramSocket *)socket
110 buffer: (void *)buffer
111 length: (size_t)length
112 mode: (OFRunLoopMode)mode
113# ifdef OF_HAVE_BLOCKS
114 handler: (nullable OFDatagramSocketPacketReceivedHandler)handler
115# endif
116 delegate: (nullable id <OFDatagramSocketDelegate>)delegate;
117+ (void)of_addAsyncSendForDatagramSocket: (OFDatagramSocket *)socket
118 data: (OFData *)data
119 receiver: (const OFSocketAddress *)receiver
120 mode: (OFRunLoopMode)mode
121# ifdef OF_HAVE_BLOCKS
122 handler: (nullable OFDatagramSocketDataSentHandler)handler
123# endif
124 delegate: (nullable id <OFDatagramSocketDelegate>)delegate;
125+ (void)of_addAsyncReceiveForSequencedPacketSocket:
127 buffer: (void *)buffer
128 length: (size_t)length
129 mode: (OFRunLoopMode)mode
130# ifdef OF_HAVE_BLOCKS
131 handler: (nullable OFSequencedPacketSocketPacketReceivedHandler)handler
132# endif
133 delegate: (nullable id <OFSequencedPacketSocketDelegate>)delegate;
134+ (void)of_addAsyncSendForSequencedPacketSocket:
136 data: (OFData *)data
137 mode: (OFRunLoopMode)mode
138# ifdef OF_HAVE_BLOCKS
139 handler: (nullable OFSequencedPacketSocketDataSentHandler)handler
140# endif
141 delegate: (nullable id <OFSequencedPacketSocketDelegate>)delegate;
142# ifdef OF_HAVE_SCTP
143+ (void)of_addAsyncReceiveForSCTPSocket: (OFSCTPSocket *)socket
144 buffer: (void *)buffer
145 length: (size_t)length
146 mode: (OFRunLoopMode)mode
147# ifdef OF_HAVE_BLOCKS
148 handler: (nullable OFSCTPSocketMessageReceivedHandler)handler
149# endif
150 delegate: (nullable id <OFSCTPSocketDelegate>)delegate;
151+ (void)of_addAsyncSendForSCTPSocket: (OFSCTPSocket *)socket
152 data: (OFData *)data
153 info: (OFSCTPMessageInfo)info
154 mode: (OFRunLoopMode)mode
155# ifdef OF_HAVE_BLOCKS
156 handler: (nullable OFSCTPSocketDataSentHandler)handler
157# endif
158 delegate: (nullable id <OFSCTPSocketDelegate>)delegate;
159# endif
160+ (void)of_cancelAsyncRequestsForObject: (id)object mode: (OFRunLoopMode)mode;
161#endif
162- (void)of_removeTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode;
163@end
164
165OF_ASSUME_NONNULL_END
bool(^ OFDatagramSocketPacketReceivedHandler)(OFDatagramSocket *socket, void *buffer, size_t length, const OFSocketAddress *sender, id exception)
A handler which is called when a packet has been received.
Definition OFDatagramSocket.h:60
OFData *(^ OFDatagramSocketDataSentHandler)(OFDatagramSocket *socket, OFData *data, const OFSocketAddress *receiver, id exception)
A handler which is called when a packet has been sent.
Definition OFDatagramSocket.h:88
bool(^ OFSCTPSocketMessageReceivedHandler)(OFSCTPSocket *socket, void *buffer, size_t length, OFSCTPMessageInfo info, id exception)
A handler which is called when a message has been received.
Definition OFSCTPSocket.h:99
OFData *(^ OFSCTPSocketDataSentHandler)(OFSCTPSocket *socket, OFData *data, OFSCTPMessageInfo info, id exception)
A handler which is called when a message has been sent.
Definition OFSCTPSocket.h:113
OFData *(^ OFSequencedPacketSocketDataSentHandler)(OFSequencedPacketSocket *socket, OFData *data, id exception)
A handler which is called when a packet has been sent.
Definition OFSequencedPacketSocket.h:85
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
OFData *(^ OFStreamDataWrittenHandler)(OFStream *stream, OFData *data, size_t bytesWritten, id exception)
A handler which is called when data was written asynchronously to a stream.
Definition OFStream.h:132
bool(^ OFStreamReadHandler)(OFStream *stream, void *buffer, size_t length, id exception)
A handler which is called when data was read asynchronously from a stream.
Definition OFStream.h:69
OFString *(^ OFStreamStringWrittenHandler)(OFStream *stream, OFString *string, OFStringEncoding encoding, size_t bytesWritten, id exception)
A handler which is called when a string was written asynchronously to a stream.
Definition OFStream.h:166
bool(^ OFStreamStringReadHandler)(OFStream *stream, OFString *string, id exception)
A block which is called when a string was read asynchronously from a stream.
Definition OFStream.h:83
OFStringEncoding
The encoding of a string.
Definition OFString.h:65
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
A base class for datagram sockets.
Definition OFDatagramSocket.h:147
An abstract class for storing objects in a dictionary.
Definition OFDictionary.h:84
The root class for all other classes inside ObjFW.
Definition OFObject.h:692
A class providing a run loop for the application and its processes.
Definition OFRunLoop.h:66
A class which provides methods to create and use SCTP sockets in one-to-one mode.
Definition OFSCTPSocket.h:180
A base class for sequenced packet sockets.
Definition OFSequencedPacketSocket.h:184
A base class for different types of streams.
Definition OFStream.h:280
A class for handling strings.
Definition OFString.h:143
A class for creating and firing timers.
Definition OFTimer.h:50
A struct which represents a host / port pair for a socket.
Definition OFSocket.h:189