Wrote a simple FIFO queue class
[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
13 enum {
14     ITInetMaxConnections = 36
15 };
16
17 typedef enum {
18     ITInetSocketConnecting,
19     ITInetSocketListening,
20     ITInetSocketReading,
21     ITInetSocketWriting,
22     ITInetSocketDisconnected
23 } ITInetSocketState;
24
25 typedef enum {
26     ITInetHostNotFound,
27     ITInetConnectionDropped,
28     ITInetCouldNotConnect,
29 } ITInetSocketError;
30
31 @protocol ITInetSocketOwner
32 - (void) dataRecieved:(in NSData*)data;
33 - (void) errorOccured:(ITInetSocketError)err during:(ITInetSocketState)state;
34 - (void) finishedConnecting;
35 @end
36
37 @interface ITInetSocket : NSObject {
38     @public
39     int sockfd;
40     int port;
41     id delegate;
42     struct addrinfo *ai;
43     NSData *writeBuffer;
44     ITInetSocketState state;
45 }
46 -(id) initWithFD:(int)fd delegate:(id)d;
47 -(id) initWithDelegate:(id)d;
48
49 -(void) connectToHost:(NSString*)host onPort:(short)port;
50 -(ITInetSocketState) state;
51 @end