EHS Embedded HTTP Server  1.5.1.0
networkabstraction.h
1 /* $Id: networkabstraction.h 120 2012-04-05 22:03:59Z felfert $
2  *
3  * EHS is a library for embedding HTTP(S) support into a C++ application
4  *
5  * Copyright (C) 2004 Zachary J. Hansen
6  *
7  * Code cleanup, new features and bugfixes: Copyright (C) 2010 Fritz Elfert
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1 as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * This can be found in the 'COPYING' file.
23  *
24  */
25 
26 #ifndef NETWORK_ABSTRACTION_H
27 #define NETWORK_ABSTRACTION_H
28 
29 #include <string>
30 #include <cstdlib>
31 
33 
34 #ifdef _WIN32
35 typedef SOCKET ehs_socket_t;
36 #else
37 typedef int ehs_socket_t;
38 #endif
39 
50 
51  public:
52 
57  virtual void RegisterBindHelper(PrivilegedBindHelper *helper) = 0;
58 
63  virtual void SetBindAddress(const char * bindAddress) = 0;
64 
69  virtual std::string GetRemoteAddress() const = 0;
70 
75  virtual int GetRemotePort() const = 0;
76 
81  virtual std::string GetLocalAddress() const = 0;
82 
87  virtual int GetLocalPort() const = 0;
88 
89  DEPRECATED("Use GetRemoteAddress()")
95  virtual std::string GetAddress() const { return GetRemoteAddress(); }
96 
97  DEPRECATED("Use GetRemotePort()")
103  virtual int GetPort() const { return GetRemotePort(); }
104 
110  virtual std::string GetPeer() const = 0;
111 
119  virtual void Init(int port) = 0;
120 
122  virtual ~NetworkAbstraction() { }
123 
128  virtual ehs_socket_t GetFd() const = 0;
129 
136  virtual int Read(void *buf, int bufsize) = 0;
137 
145  virtual int Send(const void *buf, size_t buflen, int flags = 0) = 0;
146 
148  virtual void Close() = 0;
149 
154  virtual NetworkAbstraction *Accept() = 0;
155 
158  virtual bool IsSecure() const = 0;
159 
161  virtual void ThreadCleanup() = 0;
162 };
163 
164 #endif // NETWORK_ABSTRACTION_H
Abstracts different socket types.
virtual void ThreadCleanup()=0
Handles thread specific clean up (used by OpenSSL).
virtual std::string GetAddress() const
Retrieves the peer address.
virtual void SetBindAddress(const char *bindAddress)=0
Sets the bind address of the socket.
virtual std::string GetPeer() const =0
Combination of GetRemoteAddress and GetRemotePort.
virtual ~NetworkAbstraction()
Destructor.
virtual int Send(const void *buf, size_t buflen, int flags=0)=0
Performs a send on the underlying socket.
virtual NetworkAbstraction * Accept()=0
Waits for an incoming connection.
virtual std::string GetLocalAddress() const =0
Retrieves the peer address.
virtual int GetPort() const
Retrieves the peer's port of a connection.
virtual void Init(int port)=0
Initializes a listening socket.
virtual void Close()=0
Closes the underlying socket.
virtual int GetRemotePort() const =0
Retrieves the peer's port of a connection.
virtual void RegisterBindHelper(PrivilegedBindHelper *helper)=0
Registers a PrivilegedBindHelper for use by this instance.
virtual int Read(void *buf, int bufsize)=0
Performs a read from the underlying socket.
virtual int GetLocalPort() const =0
Retrieves the peer's port of a connection.
virtual std::string GetRemoteAddress() const =0
Retrieves the peer address.
virtual bool IsSecure() const =0
Determines, whether the underlying socket is socure.
virtual ehs_socket_t GetFd() const =0
Retrieves the underlying file descriptor.
Helper class for binding of sockets to privileged ports.
Definition: ehs.h:99