ObjFW
Loading...
Searching...
No Matches
OFTCPSocket.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 "OFStreamSocket.h"
21#import "OFRunLoop.h"
22
23OF_ASSUME_NONNULL_BEGIN
24
27@class OFTCPSocket;
28@class OFString;
29
30#ifdef OF_HAVE_BLOCKS
39typedef void (^OFTCPSocketAsyncConnectBlock)(id _Nullable exception)
40 OF_DEPRECATED(ObjFW, 1, 2, "Use OFTCPSocketConnecetedHandler instead");
41
52 OFString *host, uint16_t port, id _Nullable exception);
53#endif
54
60@protocol OFTCPSocketDelegate <OFStreamSocketDelegate>
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 OF_RESERVE_IVARS(OFTCPSocket, 4)
93}
94
95#ifdef OF_HAVE_CLASS_PROPERTIES
96@property (class, nullable, copy, nonatomic) OFString *SOCKS5Host;
97@property (class, nonatomic) uint16_t SOCKS5Port;
98#endif
99
100#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
109@property (nonatomic) bool sendsKeepAlives;
110#endif
111
112#ifndef OF_WII
122@property (nonatomic) bool canDelaySendingSegments;
123#endif
124
128@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *SOCKS5Host;
129
133@property (nonatomic) uint16_t SOCKS5Port;
134
141@property OF_NULLABLE_PROPERTY (assign, nonatomic)
142 id <OFTCPSocketDelegate> delegate;
143
150+ (void)setSOCKS5Host: (nullable OFString *)SOCKS5Host;
151
157+ (nullable OFString *)SOCKS5Host;
158
164+ (void)setSOCKS5Port: (uint16_t)SOCKS5Port;
165
171+ (uint16_t)SOCKS5Port;
172
181- (void)connectToHost: (OFString *)host port: (uint16_t)port;
182
189- (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port;
190
199- (void)asyncConnectToHost: (OFString *)host
200 port: (uint16_t)port
201 runLoopMode: (OFRunLoopMode)runLoopMode;
202
203#ifdef OF_HAVE_BLOCKS
213- (void)asyncConnectToHost: (OFString *)host
214 port: (uint16_t)port
215 block: (OFTCPSocketAsyncConnectBlock)block
216 OF_DEPRECATED(ObjFW, 1, 2,
217 "Use -[asyncConnectToHost:port:handler:] instead");
218
226- (void)asyncConnectToHost: (OFString *)host
227 port: (uint16_t)port
228 handler: (OFTCPSocketConnectedHandler)handler;
229
241- (void)asyncConnectToHost: (OFString *)host
242 port: (uint16_t)port
243 runLoopMode: (OFRunLoopMode)runLoopMode
244 block: (OFTCPSocketAsyncConnectBlock)block
245 OF_DEPRECATED(ObjFW, 1, 2,
246 "Use -[asyncConnectToHost:port:runLoopMode:handler:] instead");
247
257- (void)asyncConnectToHost: (OFString *)host
258 port: (uint16_t)port
259 runLoopMode: (OFRunLoopMode)runLoopMode
260 handler: (OFTCPSocketConnectedHandler)handler;
261#endif
262
274- (OFSocketAddress)bindToHost: (OFString *)host port: (uint16_t)port;
275@end
276
277OF_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
OFString * SOCKS5Host
The host to use as a SOCKS5 proxy.
Definition OFTCPSocket.h:128
A struct which represents a host / port pair for a socket.
Definition OFSocket.h:189