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 #ifdef __wii__
69  bool _keepAliveEnabled, _TCPNoDelayEnabled;
70 #endif
71 }
72 
73 #ifdef OF_HAVE_PROPERTIES
74 @property (readonly, getter=isListening) bool listening;
75 @property OF_NULLABLE_PROPERTY (copy) OFString *SOCKS5Host;
76 @property uint16_t SOCKS5Port;
77 @property (getter=isKeepAliveEnabled) bool keepAliveEnabled;
78 @property (getter=isTCPNoDelayEnabled) bool TCPNoDelayEnabled;
79 #endif
80 
87 + (void)setSOCKS5Host: (nullable OFString*)SOCKS5Host;
88 
94 + (nullable OFString*)SOCKS5Host;
95 
101 + (void)setSOCKS5Port: (uint16_t)SOCKS5Port;
102 
108 + (uint16_t)SOCKS5Port;
109 
115 - (void)setSOCKS5Host: (nullable OFString*)host;
116 
122 - (nullable OFString*)SOCKS5Host;
123 
131 - (void)setSOCKS5Port: (uint16_t)port;
132 
138 - (uint16_t)SOCKS5Port;
139 
146 - (void)connectToHost: (OFString*)host
147  port: (uint16_t)port;
148 
149 #ifdef OF_HAVE_THREADS
150 
160 - (void)asyncConnectToHost: (OFString*)host
161  port: (uint16_t)port
162  target: (id)target
163  selector: (SEL)selector;
164 
165 # ifdef OF_HAVE_BLOCKS
166 
173 - (void)asyncConnectToHost: (OFString*)host
174  port: (uint16_t)port
176 # endif
177 #endif
178 
188 - (uint16_t)bindToHost: (OFString*)host
189  port: (uint16_t)port;
190 
196 - (void)listenWithBackLog: (int)backLog;
197 
201 - (void)listen;
202 
208 - (instancetype)accept;
209 
221 - (void)asyncAcceptWithTarget: (id)target
222  selector: (SEL)selector;
223 
224 #ifdef OF_HAVE_BLOCKS
225 
232 - (void)asyncAcceptWithBlock: (of_tcp_socket_async_accept_block_t)block;
233 #endif
234 
242 - (nullable OFString*)remoteAddress;
243 
249 - (bool)isListening;
250 
256 - (void)setKeepAliveEnabled: (bool)enabled;
257 
263 - (bool)isKeepAliveEnabled;
264 
270 - (void)setTCPNoDelayEnabled: (bool)enabled;
271 
277 - (bool)isTCPNoDelayEnabled;
278 @end
279 
280 #ifdef __cplusplus
281 extern "C" {
282 #endif
283 extern Class OF_NULLABLE of_tls_socket_class;
284 #ifdef __cplusplus
285 }
286 #endif
287 
288 OF_ASSUME_NONNULL_END
A class for handling strings.
Definition: OFString.h:91
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
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
A class which provides functions to create and use stream sockets.
Definition: OFStreamSocket.h:28