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
20 * @constant ITInetMaxConnections
21 * @abstract The maximum number of running ITInetSockets you can have.
22 * @discussion The socket will error during a connection request if you are over the maximum.
26 ITInetMaxConnections = 128
30 * @enum ITInetSocketState
31 * @abstract Possible states of a socket
32 * @constant ITInetSocketConnecting The socket is negotiating a connection.
33 * @constant ITInetSocketListening The socket is a server socket.
34 * @constant ITInetSocketReading The socket is reading data from the other side.
35 * @constant ITInetSocketWriting The socket is sending data to the other side.
36 * @constant ITInetSocketDisconnected The socket does not have a connection.
39 ITInetSocketConnecting,
40 ITInetSocketListening,
43 ITInetSocketDisconnected
47 * @enum ITInetSocketError
48 * @abstract Possible error conditions of a socket
49 * @constant ITInetHostNotFound The host specified does not actually exist.
50 * @constant ITInetConnectionDropped The remote side dropped the connection.
51 * @constant ITInetCouldNotConnect The socket was unable to connect for some reason
55 ITInetConnectionDropped,
62 * @protocol ITInetSocketDelegate
63 * @abstract Delegate methods for ITInetSocket
64 * @discussion ITInetSockets use these methods to communicate with their delegates
66 @protocol ITInetSocketDelegate <ITByteStreamDelegate>
68 * @method dataReceived:
69 * @abstract Alerts the delegate of data.
70 * @discussion The delegate should check [sender readPipe] to get the data.
71 * @param sender The socket that the messages came from.
73 - (void) dataReceived:(ITInetSocket *)sender;
75 * @method errorOccured:during:onSocket:
76 * @abstract Alerts the delegate of an error condition.
77 * @discussion The delegate can try retryCondition.
78 * @param err The error class.
79 * @param state What the socket was doing when the error occured.
80 * @param sender The socket the error occured on.
82 - (void) errorOccured:(ITInetSocketError)err during:(ITInetSocketState)state onSocket:(ITInetSocket*)sender;
84 * @method finishedConnecting:
85 * @abstract Alerts the delegate of a successful connection attempt.
86 * @discussion The delegate should send whatever initial data is required for the protocol (nickname for IRC, etc.)
87 * @param sender The socket that established the connection.
89 - (void) finishedConnecting:(ITInetSocket *)sender;
94 * @abstract An Internet socket class.
95 * @discussion ITInetSocket is an Internet socket class supporting IPv6 and Rendezvous.
97 @interface ITInetSocket : NSObject <ITByteStreamDelegate> {
106 volatile int dieflag;
107 volatile int actionflag;
108 id <ITInetSocketDelegate,NSObject> delegate;
109 struct addrinfo *ai, *ai_cur;
110 ITByteStream *readPipe, *writePipe;
111 ITInetSocketState state;
115 * @method startAutoconnectingToService:delegate:
116 * @abstract Automatically creates sockets whenever a certain type of Rendezvous service appears.
117 * @discussion The auto-created sockets will send finishedConnecting: to the delegate.
118 * @param type The type of Rendezvous service to listen on.
119 * @param d The delegate that the sockets will belong to.
121 +(void)startAutoconnectingToService:(NSString*)type delegate:(id <ITInetSocketDelegate,NSObject>)d;
123 * @method initWithFD:delegate:
124 * @abstract Wraps a socket around an existing socket descriptor.
125 * @discussion The socket will start listening on the descriptor as normal.
126 * @param fd The descriptor.
127 * @param d The delegate for the socket.
129 -(id) initWithFD:(int)fd delegate:(id <ITInetSocketDelegate,NSObject>)d;
131 * @method initWithDelegate:
132 * @abstract Creates a new socket.
133 * @discussion The socket will not be connected to anything.
134 * @param d The delegate of the socket.
136 -(id) initWithDelegate:(id <ITInetSocketDelegate,NSObject>)d;
138 -(id <ITInetSocketDelegate>)delegate;
139 -(unsigned short)bufferSize;
140 -(void)setBufferSize:(unsigned short)bufs;
141 -(void) connectToHost:(NSString*)host onPort:(short)port;
142 -(void) connectToHost:(NSString*)host onNamedPort:(NSString*)port;
143 -(void) connectWithSockaddrArray:(NSArray*)arr;
144 -(ITInetSocketState) state;
145 -(void) retryConnection;