ObjFW
 All Classes Functions Variables
OFTCPSocket.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012
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 #ifndef __STDC_LIMIT_MACROS
18 # define __STDC_LIMIT_MACROS
19 #endif
20 #ifndef __STDC_CONSTANT_MACROS
21 # define __STDC_CONSTANT_MACROS
22 #endif
23 
24 #ifndef _WIN32
25 # include <sys/types.h>
26 # include <sys/socket.h>
27 # include <netdb.h>
28 #endif
29 
30 #import "OFStreamSocket.h"
31 
32 #ifdef _WIN32
33 # include <ws2tcpip.h>
34 #endif
35 
36 @class OFTCPSocket;
37 @class OFString;
38 
39 #ifdef OF_HAVE_BLOCKS
40 typedef void (^of_tcpsocket_async_connect_block_t)(OFTCPSocket*, OFException*);
41 typedef BOOL (^of_tcpsocket_async_accept_block_t)(OFTCPSocket*, OFTCPSocket*,
42  OFException*);
43 #endif
44 
52 {
53  BOOL listening;
54  struct sockaddr_storage *sockAddr;
55  socklen_t sockAddrLen;
57  uint16_t SOCKS5Port;
58 }
59 
60 #ifdef OF_HAVE_PROPERTIES
61 @property (readonly, getter=isListening) BOOL listening;
62 @property (copy) OFString *SOCKS5Host;
63 @property uint16_t SOCKS5Port;
64 #endif
65 
71 + (void)setSOCKS5Host: (OFString*)host;
72 
78 + (OFString*)SOCKS5Host;
79 
85 + (void)setSOCKS5Port: (uint16_t)port;
86 
92 + (uint16_t)SOCKS5Port;
93 
99 - (void)setSOCKS5Host: (OFString*)host;
100 
106 - (OFString*)SOCKS5Host;
107 
115 - (void)setSOCKS5Port: (uint16_t)port;
116 
122 - (uint16_t)SOCKS5Port;
123 
130 - (void)connectToHost: (OFString*)host
131  port: (uint16_t)port;
132 
143 - (void)asyncConnectToHost: (OFString*)host
144  port: (uint16_t)port
145  target: (id)target
146  selector: (SEL)selector;
147 
148 #ifdef OF_HAVE_BLOCKS
149 
156 - (void)asyncConnectToHost: (OFString*)host
157  port: (uint16_t)port
158  block: (of_tcpsocket_async_connect_block_t)block;
159 #endif
160 
170 - (uint16_t)bindToHost: (OFString*)host
171  port: (uint16_t)port;
172 
178 - (void)listenWithBackLog: (int)backLog;
179 
183 - (void)listen;
184 
190 - (OFTCPSocket*)accept;
191 
203 - (void)asyncAcceptWithTarget: (id)target
204  selector: (SEL)selector;
205 
206 #ifdef OF_HAVE_BLOCKS
207 
214 - (void)asyncAcceptWithBlock: (of_tcpsocket_async_accept_block_t)block;
215 #endif
216 
222 - (void)setKeepAlivesEnabled: (BOOL)enable;
223 
231 - (OFString*)remoteAddress;
232 
238 - (BOOL)isListening;
239 @end