ObjFW
OFStreamSocket.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 "OFStream.h"
17 
18 #import "socket.h"
19 
20 OF_ASSUME_NONNULL_BEGIN
21 
24 @class OFStreamSocket;
25 
26 #ifdef OF_HAVE_BLOCKS
37  OFStreamSocket *acceptedSocket, id _Nullable exception);
38 #endif
39 
46 @optional
56 - (bool)socket: (OFStreamSocket *)socket
57  didAcceptSocket: (OFStreamSocket *)acceptedSocket
58  exception: (nullable id)exception;
59 @end
60 
68 {
69  of_socket_t _socket;
70  bool _atEndOfStream, _listening;
71  of_socket_address_t _remoteAddress;
72  OF_RESERVE_IVARS(OFStreamSocket, 4)
73 }
74 
78 @property (readonly, nonatomic, getter=isListening) bool listening;
79 
85 @property (readonly, nonatomic) const of_socket_address_t *remoteAddress;
86 
93 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
95 
101 + (instancetype)socket;
102 
108 - (void)listenWithBacklog: (int)backlog;
109 
113 - (void)listen;
114 
120 - (instancetype)accept;
121 
125 - (void)asyncAccept;
126 
132 - (void)asyncAcceptWithRunLoopMode: (of_run_loop_mode_t)runLoopMode;
133 
134 #ifdef OF_HAVE_BLOCKS
142 - (void)asyncAcceptWithBlock: (of_stream_socket_async_accept_block_t)block;
143 
152 - (void)asyncAcceptWithRunLoopMode: (of_run_loop_mode_t)runLoopMode
154  block;
155 #endif
156 @end
157 
158 OF_ASSUME_NONNULL_END
bool(^ of_stream_socket_async_accept_block_t)(OFStreamSocket *acceptedSocket, id _Nullable exception)
A block which is called when the socket accepted a connection.
Definition: OFStreamSocket.h:36
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 which provides methods to create and use stream sockets.
Definition: OFStreamSocket.h:69
A base class for different types of streams.
Definition: OFStream.h:191
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
Definition: OFStream.h:101
Definition: OFStreamSocket.h:45
A struct which represents a host / port pair for a socket.
Definition: socket.h:136