5 // Created by Alexander Strange on Tue Feb 11 2003.
6 // Copyright (c) 2003 __MyCompanyName__. All rights reserved.
9 #import <Foundation/Foundation.h>
10 #import <netinet/in.h>
12 #import "ITByteStream.h"
15 * @header ITInetSocket
16 * @abstract Definitions for the ITInetSocket class
21 * @enum ITInetSocketState
22 * @abstract Possible states of a socket
23 * @constant ITInetSocketConnecting The socket is negotiating a connection.
24 * @constant ITInetSocketListening The socket is a server socket.
25 * @constant ITInetSocketReading The socket is reading data from the other side.
26 * @constant ITInetSocketWriting The socket is sending data to the other side.
27 * @constant ITInetSocketDisconnected The socket does not have a connection.
30 ITInetSocketConnecting,
31 ITInetSocketListening,
34 ITInetSocketDisconnected
38 * @enum ITInetSocketError
39 * @abstract Possible error conditions of a socket
40 * @constant ITInetHostNotFound The host specified does not actually exist.
41 * @constant ITInetConnectionDropped The remote side dropped the connection.
42 * @constant ITInetCouldNotConnect The socket was unable to connect for some reason
46 ITInetConnectionDropped,
53 * @protocol ITInetSocketDelegate
54 * @abstract Delegate methods for ITInetSocket
55 * @discussion ITInetSockets use these methods to communicate with their delegates
57 @protocol ITInetSocketDelegate <ITByteStreamDelegate>
59 * @method dataReceived:
60 * @abstract Alerts the delegate of data.
61 * @discussion The delegate should check [sender readPipe] to get the data.
62 * @param sender The socket that the messages came from.
64 - (oneway void) dataReceived:(ITInetSocket *)sender;
66 * @method errorOccured:during:onSocket:
67 * @abstract Alerts the delegate of an error condition.
68 * @discussion The delegate can try retryCondition.
69 * @param err The error class.
70 * @param state What the socket was doing when the error occured.
71 * @param sender The socket the error occured on.
73 - (oneway void) errorOccured:(ITInetSocketError)err during:(ITInetSocketState)state onSocket:(ITInetSocket*)sender;
75 * @method finishedConnecting:
76 * @abstract Alerts the delegate of a successful connection attempt.
77 * @discussion The delegate should send whatever initial data is required for the protocol (nickname for IRC, etc.)
78 * @param sender The socket that established the connection.
80 - (oneway void) finishedConnecting:(ITInetSocket *)sender;
85 * @abstract An Internet socket class.
86 * @discussion ITInetSocket is an Internet socket class supporting IPv6 and Rendezvous.
88 @interface ITInetSocket : NSObject <ITByteStreamDelegate> {
98 volatile int actionflag;
99 id <ITInetSocketDelegate,NSObject> delegate;
100 struct addrinfo *ai, *ai_cur;
101 ITByteStream *readPipe, *writePipe;
102 ITInetSocketState state;
106 * @method startAutoconnectingToService:delegate:
107 * @abstract Automatically creates sockets whenever a certain type of Rendezvous service appears.
108 * @discussion The auto-created sockets will send finishedConnecting: to the delegate.
109 * @param type The type of Rendezvous service to listen on.
110 * @param d The delegate that the sockets will belong to.
112 +(void)startAutoconnectingToService:(NSString*)type delegate:(id <ITInetSocketDelegate,NSObject>)d;
114 * @method initWithFD:delegate:
115 * @abstract Wraps a socket around an existing socket descriptor.
116 * @discussion The socket will start listening on the descriptor as normal.
117 * @param fd The descriptor.
118 * @param d The delegate for the socket.
120 -(id) initWithFD:(int)fd delegate:(id <ITInetSocketDelegate,NSObject>)d;
122 * @method initWithDelegate:
123 * @abstract Creates a new socket.
124 * @discussion The socket will not be connected to anything.
125 * @param d The delegate of the socket.
127 -(id) initWithDelegate:(id <ITInetSocketDelegate,NSObject>)d;
129 -(id <ITInetSocketDelegate>)delegate;
130 -(unsigned short)bufferSize;
131 -(void)setBufferSize:(unsigned short)bufs;
132 -(void) connectToHost:(NSString*)host onPort:(short)port;
133 -(void) connectToHost:(NSString*)host onNamedPort:(NSString*)port;
134 -(void) connectWithSockaddrArray:(NSArray*)arr;
135 -(ITInetSocketState) state;
136 -(void) retryConnection;