sockets.hpp
Go to the documentation of this file.
00001 
00015 /*****************************************************************************
00016  ** Ifdefs
00017  *****************************************************************************/
00018 
00019 #ifndef ECL_IO_SOCKETS_HPP_
00020 #define ECL_IO_SOCKETS_HPP_
00021 
00022 /*****************************************************************************
00023  ** Include
00024  *****************************************************************************/
00025 
00026 #include <string>
00027 #include <ecl/config/ecl.hpp>
00028 #include <ecl/errors/handlers.hpp>
00029 
00030 #ifdef ECL_IS_WIN32
00031   #include <ecl/config/windows.hpp>
00032   #include <winsock2.h>
00033   #include <ws2tcpip.h>
00034   //  #include <iphlpapi.h>
00035   //  #include <sys/types.h>
00036 #elif defined(ECL_IS_POSIX)
00037   #include <netinet/in.h> // provides AF_LOCAL etc...
00038   #include <errno.h>
00039 #else
00040   #error("There is not a supporting sockets implementation on this platform (possibly needs extended ecl support).")
00041 #endif
00042 #include "macros.hpp"
00043 
00044 /*****************************************************************************
00045  ** Namespaces
00046  *****************************************************************************/
00047 
00048 namespace ecl
00049 {
00050 
00051 /*****************************************************************************
00052  ** Types
00053  *****************************************************************************/
00054 
00055 #ifdef ECL_IS_WIN32
00056   typedef SOCKET socket_descriptor; 
00057 #else
00058   typedef int socket_descriptor; 
00059 #endif
00060 
00061 /*****************************************************************************
00062  ** Errors
00063  *****************************************************************************/
00064 
00068 class ecl_io_PUBLIC SocketError : public Error
00069 {
00070 public:
00076   SocketError(const ErrorFlag& flag = UnknownError) : Error(flag)
00077   {}
00078 protected:
00079   virtual const char* invalidArgErrorString() const
00080   { return "One of the arguments is invalid (usually a socket descriptor).";}
00081 #ifdef ECL_IS_WIN32
00082   virtual const char* notSupportedError() const
00083   { return "This version of winsock is not supported on this platform.";}
00084   virtual const char* interruptedErrorString() const
00085   { return "Interrupted by WSACancelBlockingCall.";}
00086   virtual const char* notInitialisedErrorString() const
00087   { return "The underlying winsock subsystem is not initialised (needs WSAStartup).";}
00088   virtual const char* blockingErrorString() const
00089   { return "Marked as non-blocking, but current configuration would block.";}
00090   virtual const char* busyErrorString() const
00091   { return "A blocking winsock operation is in progress.";}
00092   virtual const char* systemFailureErrorString() const
00093   { return "The network subsystem has failed.";}
00094 #elif defined(ECL_IS_POSIX)
00095   virtual const char* interruptedErrorString() const
00096   { return "Interrupted by a signal or an io error.";}
00097   virtual const char* argNotSupportedString() const
00098   { return "The specified address family or protocol is not supported on this machine.";}
00099 #endif
00100 };
00101 
00102 /*****************************************************************************
00103  ** Functions
00104  *****************************************************************************/
00105 
00122 ecl_io_PUBLIC SocketError init_sockets();
00139 ecl_io_PUBLIC SocketError close_socket(const socket_descriptor& sock);
00154 ecl_io_PUBLIC SocketError shutdown_sockets();
00155 
00156 } // namespace ecl
00157 
00158 #endif /* ECL_IO_SOCKETS_HPP_ */


ecl_io
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 18:53:24