Wired Networking  2.0
Objective-C implementation of the Wired 2.0 protocol
WISocket.h
00001 /* $Id$ */
00002 
00003 /*
00004  *  Copyright (c) 2006-2009 Axel Andersson
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *  1. Redistributions of source code must retain the above copyright
00011  *     notice, this list of conditions and the following disclaimer.
00012  *  2. Redistributions in binary form must reproduce the above copyright
00013  *     notice, this list of conditions and the following disclaimer in the
00014  *     documentation and/or other materials provided with the distribution.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00017  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
00020  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00023  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00024  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00025  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 @interface WISocketTLS : WIObject {
00030                 wi_socket_tls_t                                                 *_tls;
00031 }
00032 
00033 + (WISocketTLS *)socketTLSForClient;
00034 
00035 - (wi_socket_tls_t *)TLS;
00036 
00037 - (void)setSSLCiphers:(NSString *)ciphers;
00038 
00039 @end
00040 
00041 
00042 #define WISocketBufferSize                                      WI_SOCKET_BUFFER_SIZE
00043 
00044 
00045 enum _WISocketType {
00046                 WISocketTCP                                                                                     = WI_SOCKET_TCP,
00047                 WISocketUDP                                                                                     = WI_SOCKET_UDP
00048 };
00049 typedef enum _WISocketType                                      WISocketType;
00050 
00051 
00052 enum _WISocketDirection {
00053                 WISocketRead                                                                    = WI_SOCKET_READ,
00054                 WISocketWrite                                                                   = WI_SOCKET_WRITE
00055 };
00056 typedef enum _WISocketDirection                 WISocketDirection;
00057 
00058 
00059 enum _WISocketEvent {
00060                 WISocketEventNone                                                               = kCFSocketNoCallBack,
00061                 WISocketEventRead                                                               = kCFSocketReadCallBack,
00062                 WISocketEventWrite                                                              = kCFSocketWriteCallBack
00063 };
00064 typedef enum _WISocketEvent                                     WISocketEvent;
00065 
00066 
00067 @protocol WISocketDelegate;
00068 @class WIAddress, WIError;
00069 
00070 @interface WISocket : WIObject {
00071                 id <WISocketDelegate>                                           delegate;
00072                 
00073                 wi_socket_t                                                                                     *_socket;
00074                 
00075                 WIAddress                                                                                       *_address;
00076                 
00077                 NSMutableString                                                                 *_buffer;
00078                 
00079                 WIError                                                                                                         *_readTimeoutError;
00080 
00081                 CFSocketRef                                                                                     _socketRef;
00082                 CFRunLoopSourceRef                                                              _sourceRef;
00083 }
00084 
00085 + (WISocket *)socketWithAddress:(WIAddress *)address type:(WISocketType)type;
00086 + (WISocket *)socketWithFileDescriptor:(int)sd;
00087 
00088 - (id)initWithAddress:(WIAddress *)address type:(WISocketType)type;
00089 - (id)initWithFileDescriptor:(int)sd;
00090 
00091 - (WIAddress *)address;
00092 - (int)fileDescriptor;
00093 - (void *)SSL;
00094 - (wi_socket_t *)socket;
00095 - (NSString *)cipherVersion;
00096 - (NSString *)cipherName;
00097 - (NSUInteger)cipherBits;
00098 - (NSString *)certificateName;
00099 - (NSUInteger)certificateBits;
00100 - (NSString *)certificateHostname;
00101 
00102 - (void)setDelegate:(id <WISocketDelegate>)delegate;
00103 - (id <WISocketDelegate>)delegate;
00104 - (void)setPort:(NSUInteger)port;
00105 - (NSUInteger)port;
00106 - (void)setDirection:(WISocketDirection)direction;
00107 - (WISocketDirection)direction;
00108 - (void)setBlocking:(BOOL)blocking;
00109 - (BOOL)blocking;
00110 - (void)setInteractive:(BOOL)interactive;
00111 - (BOOL)interactive;
00112 
00113 - (BOOL)waitWithTimeout:(NSTimeInterval)timeout;
00114 
00115 - (BOOL)connectWithTimeout:(NSTimeInterval)timeout error:(WIError **)error;
00116 - (BOOL)connectWithTLS:(WISocketTLS *)tls timeout:(NSTimeInterval)timeout error:(WIError **)error;
00117 - (BOOL)listenWithError:(WIError **)error;
00118 - (WISocket *)acceptWithTimeout:(NSTimeInterval)timeout error:(WIError **)error;
00119 - (void)close;
00120 
00121 - (BOOL)writeString:(NSString *)string encoding:(NSStringEncoding)encoding timeout:(NSTimeInterval)timeout error:(WIError **)error;
00122 
00123 - (NSString *)readStringOfLength:(NSUInteger)length encoding:(NSStringEncoding)encoding timeout:(NSTimeInterval)timeout error:(WIError **)error;
00124 - (NSString *)readStringUpToString:(NSString *)separator encoding:(NSStringEncoding)encoding timeout:(NSTimeInterval)timeout error:(WIError **)error;
00125 
00126 - (void)scheduleInRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)mode;
00127 - (void)removeFromRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)mode;
00128 
00129 @end
00130 
00131 
00132 @protocol WISocketDelegate <NSObject>
00133 
00134 - (void)socket:(WISocket *)socket handleEvent:(WISocketEvent)event;
00135 
00136 @end
 All Classes