ObjFW
OFTCPSocket.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFStreamSocket.h"
18 
19 #import "socket.h"
20 
21 OF_ASSUME_NONNULL_BEGIN
22 
25 @class OFTCPSocket;
26 @class OFString;
27 
28 #ifdef OF_HAVE_BLOCKS
29 
37  OFException *OF_NULLABLE exception);
38 
50  OFTCPSocket *acceptedSocket, OFException *OF_NULLABLE exception);
51 #endif
52 
62 {
63  bool _listening;
64  struct sockaddr *_address;
65  socklen_t _addressLength;
66  OFString *_SOCKS5Host;
67  uint16_t _SOCKS5Port;
68 }
69 
70 #ifdef OF_HAVE_PROPERTIES
71 @property (readonly, getter=isListening) bool listening;
72 @property OF_NULLABLE_PROPERTY (copy) OFString *SOCKS5Host;
73 @property uint16_t SOCKS5Port;
74 @property (getter=isKeepAliveEnabled) bool keepAliveEnabled;
75 @property (getter=isTCPNoDelayEnabled) bool TCPNoDelayEnabled;
76 #endif
77 
84 + (void)setSOCKS5Host: (nullable OFString*)SOCKS5Host;
85 
91 + (nullable OFString*)SOCKS5Host;
92 
98 + (void)setSOCKS5Port: (uint16_t)SOCKS5Port;
99 
105 + (uint16_t)SOCKS5Port;
106 
112 - (void)setSOCKS5Host: (nullable OFString*)host;
113 
119 - (nullable OFString*)SOCKS5Host;
120 
128 - (void)setSOCKS5Port: (uint16_t)port;
129 
135 - (uint16_t)SOCKS5Port;
136 
143 - (void)connectToHost: (OFString*)host
144  port: (uint16_t)port;
145 
146 #ifdef OF_HAVE_THREADS
147 
157 - (void)asyncConnectToHost: (OFString*)host
158  port: (uint16_t)port
159  target: (id)target
160  selector: (SEL)selector;
161 
162 # ifdef OF_HAVE_BLOCKS
163 
170 - (void)asyncConnectToHost: (OFString*)host
171  port: (uint16_t)port
173 # endif
174 #endif
175 
185 - (uint16_t)bindToHost: (OFString*)host
186  port: (uint16_t)port;
187 
193 - (void)listenWithBackLog: (int)backLog;
194 
198 - (void)listen;
199 
205 - (instancetype)accept;
206 
218 - (void)asyncAcceptWithTarget: (id)target
219  selector: (SEL)selector;
220 
221 #ifdef OF_HAVE_BLOCKS
222 
229 - (void)asyncAcceptWithBlock: (of_tcp_socket_async_accept_block_t)block;
230 #endif
231 
239 - (nullable OFString*)remoteAddress;
240 
246 - (bool)isListening;
247 
253 - (void)setKeepAliveEnabled: (bool)enabled;
254 
260 - (bool)isKeepAliveEnabled;
261 
267 - (void)setTCPNoDelayEnabled: (bool)enabled;
268 
274 - (bool)isTCPNoDelayEnabled;
275 @end
276 
277 #ifdef __cplusplus
278 extern "C" {
279 #endif
280 extern Class OF_NULLABLE of_tls_socket_class;
281 #ifdef __cplusplus
282 }
283 #endif
284 
285 OF_ASSUME_NONNULL_END
A class for handling strings.
Definition: OFString.h:91
void(^ of_tcp_socket_async_connect_block_t)(OFTCPSocket *socket, OFException *OF_NULLABLE exception)
A block which is called when the socket connected.
Definition: OFTCPSocket.h:36
A class which provides functions to create and use TCP sockets.
Definition: OFTCPSocket.h:61
bool(^ of_tcp_socket_async_accept_block_t)(OFTCPSocket *socket, OFTCPSocket *acceptedSocket, OFException *OF_NULLABLE exception)
A block which is called when the socket accepted a connection.
Definition: OFTCPSocket.h:49
The base class for all exceptions in ObjFW.
Definition: OFException.h:144
A class which provides functions to create and use stream sockets.
Definition: OFStreamSocket.h:28