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 
00043 
00044 /*****************************************************************************
00045 ** Namespaces
00046 *****************************************************************************/
00047 
00048 namespace ecl {
00049 
00050 /*****************************************************************************
00051 ** Types
00052 *****************************************************************************/
00053 
00054 #ifdef ECL_IS_WIN32
00055         typedef SOCKET socket_descriptor; 
00056 #else
00057         typedef int socket_descriptor; 
00058 #endif
00059 
00060 
00061 /*****************************************************************************
00062 ** Errors
00063 *****************************************************************************/
00064 
00068 class ECL_PUBLIC SocketError : public Error {
00069 public:
00075         SocketError(const ErrorFlag& flag = UnknownError) : Error(flag) {}
00076 protected:
00077         virtual const char* invalidArgErrorString() const { return "One of the arguments is invalid (usually a socket descriptor)."; }
00078 #ifdef ECL_IS_WIN32
00079         virtual const char* notSupportedError() const { return "This version of winsock is not supported on this platform."; }
00080         virtual const char* interruptedErrorString() const { return "Interrupted by WSACancelBlockingCall."; }
00081         virtual const char* notInitialisedErrorString() const { return "The underlying winsock subsystem is not initialised (needs WSAStartup)."; }
00082         virtual const char* blockingErrorString() const { return "Marked as non-blocking, but current configuration would block."; }
00083         virtual const char* busyErrorString() const { return "A blocking winsock operation is in progress."; }
00084         virtual const char* systemFailureErrorString() const { return "The network subsystem has failed."; }
00085 
00086 #elif defined(ECL_IS_POSIX)
00087         virtual const char* interruptedErrorString() const { return "Interrupted by a signal or an io error."; }
00088         virtual const char* argNotSupportedString() const { return "The specified address family or protocol is not supported on this machine."; }
00089 #endif
00090 };
00091 
00092 /*****************************************************************************
00093 ** Functions
00094 *****************************************************************************/
00095 
00112 SocketError init_sockets();
00129 SocketError close_socket(const socket_descriptor& sock);
00144 SocketError shutdown_sockets();
00145 
00146 } // namespace ecl
00147 
00148 
00149 #endif /* ECL_IO_SOCKETS_HPP_ */


ecl_io
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:11:37