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
41typedef bool (^OFStreamSocketAsyncAcceptBlock)(OFStreamSocket *acceptedSocket,
42 id _Nullable exception)
43 OF_DEPRECATED(ObjFW, 1, 2, "Use OFStreamSocketAcceptedHandler instead");
44
56 OFStreamSocket *acceptedSocket, id _Nullable exception);
57#endif
58
64@protocol OFStreamSocketDelegate <OFStreamDelegate>
65@optional
75- (bool)socket: (OFStreamSocket *)socket
76 didAcceptSocket: (OFStreamSocket *)acceptedSocket
77 exception: (nullable id)exception;
78@end
79
87{
88 OFSocketHandle _socket;
89#ifdef OF_AMIGAOS
90 LONG _socketID;
91 int _family; /* unused, reserved for ABI stability */
92#endif
93 bool _atEndOfStream, _listening;
94 OFSocketAddress _remoteAddress;
95 OF_RESERVE_IVARS(OFStreamSocket, 4)
96}
97
101@property (readonly, nonatomic, getter=isListening) bool listening;
111@property (readonly, nonatomic) const OFSocketAddress *remoteAddress;
119@property OF_NULLABLE_PROPERTY (assign, nonatomic)
120 id <OFStreamSocketDelegate> delegate;
127+ (instancetype)socket;
128
136- (void)listenWithBacklog: (int)backlog;
137
144- (void)listen;
145
153- (instancetype)accept;
154
158- (void)asyncAccept;
159
165- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode;
166
167#ifdef OF_HAVE_BLOCKS
177- (void)asyncAcceptWithBlock: (OFStreamSocketAsyncAcceptBlock)block
178 OF_DEPRECATED(ObjFW, 1, 2, "Use -[asyncAcceptWithHandler:] instead");
179
187- (void)asyncAcceptWithHandler: (OFStreamSocketAcceptedHandler)handler;
188
199- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
201 OF_DEPRECATED(ObjFW, 1, 2,
202 "Use -[asyncAcceptWithRunLoopMode:handler:] instead");
203
212- (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
213 handler: (OFStreamSocketAcceptedHandler)handler;
214#endif
215
226- (void)releaseSocketFromCurrentThread;
227
238- (void)obtainSocketForCurrentThread;
239@end
240
241OF_ASSUME_NONNULL_END
bool(^ OFStreamSocketAcceptedHandler)(OFStreamSocket *socket, OFStreamSocket *acceptedSocket, id exception)
A handler which is called when the socket accepted a connection.
Definition OFStreamSocket.h:55
bool(^ OFStreamSocketAsyncAcceptBlock)(OFStreamSocket *acceptedSocket, id exception)
A block which is called when the socket accepted a connection.
Definition OFStreamSocket.h:41
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:88
A base class for different types of streams.
Definition OFStream.h:280
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition OFKernelEventObserver.h:83
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition OFKernelEventObserver.h:97
A struct which represents a host / port pair for a socket.
Definition OFSocket.h:189