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 <DataReciever>
59 * @method errorOccured:during:onSocket:
60 * @abstract Alerts the delegate of an error condition.
61 * @discussion The delegate can try retryCondition.
62 * @param err The error class.
63 * @param state What the socket was doing when the error occured.
64 * @param sender The socket the error occured on.
66 - (oneway void) errorOccured:(ITInetSocketError)err during:(ITInetSocketState)state onSocket:(ITInetSocket*)sender;
68 * @method finishedConnecting:
69 * @abstract Alerts the delegate of a successful connection attempt.
70 * @discussion The delegate should send whatever initial data is required for the protocol (nickname for IRC, etc.)
71 * @param sender The socket that established the connection.
73 - (oneway void) finishedConnecting:(ITInetSocket *)sender;
78 * @abstract An Internet socket class.
79 * @discussion ITInetSocket is an Internet socket class supporting IPv6 and Rendezvous.
81 @interface ITInetSocket : NSObject <DataReciever> {
87 volatile int actionflag;
88 id <ITInetSocketDelegate> delegate;
89 struct addrinfo *ai, *ai_cur;
90 ITByteStream *readPipe, *writePipe;
91 ITInetSocketState state;
95 * @method startAutoconnectingToService:delegate:
96 * @abstract Automatically creates sockets whenever a certain type of Rendezvous service appears.
97 * @discussion The auto-created sockets will send finishedConnecting: to the delegate.
98 * @param type The type of Rendezvous service to listen on.
99 * @param d The delegate that the sockets will belong to.
101 +(void)startAutoconnectingToService:(NSString*)type delegate:(id <ITInetSocketDelegate>)d;
103 * @method initWithFD:delegate:
104 * @abstract Wraps a socket around an existing socket descriptor.
105 * @discussion The socket will start listening on the descriptor as normal.
106 * @param fd The descriptor.
107 * @param d The delegate for the socket.
109 -(id) initWithFD:(int)fd delegate:(id <ITInetSocketDelegate>)d;
111 * @method initWithDelegate:
112 * @abstract Creates a new socket.
113 * @discussion The socket will not be connected to anything.
114 * @param d The delegate of the socket.
116 -(id) initWithDelegate:(id <ITInetSocketDelegate>)d;
118 -(id <ITInetSocketDelegate>)delegate;
119 -(unsigned short)bufferSize;
120 -(void)setBufferSize:(unsigned short)bufs;
121 -(void) connectToHost:(NSString*)host onPort:(short)port;
122 -(void) connectToHost:(NSString*)host onNamedPort:(NSString*)port;
123 -(void) connectWithSockaddrArray:(NSArray*)arr;
124 -(ITInetSocketState) state;
125 -(void) retryConnection;
127 -(ITByteStream *)readPipe;
128 -(ITByteStream *)writePipe;