More socket work
[ITFoundation.git] / ITInetSocket.h
1 //
2 //  ITInetSocket.h
3 //  ITFoundation
4 //
5 //  Created by Alexander Strange on Tue Feb 11 2003.
6 //  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
7 //
8
9 #import <Foundation/Foundation.h>
10 #import <netinet/in.h>
11 #import <netdb.h>
12 #import "ITByteStream.h"
13
14 enum {
15     ITInetMaxConnections = 36
16 };
17
18 typedef enum {
19     ITInetSocketConnecting,
20     ITInetSocketListening,
21     ITInetSocketReading,
22     ITInetSocketWriting,
23     ITInetSocketDisconnected
24 } ITInetSocketState;
25
26 typedef enum {
27     ITInetHostNotFound,
28     ITInetConnectionDropped,
29     ITInetCouldNotConnect,
30 } ITInetSocketError;
31
32 @protocol ITInetSocketOwner
33 - (void) dataRecieved:(in NSData*)data;
34 - (void) errorOccured:(ITInetSocketError)err during:(ITInetSocketState)state;
35 - (void) finishedConnecting;
36 @end
37
38 @interface ITInetSocket : NSObject {
39     @public
40     int sockfd;
41     int port;
42     id delegate;
43     struct addrinfo *ai;
44     ITByteStream *readPipe, *writePipe;
45     ITInetSocketState state;
46     NSArray *sarr;
47 }
48 +(void)startAutoconnectingToService:(NSString*)type delegate:(id)d;
49 -(id) initWithFD:(int)fd delegate:(id)d;
50 -(id) initWithDelegate:(id)d;
51
52 -(void) connectToHost:(NSString*)host onPort:(short)port;
53 -(void) connectToHost:(NSString*)host onNamedPort:(NSString*)port;
54 -(void) connectWithSockaddrArray:(NSArray*)arr;
55 -(ITInetSocketState) state;
56 @end