Back to index

lightning-sunbird  0.9+nobinonly
GUSIMTInet.h
Go to the documentation of this file.
00001 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
00002 // % Project  :      GUSI                        -      Grand Unified Socket Interface                    
00003 // % File            :      GUSIMTInet.nw        -      Common routines for MacTCP                   
00004 // % Author   :      Matthias Neeracher                                           
00005 // % Language :      C++                                                        
00006 // %                                                                       
00007 // % $Log: GUSIMTInet.h,v $
00008 // % Revision 1.1  2001/03/11 22:35:57  sgehani%netscape.com
00009 // % First Checked In.
00010 // %                                               
00011 // % Revision 1.14  2000/10/16 04:34:23  neeri                             
00012 // % Releasing 2.1.2                                                       
00013 // %                                                                       
00014 // % Revision 1.13  2000/05/23 07:03:25  neeri                             
00015 // % Improve formatting                                                    
00016 // %                                                                       
00017 // % Revision 1.12  1999/08/26 05:45:04  neeri                             
00018 // % Fixes for literate edition of source code                             
00019 // %                                                                       
00020 // % Revision 1.11  1999/08/02 07:02:43  neeri                             
00021 // % Support for asynchronous errors and other socket options              
00022 // %                                                                       
00023 // % Revision 1.10  1999/06/30 07:42:06  neeri                             
00024 // % Getting ready to release 2.0b3                                        
00025 // %                                                                       
00026 // % Revision 1.9  1999/05/29 06:26:43  neeri                              
00027 // % Fixed header guards                                                   
00028 // %                                                                       
00029 // % Revision 1.8  1999/04/29 05:33:19  neeri                              
00030 // % Fix fcntl prototype                                                   
00031 // %                                                                       
00032 // % Revision 1.7  1999/03/17 09:05:08  neeri                              
00033 // % Added GUSITimer, expanded docs                                        
00034 // %                                                                       
00035 // % Revision 1.6  1998/10/25 11:57:35  neeri                              
00036 // % Ready to release 2.0a3                                                
00037 // %                                                                       
00038 // % Revision 1.5  1998/10/11 16:45:16  neeri                              
00039 // % Ready to release 2.0a2                                                
00040 // %                                                                       
00041 // % Revision 1.4  1998/02/11 12:57:12  neeri                              
00042 // % PowerPC Build                                                         
00043 // %                                                                       
00044 // % Revision 1.3  1998/01/25 20:53:55  neeri                              
00045 // % Engine implemented, except for signals & scheduling                   
00046 // %                                                                       
00047 // % Revision 1.2  1996/12/22 19:57:56  neeri                              
00048 // % TCP streams work                                                      
00049 // %                                                                       
00050 // % Revision 1.1  1996/12/16 02:12:40  neeri                              
00051 // % TCP Sockets sort of work                                              
00052 // %                                                                       
00053 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
00054 //                                                                         
00055 // \chapter{Basic MacTCP code}                                             
00056 //                                                                         
00057 // A [[GUSIMTInetSocket]] defines the infrastructure shared between        
00058 // MacTCP TCP and UDP sockets.                                             
00059 //                                                                         
00060 // <GUSIMTInet.h>=                                                         
00061 #ifndef _GUSIMTInet_
00062 #define _GUSIMTInet_
00063 
00064 #ifdef GUSI_SOURCE
00065 
00066 #include <sys/cdefs.h>
00067 
00068 __BEGIN_DECLS
00069 // <Definition of [[GUSIwithMTInetSockets]]>=                              
00070 void GUSIwithMTInetSockets();
00071 __END_DECLS
00072 
00073 #ifdef GUSI_INTERNAL
00074 
00075 #include "GUSISocket.h"
00076 #include "GUSISocketMixins.h"
00077 
00078 #include <netinet/in.h>
00079 #include <MacTCP.h>
00080 
00081 // \section{Definition of [[GUSIMTInetSocket]]}                            
00082 //                                                                         
00083 // MacTCP related sockets are buffered, have a standard state model, and can be
00084 // nonblocking.                                                            
00085 //                                                                         
00086 // <Definition of class [[GUSIMTInetSocket]]>=                             
00087 class GUSIMTInetSocket : 
00088        public               GUSISocket, 
00089        protected     GUSISMBlocking,
00090        protected     GUSISMState,
00091        protected     GUSISMInputBuffer,
00092        protected     GUSISMOutputBuffer,
00093        protected     GUSISMAsyncError
00094 {
00095 public:
00096        GUSIMTInetSocket();
00097        // [[bind]] for MacTCP sockets has the fatal flaw that it is totally unable to
00098  // reserve a socket.                                                       
00099  //                                                                         
00100  // <Overridden member functions for [[GUSIMTInetSocket]]>=                 
00101  virtual int bind(void * addr, socklen_t namelen);
00102  // [[getsockname]] and [[getpeername]] return the stored values.           
00103  //                                                                         
00104  // <Overridden member functions for [[GUSIMTInetSocket]]>=                 
00105  virtual int getsockname(void * addr, socklen_t * namelen);
00106  virtual int getpeername(void * addr, socklen_t * namelen);
00107  // [[shutdown]] just delegates to [[GUSISMState]].                         
00108  //                                                                         
00109  // <Overridden member functions for [[GUSIMTInetSocket]]>=                 
00110  virtual int shutdown(int how);
00111  // [[fcntl]] handles the blocking support.                                 
00112  //                                                                         
00113  // <Overridden member functions for [[GUSIMTInetSocket]]>=                 
00114  virtual int fcntl(int cmd, va_list arg);
00115  // [[ioctl]] deals with blocking support and with [[FIONREAD]].            
00116  //                                                                         
00117  // <Overridden member functions for [[GUSIMTInetSocket]]>=                 
00118  virtual int ioctl(unsigned int request, va_list arg);
00119  // [[getsockopt]] and [[setsockopt]] are available for setting buffer sizes and 
00120  // getting asynchronous errors.                                            
00121  //                                                                         
00122  // <Overridden member functions for [[GUSIMTInetSocket]]>=                 
00123  virtual int getsockopt(int level, int optname, void *optval, socklen_t * optlen);
00124  // <Overridden member functions for [[GUSIMTInetSocket]]>=                 
00125  virtual int setsockopt(int level, int optname, void *optval, socklen_t optlen);
00126  // MacTCP sockets implement socket style calls.                            
00127  //                                                                         
00128  // <Overridden member functions for [[GUSIMTInetSocket]]>=                 
00129  virtual bool Supports(ConfigOption config);
00130        // MacTCP I/O calls communicate by means of read and write data structures,
00131  // of which we need only the most primitive variants.                      
00132  //                                                                         
00133  // <Definition of classes [[MiniWDS]] and [[MidiWDS]]>=                    
00134  #if PRAGMA_STRUCT_ALIGN
00135        #pragma options align=mac68k
00136  #endif
00137  class MiniWDS {
00138  public:
00139        u_short       fLength;
00140        char *        fDataPtr;
00141        u_short fZero;
00142 
00143        MiniWDS() : fZero(0)        {}
00144        Ptr operator &()                   {      return (Ptr)this;    }
00145  };
00146  class MidiWDS {
00147  public:
00148        u_short       fLength;
00149        char *        fDataPtr;
00150        u_short       fLength2;
00151        char *        fDataPtr2;
00152        u_short fZero;
00153 
00154        MidiWDS() : fZero(0)        {}
00155        Ptr operator &()                   {      return (Ptr)this;    }
00156  };
00157  #if PRAGMA_STRUCT_ALIGN
00158        #pragma options align=reset
00159  #endif
00160        // The only other interesting bit in the interface is the driver management, which
00161  // arranges to open the MacTCP driver and domain name resolver at most once,
00162  // as late as possible in the program (If you open some SLIP or PPP drivers 
00163  // before the Toolbox is initialized, you'll wish you'd curled up by the fireside
00164  // with a nice Lovecraft novel instead). [[Driver]] returns the driver reference
00165  // number of the MacTCP driver. [[HostAddr]] returns our host's IP address.
00166  //                                                                         
00167  // <MacTCP driver management>=                                             
00168  static short Driver();
00169  static u_long       HostAddr();
00170 protected:
00171        // All MacTCP related sockets need a [[StreamPtr]]; they store their own and 
00172  // their peer's address away, and the save errors reported at interrupt time
00173  // in an [[fAsyncError]] field.                                            
00174  //                                                                         
00175  // <Data members for [[GUSIMTInetSocket]]>=                                
00176  StreamPtr    fStream;
00177  sockaddr_in  fSockAddr;
00178  sockaddr_in  fPeerAddr;
00179  // \section{Implementation of [[GUSIMTInetSocket]]}                        
00180  //                                                                         
00181  // [[Driver]] preserves error status in an [[OSErr]]                       
00182  // variable, initially [[1]] to convey unresolvedness.                     
00183  //                                                                         
00184  // <Data members for [[GUSIMTInetSocket]]>=                                
00185  static short sDrvrRefNum;
00186  static OSErr sDrvrState;
00187  static u_long       sHostAddress;
00188 };
00189 
00190 #endif /* GUSI_INTERNAL */
00191 
00192 #endif /* GUSI_SOURCE */
00193 
00194 #endif /* _GUSIMTInet_ */