00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00039 #ifndef OW_SOCKETBASEIMPL_HPP_INCLUDE_GUARD_
00040 #define OW_SOCKETBASEIMPL_HPP_INCLUDE_GUARD_
00041 #include "OW_config.h"
00042 #include "OW_SelectableIFC.hpp"
00043 #include "OW_IntrusiveReference.hpp"
00044 #include "OW_SocketException.hpp"
00045 #include "OW_String.hpp"
00046 #include "OW_SocketAddress.hpp"
00047 #include "OW_Types.hpp"
00048 #include "OW_SocketStreamBuffer.hpp"
00049 #include "OW_IOIFC.hpp"
00050 #if defined(OW_HAVE_ISTREAM) && defined(OW_HAVE_OSTREAM)
00051 #include <istream>
00052 #include <ostream>
00053 #else
00054 #include <iostream>
00055 #endif
00056
00057
00058
00059
00060 namespace OW_NAMESPACE
00061 {
00062
00063 class OW_COMMON_API SocketBaseImpl : public SelectableIFC, public IOIFC
00064 {
00065 public:
00066 SocketBaseImpl();
00067 SocketBaseImpl(SocketHandle_t fd, SocketAddress::AddressType addrType);
00068 SocketBaseImpl(const SocketAddress& addr);
00069 virtual ~SocketBaseImpl();
00070 virtual void connect(const SocketAddress& addr);
00071 virtual void disconnect();
00072 void setReceiveTimeout(int seconds) { m_recvTimeout = seconds; }
00073 int getReceiveTimeout() const { return m_recvTimeout; }
00074 void setSendTimeout(int seconds) { m_sendTimeout = seconds; }
00075 int getSendTimeout() const { return m_sendTimeout; }
00076 void setConnectTimeout(int seconds) { m_connectTimeout = seconds; }
00077 int getConnectTimeout() const { return m_connectTimeout; }
00078 void setTimeouts(int seconds) { m_recvTimeout = m_sendTimeout = m_connectTimeout = seconds; }
00079 bool receiveTimeOutExpired() const { return m_recvTimeoutExprd; }
00080 int write(const void* dataOut, int dataOutLen,
00081 bool errorAsException=false);
00082 int read(void* dataIn, int dataInLen,
00083 bool errorAsException=false);
00084 virtual bool waitForInput(int timeOutSecs=-1);
00085 bool waitForOutput(int timeOutSecs=-1);
00086 std::istream& getInputStream();
00087 std::ostream& getOutputStream();
00088 std::iostream& getIOStream();
00089 SocketAddress getLocalAddress() const { return m_localAddress; }
00090 SocketAddress getPeerAddress() const { return m_peerAddress; }
00091 SocketHandle_t getfd() const { return m_sockfd; }
00092 Select_t getSelectObj() const;
00093 bool isConnected() const { return m_isConnected; }
00094 static void setDumpFiles(const String& in, const String& out);
00095 protected:
00096 virtual int readAux(void* dataIn, int dataInLen) = 0;
00097 virtual int writeAux(const void* dataOut, int dataOutLen) = 0;
00098
00099 bool m_isConnected;
00100 SocketHandle_t m_sockfd;
00101 SocketAddress m_localAddress;
00102 SocketAddress m_peerAddress;
00103 #if defined(OW_WIN32)
00104 HANDLE m_event;
00105 #endif
00106
00107 private:
00108 void fillInetAddrParms();
00109 #if !defined(OW_WIN32)
00110 void fillUnixAddrParms();
00111 #endif
00112 SocketBaseImpl(const SocketBaseImpl& arg);
00113 SocketBaseImpl& operator= (const SocketBaseImpl& arg);
00114 #if defined(OW_WIN32)
00115 static int waitForEvent(HANDLE event, int secsToTimeout=-1);
00116 #endif
00117
00118 bool m_recvTimeoutExprd;
00119 SocketStreamBuffer m_streamBuf;
00120 std::istream m_in;
00121 std::ostream m_out;
00122 std::iostream m_inout;
00123 int m_recvTimeout;
00124 int m_sendTimeout;
00125 int m_connectTimeout;
00126
00127 static String m_traceFileOut;
00128 static String m_traceFileIn;
00129 };
00130 OW_EXPORT_TEMPLATE(OW_COMMON_API, IntrusiveReference, SocketBaseImpl);
00131
00132 }
00133
00134 #endif