ObjFW
Loading...
Searching...
No Matches
OFStreamSocket.h
Go to the documentation of this file.
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 "OFStream.h"
21#import "OFSocket.h"
22
23OF_ASSUME_NONNULL_BEGIN
24
27@class OFStreamSocket;
28
29#ifdef OF_HAVE_BLOCKS
39typedef bool (^OFStreamSocketAsyncAcceptBlock)(OFStreamSocket *acceptedSocket,
40 id _Nullable exception);
41#endif
42
48@protocol OFStreamSocketDelegate <OFStreamDelegate>
49@optional
59- (bool)socket: (OFStreamSocket *)socket
60 didAcceptSocket: (OFStreamSocket *)acceptedSocket
61 exception: (nullable id)exception;
62@end
63
71{
72 OFSocketHandle _socket;
73#ifdef OF_AMIGAOS
74 LONG _socketID;
75 int _family; /* unused, reserved for ABI stability */
76#endif
77 bool _atEndOfStream, _listening;
78 OFSocketAddress _remoteAddress;
79 OF_RESERVE_IVARS(OFStreamSocket, 4)
80}
81
85@property (readonly, nonatomic, getter=isListening) bool listening;
95@property (readonly, nonatomic) const OFSocketAddress *remoteAddress;
103@property OF_NULLABLE_PROPERTY (assign, nonatomic)
104 id <OFStreamSocketDelegate> delegate;
111+ (instancetype)socket;
112
120- (void)listenWithBacklog: (int)backlog;
121
128- (void)listen;
129
137- (instancetype)accept;
138
142- (void)asyncAccept;
143
149- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode;
150
151#ifdef OF_HAVE_BLOCKS
159- (void)asyncAcceptWithBlock: (OFStreamSocketAsyncAcceptBlock)block;
160
169- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
170 block: (OFStreamSocketAsyncAcceptBlock)block;
171#endif
172
183- (void)releaseSocketFromCurrentThread;
184
195- (void)obtainSocketForCurrentThread;
196@end
197
198OF_ASSUME_NONNULL_END
bool(^ OFStreamSocketAsyncAcceptBlock)(OFStreamSocket *acceptedSocket, id exception)
A block which is called when the socket accepted a connection.
Definition OFStreamSocket.h:39
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:72
A base class for different types of streams.
Definition OFStream.h:192
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition OFKernelEventObserver.h:88
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition OFKernelEventObserver.h:103
A struct which represents a host / port pair for a socket.
Definition OFSocket.h:186