Socket.h

Go to the documentation of this file.
00001 
00014 // Socket.h: interface for the Socket class
00015 
00016 #ifndef SOCKET_H_
00017 #define SOCKET_H_
00018 
00019 #ifdef _MSC_VER
00020 #pragma once
00021 #endif // MSVC
00022 
00023 #include "SocketIncludes.h"
00024 #include "SocketAddress.h"
00025 
00026 
00028 // SocketOptions
00029 
00030 // enumeration defining the Socket options that can be set
00031 
00070 
00071 // Socket
00072 
00073 // Cntains the behaviors common to all sockets.
00074 
00075 class Socket
00076 {
00077 public:
00078 
00079         enum SocketShutdownMode
00080         {
00081                 ShutdownReceive = 0x00,         // Disable sending on this socket.
00082                 ShutdownSend = 0x01,            // Disable receiving on this socket. 
00083                 ShutdownBoth = 0x02                     // Disable both sending and receiving on this socket
00084         };
00085 
00086         // Destructor is virutal for subclass specific cleanup
00087         virtual ~Socket();
00088 
00089         // Comparison to another Socket
00090         bool operator==(const Socket& socket) const throw();
00091         bool operator<(const Socket& socket) const throw();
00092 
00093         // standard c++ inserter
00094         std::ostream& operator<<(std::ostream& stream) const;
00095 
00096         // Check the open flag
00097         bool isOpen() const throw();
00098 
00099         // Close the Socket
00100         void close();
00101 
00102         // Retrieve whether the Socket will close the native socket on destruction
00103         bool isAutoClosing() const throw();
00104 
00105         // Specify whether or not the destructor will close the native socket
00106         void setToAutoClose(bool autoClose) throw();
00107 
00108         // Associates a local address with a socket
00109         void bind(const SocketAddress& address);
00110 
00111         // Shutsdown socket (with code of ShutdownSend)
00112         void shutdownSocketSends();
00113 
00114         // Shutsdown socket (with code of ShutdownReceive)
00115         void shutdownSocketReceives();
00116 
00117         // Shutsown socket (with code of ShutdownBoth)
00118         void shutdown();
00119 
00120         // Shutdown socket (see SocketShutdown enum)
00121         void shutdown(SocketShutdownMode code);
00122 
00123         // The type of socket (ie, SOCK_STREAM)
00124         int getSocketType() const;
00125 
00126         // Get a SocketAddress object descibing the socket
00127         SocketAddress getSocketAddress() const;
00128 
00129         // Convert the Socket to the native OS socket descriptor
00130         operator SOCKET() const throw();
00131 
00132         // Accessors for the native OS socket descriptor
00133         SOCKET getDescriptor() const throw();
00134         void setDescriptor(SOCKET socketHandle) throw();
00135 
00136         // Accessors for the socket's receiving buffer size.
00137         int getReceivingBufferSize() const;
00138         void setReceivingBufferSize(int size);
00139 
00140         // Accessors for the socket's sending buffer size.
00141         int getSendingBufferSize() const;
00142         void setSendingBufferSize(int newBufferSize);
00143 
00144         // Retrieves error status and clears the status
00145         int getAndClearErrorStatus();
00146 
00147         // Retrieve the length of time the socket will wait for unsent data
00148         // before the socket is closed and whether it is set
00149         bool getLingerInformation(int& seconds) const;
00150 
00151         // Specify the length of time to wait for unsent data before a socket is closed
00152         void setLingerInformation(bool flag,int seconds);
00153 
00154         // Retrieve whether routing is enabled
00155         // The default option is false for the SO_DONTROUTE
00156         bool getRouting() const;
00157 
00158         // Specify whether the socket should use routing
00159         void setRouting(bool flag);
00160 
00161         // Retrieve whether the address to which this socket is bound can be used by others
00162         bool canLocalAddressesBeReused() const;
00163 
00164         // Specify whether the address to which this socket is bound can be used by others
00165         void setReuseLocalAddresses(bool flag);
00166 protected:
00167         // Construct from the native OS socket descriptor
00168         Socket(SOCKET descriptor);
00169 
00170         // Construct a Socket that is bound to a specific service
00171         Socket(int type,int domain,int protocol = 0);
00172 
00173         // Close and reopen the TcpSocket (all active connections will be lost)
00174         void reset(int type,int domain,int protocol = 0);
00175     
00176         // Associates a local address with a socket
00177         void bind(sockaddr* address,int size);
00178 
00179         // Accessor to set the socket name
00180         void name(sockaddr* address,int& size) const;
00181 
00182         // Methods to set varios socket option
00183         // See the berkley Sockets documentation on what all of the options are
00184         int getOption(int code) const;
00185         void getOption(int code,void* storage,int& size) const;
00186         void setOption(int code,int value);     
00187         void setOption(int code,void* storage,int size);
00188 
00189         // Boolean methods for convenience
00190         bool getBoolOption(int code) const;
00191         void setBoolOption(int code,bool flag);
00192 
00193         // Native operating system socket handle
00194         SOCKET socketHandle;
00195 
00196         // Flage to close the socket on destruction
00197         bool autoClosing;
00198 
00199         // State mask for IO
00200         short flags_;
00201 };
00202 
00203 
00204 #endif // SOCKET_H_

Generated on Tue Mar 28 09:10:15 2006 for Simple SOAP by  doxygen 1.4.6