EHS Embedded HTTP Server  1.5.0.132
networkabstraction.h
00001 /* $Id: networkabstraction.h 120 2012-04-05 22:03:59Z felfert $
00002  *
00003  * EHS is a library for embedding HTTP(S) support into a C++ application
00004  *
00005  * Copyright (C) 2004 Zachary J. Hansen
00006  *
00007  * Code cleanup, new features and bugfixes: Copyright (C) 2010 Fritz Elfert
00008  *
00009  *    This library is free software; you can redistribute it and/or
00010  *    modify it under the terms of the GNU Lesser General Public
00011  *    License version 2.1 as published by the Free Software Foundation;
00012  *
00013  *    This library is distributed in the hope that it will be useful,
00014  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *    Lesser General Public License for more details.
00017  *
00018  *    You should have received a copy of the GNU Lesser General Public
00019  *    License along with this library; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  *    This can be found in the 'COPYING' file.
00023  *
00024  */
00025 
00026 #ifndef NETWORK_ABSTRACTION_H
00027 #define NETWORK_ABSTRACTION_H
00028 
00029 #include <string>
00030 #include <cstdlib>
00031 
00032 class PrivilegedBindHelper;
00033 
00034 #ifdef _WIN32
00035 typedef SOCKET ehs_socket_t;
00036 #else
00037 typedef int ehs_socket_t;
00038 #endif
00039 
00049 class NetworkAbstraction {
00050 
00051     public:
00052 
00057         virtual void RegisterBindHelper(PrivilegedBindHelper *helper) = 0;
00058 
00063         virtual void SetBindAddress(const char * bindAddress) = 0;
00064 
00069         virtual std::string GetRemoteAddress() const = 0;
00070 
00075         virtual int GetRemotePort() const = 0;
00076 
00081         virtual std::string GetLocalAddress() const = 0;
00082 
00087         virtual int GetLocalPort() const = 0;
00088 
00089         DEPRECATED("Use GetRemoteAddress()")
00095             virtual std::string GetAddress() const { return GetRemoteAddress(); }
00096 
00097         DEPRECATED("Use GetRemotePort()")
00103             virtual int GetPort() const { return GetRemotePort(); }
00104 
00110         virtual std::string GetPeer() const = 0;
00111 
00119         virtual void Init(int port) = 0;
00120 
00122         virtual ~NetworkAbstraction() { }
00123 
00128         virtual ehs_socket_t GetFd() const = 0;
00129 
00136         virtual int Read(void *buf, int bufsize) = 0;
00137 
00145         virtual int Send(const void *buf, size_t buflen, int flags = 0) = 0;
00146 
00148         virtual void Close() = 0;
00149 
00154         virtual NetworkAbstraction *Accept() = 0;
00155 
00158         virtual bool IsSecure() const = 0;
00159 
00161         virtual void ThreadCleanup() = 0;
00162 };
00163 
00164 #endif // NETWORK_ABSTRACTION_H