Thread safety in byte streams
[ITFoundation.git] / ITInetSocket.h
index 367c31e..aad407f 100755 (executable)
@@ -7,10 +7,45 @@
 //
 
 #import <Foundation/Foundation.h>
 //
 
 #import <Foundation/Foundation.h>
+#import <netinet/in.h>
+#import <netdb.h>
 
 
+enum {
+    ITInetMaxConnections = 36
+};
 
 
-@interface ITInetSocket : NSObject {
+typedef enum {
+    ITInetSocketConnecting,
+    ITInetSocketListening,
+    ITInetSocketReading,
+    ITInetSocketWriting,
+    ITInetSocketDisconnected
+} ITInetSocketState;
+
+typedef enum {
+    ITInetHostNotFound,
+    ITInetConnectionDropped,
+    ITInetCouldNotConnect,
+} ITInetSocketError;
+
+@protocol ITInetSocketOwner
+- (void) dataRecieved:(in NSData*)data;
+- (void) errorOccured:(ITInetSocketError)err during:(ITInetSocketState)state;
+- (void) finishedConnecting;
+@end
 
 
+@interface ITInetSocket : NSObject {
+    @public
+    int sockfd;
+    int port;
+    id delegate;
+    struct addrinfo *ai;
+    NSData *writeBuffer;
+    ITInetSocketState state;
 }
 }
--(id)initWithFD:(int)fd delegate:(id)d;
+-(id) initWithFD:(int)fd delegate:(id)d;
+-(id) initWithDelegate:(id)d;
+
+-(void) connectToHost:(NSString*)host onPort:(short)port;
+-(ITInetSocketState) state;
 @end
 @end