ObjFW
OFTCPSocket.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
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 *_Nullable exception);
38 
50  OFTCPSocket *acceptedSocket, OFException *_Nullable exception);
51 #endif
52 
62 {
63  bool _listening;
64  struct sockaddr *_Nullable _address;
65  socklen_t _addressLength;
66  OFString *_Nullable _SOCKS5Host;
67  uint16_t _SOCKS5Port;
68 #ifdef OF_WII
69  uint16_t _port;
70 #endif
71 }
72 
76 @property OF_NULLABLE_PROPERTY (nonatomic, copy) OFString *SOCKS5Host;
77 
81 @property (nonatomic) uint16_t SOCKS5Port;
82 
89 + (void)setSOCKS5Host: (nullable OFString *)SOCKS5Host;
90 
96 + (nullable OFString *)SOCKS5Host;
97 
103 + (void)setSOCKS5Port: (uint16_t)SOCKS5Port;
104 
110 + (uint16_t)SOCKS5Port;
111 
118 - (void)connectToHost: (OFString *)host
119  port: (uint16_t)port;
120 
121 #ifdef OF_HAVE_THREADS
122 
132 - (void)asyncConnectToHost: (OFString *)host
133  port: (uint16_t)port
134  target: (id)target
135  selector: (SEL)selector;
136 
137 # ifdef OF_HAVE_BLOCKS
138 
145 - (void)asyncConnectToHost: (OFString *)host
146  port: (uint16_t)port
148 # endif
149 #endif
150 
160 - (uint16_t)bindToHost: (OFString *)host
161  port: (uint16_t)port;
162 
168 - (void)listenWithBackLog: (int)backLog;
169 
173 - (void)listen;
174 
180 - (instancetype)accept;
181 
193 - (void)asyncAcceptWithTarget: (id)target
194  selector: (SEL)selector;
195 
196 #ifdef OF_HAVE_BLOCKS
197 
204 - (void)asyncAcceptWithBlock: (of_tcp_socket_async_accept_block_t)block;
205 #endif
206 
214 - (nullable OFString *)remoteAddress;
215 
221 - (bool)isListening;
222 
223 #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
224 
231 - (void)setKeepAliveEnabled: (bool)enabled;
232 
240 - (bool)isKeepAliveEnabled;
241 #endif
242 
243 #ifndef OF_WII
244 
251 - (void)setTCPNoDelayEnabled: (bool)enabled;
252 
260 - (bool)isTCPNoDelayEnabled;
261 #endif
262 @end
263 
264 #ifdef __cplusplus
265 extern "C" {
266 #endif
267 extern Class _Nullable of_tls_socket_class;
268 #ifdef __cplusplus
269 }
270 #endif
271 
272 OF_ASSUME_NONNULL_END
bool isKeepAliveEnabled()
Returns whether keep alive is enabled for the connection.
Definition: OFTCPSocket.m:623
id copy()
Returns the class.
Definition: OFObject.m:1133
A class for handling strings.
Definition: OFString.h:114
nullable OFString * remoteAddress()
Returns the remote address of the socket.
Definition: OFTCPSocket.m:591
nullable OFString * SOCKS5Host()
Returns the host to use as a SOCKS5 proxy when creating a new socket.
The base class for all exceptions in ObjFW.
Definition: OFException.h:143
A class which provides methods to create and use TCP sockets.
Definition: OFTCPSocket.h:61
A class which provides methods to create and use stream sockets.
Definition: OFStreamSocket.h:28
bool isListening()
Returns whether the socket is a listening socket.
Definition: OFTCPSocket.m:606
instancetype accept()
Accept an incoming connection.
Definition: OFTCPSocket.m:521
bool isTCPNoDelayEnabled()
Returns whether TCP_NODELAY is enabled for the connection.
Definition: OFTCPSocket.m:650
void(^ of_tcp_socket_async_connect_block_t)(OFTCPSocket *socket, OFException *_Nullable exception)
A block which is called when the socket connected.
Definition: OFTCPSocket.h:36
nonatomic
Definition: OFTCPSocket.h:76
bool(^ of_tcp_socket_async_accept_block_t)(OFTCPSocket *socket, OFTCPSocket *acceptedSocket, OFException *_Nullable exception)
A block which is called when the socket accepted a connection.
Definition: OFTCPSocket.h:49
void listen()
Listen on the socket.
Definition: OFTCPSocket.m:502
uint16_t SOCKS5Port()
Returns the port to use as a SOCKS5 proxy when creating a new socket.