00001 00014 // ConnectableSocket.h -- interface for the ConnectableSocket class 00015 00016 #ifndef CONNECTABLESOCKET_H_ 00017 #define CONNECTABLESOCKET_H_ 00018 00019 #ifdef _MSC_VER 00020 #pragma once 00021 #endif // MSVC 00022 00023 #include "Socket.h" 00024 00026 // ConnectableSocket 00027 00028 // Contains the behaviors common to all connectable sockets. 00029 00035 class ConnectableSocket : public Socket 00036 { 00037 public: 00038 // Socket state mask 00039 enum IoState 00040 { 00041 state_eof = 0x01, 00042 state_failed = 0x02, 00043 state_raise_event = 0x04 00044 }; 00045 00046 // standard c++ iostream inserter 00047 std::ostream& operator<<( std::ostream& stream) const; 00048 00049 // Connecting. 00050 void connectTo(const SocketAddress& address); 00051 00052 // Read from the socket stream into the buffer 00053 int read( void* buffer, int bytes); 00054 00055 // Write the buffer to the socket stream. 00056 int write(const void* buffer, int bytes); 00057 00058 // End of stream verification. 00059 bool isEof() const; 00060 bool isOk() const; 00061 bool isGood() const; 00062 00063 00064 // Accessors for end of stream notification 00065 bool eventOnEof() const; 00066 void eventOnEof(bool flag); 00067 00068 // Clears the socket 00069 void clear(); 00070 00071 // Receive from the socket using the specified buffer 00072 int receiveFrom(SocketAddress& address,void* buffer,int bytes); 00073 00074 // Peer address. 00075 SocketAddress peerAddress() const; 00076 00077 // Testing. 00078 bool isConnected() const; 00079 00080 protected: 00081 // Hidden constructors 00082 ConnectableSocket(SOCKET socketHandle); 00083 ConnectableSocket(int type,int domain,int protocol = 0); 00084 00085 // Connects the socket to the address 00086 void connectTo(sockaddr* address,int size); 00087 00088 // Retrieve whether the state is equal to the passed in state mask 00089 bool getFlags(short mask) const; 00090 }; 00091 00092 00093 #endif // CONNECTABLESOCKET_H_