FrameWorks/OmniNetworking.framework/Versions/A/Headers/ONInternetSocket.h

00001 // Copyright 1997-2005 Omni Development, Inc.  All rights reserved.
00002 //
00003 // This software may only be used and reproduced according to the
00004 // terms in the file OmniSourceLicense.html, which should be
00005 // distributed with this project and can also be found at
00006 // <http://www.omnigroup.com/developer/sourcecode/sourcelicense/>.
00007 //
00008 // $Header: svn+ssh://source.omnigroup.com/Source/svn/Omni/tags/SourceRelease_2005-11-18/OmniGroup/Frameworks/OmniNetworking/ONInternetSocket.h 68913 2005-10-03 19:36:19Z kc $
00009 
00010 #import "ONSocket.h"
00011 #import "ONInterface.h"
00012 #import <pthread.h>
00013 
00014 @class ONHost;
00015 @class ONHostAddress;
00016 @class ONPortAddress;
00017 @class ONServiceEntry;
00018 
00019 #import <Foundation/NSDate.h> // For NSTimeInterval
00020 
00021 @interface ONInternetSocket : ONSocket
00022 {
00023     /* The underlying BSD socket descriptor, or -1 */
00024     int socketFD;
00025 
00026     /* A mutex which protects changes to socketFD and other ivars */
00027     pthread_mutex_t socketLock;
00028 
00029     /* protocol family of socket, if socketFD is not -1 */
00030     short socketPF;
00031         
00032     /* Cached attributes of the endpoints of the socket connection, if any */
00033     ONPortAddress *localAddress;
00034     ONPortAddress *remoteAddress;
00035     ONHost *remoteHost;
00036     
00037     struct {
00038         unsigned int listening:1;
00039         unsigned int connected:1;
00040         unsigned int userAbort:1;
00041         unsigned int shouldNotCloseFD:1;
00042         
00043         /* These flags track the options we've set on the socket, so we can set them again if  we have to close and recreate the socket in a new protocol family */
00044         unsigned int nonBlocking:1;
00045         unsigned int allowAddressReuse:1;
00046         unsigned int allowBroadcast:1;
00047     } flags;
00048 
00049     int requestedLocalPort;  // 0=any port, -1=not bound to a local address yet
00050 }
00051 
00052 + (int)socketType;
00053 + (int)ipProtocol;
00054 
00055 + (ONInternetSocket *)socket;
00056 
00057 + (ONInternetSocket *)socketWithConnectedFileDescriptor:(int)fd shouldClose:(BOOL)closeOnDealloc;
00058 
00059 - (void)setLocalPortNumber;
00060     // Sets the local port to any available local port number
00061 
00062 - (void)setLocalPortNumber:(int)port;
00063     // Sets the local port that will be used when sending and receiving messages.
00064 
00065 - (void)setLocalPortNumber:(int)port allowingAddressReuse:(BOOL)reuse;
00066     // Sets the local port that will be used when sending and receiving messages.  If reuse is true, other sockets will be allowed to use the same local port.
00067 
00068 - (int)addressFamily;
00069     // Returns the socket's current address family, or AF_UNSPEC if none. Note that an ONInternetSocket, unlike the underlying BSD socket, can change its address family.
00070 - (void)setAddressFamily:(int)newAddressFamily;
00071     // Sets the address family of the receiver (typically to AF_INET or AF_INET6). A subsequent -connect... call might change the socket's address family to match the family of the remote address. -setAddressFamily: can be used before a call to -setLocalPortNumber in order to cause the socket to bind to an address in a family other than AF_INET.
00072     
00073 - (ONPortAddress *)localAddress;
00074 - (unsigned short int)localAddressPort;
00075 
00076 - (ONHost *)remoteAddressHost;
00077 - (ONPortAddress *)remoteAddress;
00078 - (unsigned short int)remoteAddressPort;
00079 
00080 - (ONInterface *)localInterface;
00081 
00082 - (void)connectToPortAddress:(ONPortAddress *)portAddress;
00083 - (void)connectToHost:(ONHost *)host serviceEntry:(ONServiceEntry *)service;
00084 - (void)connectToHost:(ONHost *)host port:(unsigned short int)port;
00085 - (void)connectToAddress:(ONHostAddress *)hostAddress port:(unsigned short int)port;
00086 - (void)connectToAddressFromArray:(NSArray *)portAddresses;
00087     // This attempts to connect to one of a list of addresses, e.g. for a multi-homed host or for a service with multiple MX or SRV records. Most of the -connectTo... methods invoke -connectToAddressFromArray: to do the actual work.
00088 
00089 - (void)setNonBlocking:(BOOL)shouldBeNonBlocking;
00090 - (BOOL)waitForInputWithTimeout:(NSTimeInterval)timeout;
00091 
00092 - (void)setAllowsBroadcast:(BOOL)shouldAllowBroadcast;
00093 // This really only makes sense for UDP and Multicast sockets
00094 
00095 - (int)socketFD;
00096 
00097 - (BOOL)isConnected;
00098 - (BOOL)didAbort;
00099 
00100 @end
00101 
00102 /* These are here in case they become nontrivial someday */
00103 static inline int ONProtocolFamilyForAddressFamily(int addressFamily)
00104 {
00105     return addressFamily;
00106 }
00107 
00108 static inline int ONAddressFamilyForProtocolFamily(int protocolFamily)
00109 {
00110     return protocolFamily;
00111 }
00112 
00113 
00114 #import "FrameworkDefines.h"
00115 
00116 // Exceptions which may be raised by this class
00117 OmniNetworking_EXTERN NSString *ONInternetSocketBindFailedExceptionName;
00118 OmniNetworking_EXTERN NSString *ONInternetSocketReuseSelectionFailedExceptionName;
00119 OmniNetworking_EXTERN NSString *ONInternetSocketBroadcastSelectionFailedExceptionName;
00120 OmniNetworking_EXTERN NSString *ONInternetSocketConnectFailedExceptionName;
00121 OmniNetworking_EXTERN NSString *ONInternetSocketConnectTemporarilyFailedExceptionName;
00122 OmniNetworking_EXTERN NSString *ONInternetSocketGetNameFailedExceptionName;
00123 OmniNetworking_EXTERN NSString *ONInternetSocketNotConnectedExceptionName;
00124 OmniNetworking_EXTERN NSString *ONInternetSocketReadFailedExceptionName;
00125 OmniNetworking_EXTERN NSString *ONInternetSocketSetOptionFailedExceptionName;
00126 OmniNetworking_EXTERN NSString *ONInternetSocketUserAbortExceptionName;
00127 OmniNetworking_EXTERN NSString *ONInternetSocketWriteFailedExceptionName;
00128 OmniNetworking_EXTERN NSString *ONInternetSocketCloseFailedExceptionName;

Generated on Sat Aug 26 21:14:14 2006 for MacTrek by  doxygen 1.4.7