ObjFW
OFStreamSocket.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2026 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 
23 OF_ASSUME_NONNULL_BEGIN
24 
27 @class OFStreamSocket;
28 
29 #ifdef OF_HAVE_BLOCKS
41 typedef 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 
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;
102 
111 @property (readonly, nonatomic) const OFSocketAddress *remoteAddress;
112 
119 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
120  id <OFStreamSocketDelegate> delegate;
121 
127 + (instancetype)socket;
128 
136 - (void)listenWithBacklog: (int)backlog;
137 
144 - (void)listen;
145 
155 - (instancetype)accept;
156 
162 - (void)asyncAccept;
163 
171 - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode;
172 
173 #ifdef OF_HAVE_BLOCKS
183 - (void)asyncAcceptWithBlock: (OFStreamSocketAsyncAcceptBlock)block
184  OF_DEPRECATED(ObjFW, 1, 2, "Use -[asyncAcceptWithHandler:] instead");
185 
195 - (void)asyncAcceptWithHandler: (OFStreamSocketAcceptedHandler)handler;
196 
207 - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
208  block: (OFStreamSocketAsyncAcceptBlock)block
209  OF_DEPRECATED(ObjFW, 1, 2,
210  "Use -[asyncAcceptWithRunLoopMode:handler:] instead");
211 
222 - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
223  handler: (OFStreamSocketAcceptedHandler)handler;
224 #endif
225 
236 - (void)releaseSocketFromCurrentThread;
237 
248 - (void)obtainSocketForCurrentThread;
249 @end
250 
251 OF_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:84
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition: OFKernelEventObserver.h:98
Definition: OFStream.h:176
Definition: OFStreamSocket.h:64
A struct which represents a host / port pair for a socket.
Definition: OFSocket.h:189