00001
00014
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
00029
00030
00031
00070
00071
00072
00073
00074
00075 class Socket
00076 {
00077 public:
00078
00079 enum SocketShutdownMode
00080 {
00081 ShutdownReceive = 0x00,
00082 ShutdownSend = 0x01,
00083 ShutdownBoth = 0x02
00084 };
00085
00086
00087 virtual ~Socket();
00088
00089
00090 bool operator==(const Socket& socket) const throw();
00091 bool operator<(const Socket& socket) const throw();
00092
00093
00094 std::ostream& operator<<(std::ostream& stream) const;
00095
00096
00097 bool isOpen() const throw();
00098
00099
00100 void close();
00101
00102
00103 bool isAutoClosing() const throw();
00104
00105
00106 void setToAutoClose(bool autoClose) throw();
00107
00108
00109 void bind(const SocketAddress& address);
00110
00111
00112 void shutdownSocketSends();
00113
00114
00115 void shutdownSocketReceives();
00116
00117
00118 void shutdown();
00119
00120
00121 void shutdown(SocketShutdownMode code);
00122
00123
00124 int getSocketType() const;
00125
00126
00127 SocketAddress getSocketAddress() const;
00128
00129
00130 operator SOCKET() const throw();
00131
00132
00133 SOCKET getDescriptor() const throw();
00134 void setDescriptor(SOCKET socketHandle) throw();
00135
00136
00137 int getReceivingBufferSize() const;
00138 void setReceivingBufferSize(int size);
00139
00140
00141 int getSendingBufferSize() const;
00142 void setSendingBufferSize(int newBufferSize);
00143
00144
00145 int getAndClearErrorStatus();
00146
00147
00148
00149 bool getLingerInformation(int& seconds) const;
00150
00151
00152 void setLingerInformation(bool flag,int seconds);
00153
00154
00155
00156 bool getRouting() const;
00157
00158
00159 void setRouting(bool flag);
00160
00161
00162 bool canLocalAddressesBeReused() const;
00163
00164
00165 void setReuseLocalAddresses(bool flag);
00166 protected:
00167
00168 Socket(SOCKET descriptor);
00169
00170
00171 Socket(int type,int domain,int protocol = 0);
00172
00173
00174 void reset(int type,int domain,int protocol = 0);
00175
00176
00177 void bind(sockaddr* address,int size);
00178
00179
00180 void name(sockaddr* address,int& size) const;
00181
00182
00183
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
00190 bool getBoolOption(int code) const;
00191 void setBoolOption(int code,bool flag);
00192
00193
00194 SOCKET socketHandle;
00195
00196
00197 bool autoClosing;
00198
00199
00200 short flags_;
00201 };
00202
00203
00204 #endif // SOCKET_H_