ObjFW
OFTCPSocket.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2025 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 "OFStreamSocket.h"
21 #import "OFRunLoop.h"
22 
23 OF_ASSUME_NONNULL_BEGIN
24 
27 @class OFTCPSocket;
28 @class OFString;
29 
30 #ifdef OF_HAVE_BLOCKS
39 typedef void (^OFTCPSocketAsyncConnectBlock)(id _Nullable exception)
40  OF_DEPRECATED(ObjFW, 1, 2, "Use OFTCPSocketConnecetedHandler instead");
41 
51 typedef void (^OFTCPSocketConnectedHandler)(OFTCPSocket *socket,
52  OFString *host, uint16_t port, id _Nullable exception);
53 #endif
54 
61 @optional
71 - (void)socket: (OFTCPSocket *)socket
72  didConnectToHost: (OFString *)host
73  port: (uint16_t)port
74  exception: (nullable id)exception;
75 @end
76 
86 {
87  OFString *_Nullable _SOCKS5Host;
88  uint16_t _SOCKS5Port;
89 #ifdef OF_WII
90  uint16_t _port;
91 #endif
92  uintptr_t _flags; /* Change to a smaller type on ABI bump */
93  OF_RESERVE_IVARS(OFTCPSocket, 3)
94 }
95 
96 #ifdef OF_HAVE_CLASS_PROPERTIES
97 @property (class, nullable, copy, nonatomic) OFString *SOCKS5Host;
98 @property (class, nonatomic) uint16_t SOCKS5Port;
99 #endif
100 
101 #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
110 @property (nonatomic) bool sendsKeepAlives;
111 #endif
112 
113 #ifndef OF_WII
123 @property (nonatomic) bool canDelaySendingSegments;
124 #endif
125 
131 @property (nonatomic) bool allowsMPTCP;
132 
136 @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *SOCKS5Host;
137 
141 @property (nonatomic) uint16_t SOCKS5Port;
142 
149 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
150  id <OFTCPSocketDelegate> delegate;
151 
158 + (void)setSOCKS5Host: (nullable OFString *)SOCKS5Host;
159 
165 + (nullable OFString *)SOCKS5Host;
166 
172 + (void)setSOCKS5Port: (uint16_t)SOCKS5Port;
173 
179 + (uint16_t)SOCKS5Port;
180 
189 - (void)connectToHost: (OFString *)host port: (uint16_t)port;
190 
197 - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port;
198 
207 - (void)asyncConnectToHost: (OFString *)host
208  port: (uint16_t)port
209  runLoopMode: (OFRunLoopMode)runLoopMode;
210 
211 #ifdef OF_HAVE_BLOCKS
221 - (void)asyncConnectToHost: (OFString *)host
222  port: (uint16_t)port
223  block: (OFTCPSocketAsyncConnectBlock)block
224  OF_DEPRECATED(ObjFW, 1, 2,
225  "Use -[asyncConnectToHost:port:handler:] instead");
226 
234 - (void)asyncConnectToHost: (OFString *)host
235  port: (uint16_t)port
236  handler: (OFTCPSocketConnectedHandler)handler;
237 
249 - (void)asyncConnectToHost: (OFString *)host
250  port: (uint16_t)port
251  runLoopMode: (OFRunLoopMode)runLoopMode
252  block: (OFTCPSocketAsyncConnectBlock)block
253  OF_DEPRECATED(ObjFW, 1, 2,
254  "Use -[asyncConnectToHost:port:runLoopMode:handler:] instead");
255 
265 - (void)asyncConnectToHost: (OFString *)host
266  port: (uint16_t)port
267  runLoopMode: (OFRunLoopMode)runLoopMode
268  handler: (OFTCPSocketConnectedHandler)handler;
269 #endif
270 
282 - (OFSocketAddress)bindToHost: (OFString *)host port: (uint16_t)port;
283 @end
284 
285 OF_ASSUME_NONNULL_END
void(^ OFTCPSocketAsyncConnectBlock)(id exception)
A block which is called when the socket connected.
Definition: OFTCPSocket.h:39
void(^ OFTCPSocketConnectedHandler)(OFTCPSocket *socket, OFString *host, uint16_t port, id exception)
A handler which is called when the socket connected.
Definition: OFTCPSocket.h:51
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 class for handling strings.
Definition: OFString.h:143
A class which provides methods to create and use TCP sockets.
Definition: OFTCPSocket.h:86
Definition: OFStreamSocket.h:64
Definition: OFTCPSocket.h:60
A struct which represents a host / port pair for a socket.
Definition: OFSocket.h:189