blocxx
SocketBaseImpl.hpp
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright (C) 2005, Vintela, Inc. All rights reserved.
3* Copyright (C) 2006, Novell, Inc. All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7*
8* * Redistributions of source code must retain the above copyright notice,
9* this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of
14* Vintela, Inc.,
15* nor Novell, Inc.,
16* nor the names of its contributors or employees may be used to
17* endorse or promote products derived from this software without
18* specific prior written permission.
19*
20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30* POSSIBILITY OF SUCH DAMAGE.
31*******************************************************************************/
32
33
42#ifndef BLOCXX_SOCKETBASEIMPL_HPP_INCLUDE_GUARD_
43#define BLOCXX_SOCKETBASEIMPL_HPP_INCLUDE_GUARD_
44#include "blocxx/BLOCXX_config.h"
48#include "blocxx/String.hpp"
50#include "blocxx/Types.hpp"
52#include "blocxx/IOIFC.hpp"
53#include "blocxx/Timeout.hpp"
54
55#if defined(BLOCXX_HAVE_ISTREAM) && defined(BLOCXX_HAVE_OSTREAM)
56#include <istream>
57#include <ostream>
58#else
59#include <iostream>
60#endif
61
62// The classes and functions defined in this file are not meant for general
63// use, they are internal implementation details. They may change at any time.
64
65namespace BLOCXX_NAMESPACE
66{
67
68class BLOCXX_COMMON_API SocketBaseImpl : public SelectableIFC, public IOIFC
69{
70public:
73 SocketBaseImpl(const SocketAddress& addr);
74 virtual ~SocketBaseImpl();
75 virtual void connect(const SocketAddress& addr);
76 virtual void disconnect();
77 void setReceiveTimeout(const Timeout& timeout) { m_recvTimeout = timeout; }
78 Timeout getReceiveTimeout() const { return m_recvTimeout; }
79 void setSendTimeout(const Timeout& timeout) { m_sendTimeout = timeout; }
80 Timeout getSendTimeout() const { return m_sendTimeout; }
81 void setConnectTimeout(const Timeout& timeout) { m_connectTimeout = timeout; }
82 Timeout getConnectTimeout() const { return m_connectTimeout; }
83 void setTimeouts(const Timeout& timeout) { m_recvTimeout = m_sendTimeout = m_connectTimeout = timeout; }
84 bool receiveTimeOutExpired() const { return m_recvTimeoutExprd; }
85 int write(const void* dataOut, int dataOutLen,
86 ErrorAction errorAsException = E_RETURN_ON_ERROR);
87 int read(void* dataIn, int dataInLen,
88 ErrorAction errorAsException = E_RETURN_ON_ERROR);
89 virtual bool waitForInput(const Timeout& timeout);
90 bool waitForOutput(const Timeout& timeout);
91 std::istream& getInputStream();
92 std::ostream& getOutputStream();
93 std::iostream& getIOStream();
94 SocketAddress getLocalAddress() const { return m_localAddress; }
95 SocketAddress getPeerAddress() const { return m_peerAddress; }
96 SocketHandle_t getfd() const { return m_sockfd; }
97 Select_t getSelectObj() const;
98 bool isConnected() const { return m_isConnected; }
99 static void setDumpFiles(const String& in, const String& out);
100protected:
101 virtual int readAux(void* dataIn, int dataInLen) = 0;
102 virtual int writeAux(const void* dataOut, int dataOutLen) = 0;
103
108#if defined(BLOCXX_WIN32)
109 HANDLE m_event;
110#endif
111
112private:
113 void fillInetAddrParms();
114#if !defined(BLOCXX_WIN32)
115 void fillUnixAddrParms();
116#endif
118 SocketBaseImpl& operator= (const SocketBaseImpl& arg);
119#if defined(BLOCXX_WIN32)
120 static int waitForEvent(HANDLE event, int secsToTimeout=-1);
121#endif
122
125 std::istream m_in;
126 std::ostream m_out;
127 std::iostream m_inout;
131
134};
136
137} // end namespace BLOCXX_NAMESPACE
138
139#endif
SocketAddress getLocalAddress() const
void setConnectTimeout(const Timeout &timeout)
SocketAddress getPeerAddress() const
void setTimeouts(const Timeout &timeout)
virtual int readAux(void *dataIn, int dataInLen)=0
void setSendTimeout(const Timeout &timeout)
virtual int writeAux(const void *dataOut, int dataOutLen)=0
void setReceiveTimeout(const Timeout &timeout)
SocketBaseImpl(const SocketBaseImpl &arg)
This String class is an abstract data type that represents as NULL terminated string of characters.
Definition String.hpp:67
A timeout can be absolute, which means that it will happen at the specified DateTime.
Definition Timeout.hpp:56
Taken from RFC 1321.
BLOCXX_EXPORT_TEMPLATE(BLOCXX_COMMON_API, Array, Bool)