ObjFW
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 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 #import "OFSocket.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
23 @class OFStreamSocket;
24 
25 #ifdef OF_HAVE_BLOCKS
35 typedef bool (^OFStreamSocketAsyncAcceptBlock)(OFStreamSocket *acceptedSocket,
36  id _Nullable exception);
37 #endif
38 
45 @optional
55 - (bool)socket: (OFStreamSocket *)socket
56  didAcceptSocket: (OFStreamSocket *)acceptedSocket
57  exception: (nullable id)exception;
58 @end
59 
67 {
68  OFSocketHandle _socket;
69 #ifdef OF_AMIGAOS
70  LONG _socketID;
71  int _family; /* unused, reserved for ABI stability */
72 #endif
73  bool _atEndOfStream, _listening;
74  OFSocketAddress _remoteAddress;
75  OF_RESERVE_IVARS(OFStreamSocket, 4)
76 }
77 
81 @property (readonly, nonatomic, getter=isListening) bool listening;
82 
91 @property (readonly, nonatomic) const OFSocketAddress *remoteAddress;
92 
99 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
100  id <OFStreamSocketDelegate> delegate;
101 
107 + (instancetype)socket;
108 
116 - (void)listenWithBacklog: (int)backlog;
117 
124 - (void)listen;
125 
133 - (instancetype)accept;
134 
138 - (void)asyncAccept;
139 
145 - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode;
146 
147 #ifdef OF_HAVE_BLOCKS
155 - (void)asyncAcceptWithBlock: (OFStreamSocketAsyncAcceptBlock)block;
156 
165 - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode
166  block: (OFStreamSocketAsyncAcceptBlock)block;
167 #endif
168 
179 - (void)releaseSocketFromCurrentThread;
180 
191 - (void)obtainSocketForCurrentThread;
192 @end
193 
194 OF_ASSUME_NONNULL_END
bool(^ OFStreamSocketAsyncAcceptBlock)(OFStreamSocket *acceptedSocket, id exception)
A block which is called when the socket accepted a connection.
Definition: OFStreamSocket.h:35
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:38
A class which provides methods to create and use stream sockets.
Definition: OFStreamSocket.h:68
A base class for different types of streams.
Definition: OFStream.h:188
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:99
Definition: OFStream.h:98
Definition: OFStreamSocket.h:44
A struct which represents a host / port pair for a socket.
Definition: OFSocket.h:182