ObjFW
OFRunLoop+Private.h
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 "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: (of_run_loop_mode_t)mode
43 # ifdef OF_HAVE_BLOCKS
44  block: (nullable of_stream_async_read_block_t)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: (of_run_loop_mode_t)mode
52 # ifdef OF_HAVE_BLOCKS
53  block: (nullable of_stream_async_read_block_t)block
54 # endif
55  delegate: (nullable id <OFStreamDelegate>)delegate;
56 + (void)of_addAsyncReadLineForStream: (OFStream <OFReadyForReadingObserving> *)
57  stream
58  encoding: (of_string_encoding_t)encoding
59  mode: (of_run_loop_mode_t)mode
60 # ifdef OF_HAVE_BLOCKS
61  block: (nullable
63  block
64 # endif
65  delegate: (nullable id <OFStreamDelegate>)delegate;
66 + (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *)
67  stream
68  data: (OFData *)data
69  mode: (of_run_loop_mode_t)mode
70 # ifdef OF_HAVE_BLOCKS
71  block: (nullable of_stream_async_write_data_block_t)
72  block
73 # endif
74  delegate: (nullable id <OFStreamDelegate>)delegate;
75 + (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *)
76  stream
77  string: (OFString *)string
78  encoding: (of_string_encoding_t)encoding
79  mode: (of_run_loop_mode_t)mode
80 # ifdef OF_HAVE_BLOCKS
81  block: (nullable
83  block
84 # endif
85  delegate: (nullable id <OFStreamDelegate>)delegate;
86 # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
87 + (void)of_addAsyncConnectForSocket: (id)socket
88  mode: (of_run_loop_mode_t)mode
89  delegate: (id <OFRunLoopConnectDelegate>)delegate;
90 # endif
91 + (void)of_addAsyncAcceptForSocket: (id)socket
92  mode: (of_run_loop_mode_t)mode
93  block: (nullable id)block
94  delegate: (nullable id)delegate;
95 + (void)of_addAsyncReceiveForDatagramSocket: (OFDatagramSocket *)socket
96  buffer: (void *)buffer
97  length: (size_t)length
98  mode: (of_run_loop_mode_t)mode
99 # ifdef OF_HAVE_BLOCKS
100  block: (nullable of_datagram_socket_async_receive_block_t)block
101 # endif
102  delegate: (nullable id <OFDatagramSocketDelegate>) delegate;
103 + (void)of_addAsyncSendForDatagramSocket: (OFDatagramSocket *)socket
104  data: (OFData *)data
105  receiver: (const of_socket_address_t *)receiver
106  mode: (of_run_loop_mode_t)mode
107 # ifdef OF_HAVE_BLOCKS
108  block: (nullable of_datagram_socket_async_send_data_block_t)block
109 # endif
110  delegate: (nullable id <OFDatagramSocketDelegate>)delegate;
111 + (void)of_addAsyncReceiveForSequencedPacketSocket:
112  (OFSequencedPacketSocket *)socket
113  buffer: (void *)buffer
114  length: (size_t)length
115  mode: (of_run_loop_mode_t)mode
116 # ifdef OF_HAVE_BLOCKS
118 # endif
119  delegate: (nullable id <OFSequencedPacketSocketDelegate>) delegate;
120 + (void)of_addAsyncSendForSequencedPacketSocket:
121  (OFSequencedPacketSocket *)socket
122  data: (OFData *)data
123  mode: (of_run_loop_mode_t)mode
124 # ifdef OF_HAVE_BLOCKS
126 # endif
127  delegate: (nullable id <OFSequencedPacketSocketDelegate>)delegate;
128 + (void)of_cancelAsyncRequestsForObject: (id)object
129  mode: (of_run_loop_mode_t)mode;
130 #endif
131 - (void)of_removeTimer: (OFTimer *)timer forMode: (of_run_loop_mode_t)mode;
132 @end
133 
134 OF_ASSUME_NONNULL_END
OFData *_Nullable(^ of_datagram_socket_async_send_data_block_t)(OFData *_Nonnull data, const of_socket_address_t *_Nonnull receiver, id _Nullable exception)
A block which is called when a packet has been sent.
Definition: OFDatagramSocket.h:52
bool(^ of_datagram_socket_async_receive_block_t)(size_t length, const of_socket_address_t *_Nonnull sender, id _Nullable exception)
A block which is called when a packet has been received.
Definition: OFDatagramSocket.h:39
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
OFData *_Nullable(^ of_stream_async_write_data_block_t)(OFData *_Nonnull data, size_t bytesWritten, id _Nullable exception)
A block which is called when data was written asynchronously to a stream.
Definition: OFStream.h:77
bool(^ of_stream_async_read_block_t)(size_t length, id _Nullable exception)
A block which is called when data was read asynchronously from a stream.
Definition: OFStream.h:49
OFString *_Nullable(^ of_stream_async_write_string_block_t)(OFString *_Nonnull string, size_t bytesWritten, id _Nullable exception)
A block which is called when a string was written asynchronously to a stream.
Definition: OFStream.h:92
bool(^ of_stream_async_read_line_block_t)(OFString *_Nullable line, id _Nullable exception)
A block which is called when a line was read asynchronously from a stream.
Definition: OFStream.h:62
of_string_encoding_t
The encoding of a string.
Definition: OFString.h:68
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
A base class for datagram sockets.
Definition: OFDatagramSocket.h:112
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
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:130
A base class for different types of streams.
Definition: OFStream.h:191
A class for handling strings.
Definition: OFString.h:132
A class for creating and firing timers.
Definition: OFTimer.h:46
A delegate for OFDatagramSocket.
Definition: OFDatagramSocket.h:63
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
Definition: OFStream.h:101
A struct which represents a host / port pair for a socket.
Definition: socket.h:136