sockets.hpp
Go to the documentation of this file.
1 
15 /*****************************************************************************
16  ** Ifdefs
17  *****************************************************************************/
18 
19 #ifndef ECL_IO_SOCKETS_HPP_
20 #define ECL_IO_SOCKETS_HPP_
21 
22 /*****************************************************************************
23  ** Include
24  *****************************************************************************/
25 
26 #include <string>
27 #include <ecl/config/ecl.hpp>
28 #include <ecl/errors/handlers.hpp>
29 
30 #ifdef ECL_IS_WIN32
31  #include <ecl/config/windows.hpp>
32  #include <winsock2.h>
33  #include <ws2tcpip.h>
34  // #include <iphlpapi.h>
35  // #include <sys/types.h>
36 #elif defined(ECL_IS_POSIX)
37  #include <netinet/in.h> // provides AF_LOCAL etc...
38  #include <errno.h>
39 #else
40  #error("There is not a supporting sockets implementation on this platform (possibly needs extended ecl support).")
41 #endif
42 #include "macros.hpp"
43 
44 /*****************************************************************************
45  ** Namespaces
46  *****************************************************************************/
47 
48 namespace ecl
49 {
50 
51 /*****************************************************************************
52  ** Types
53  *****************************************************************************/
54 
55 #ifdef ECL_IS_WIN32
56  typedef SOCKET socket_descriptor;
57 #else
58  typedef int socket_descriptor;
59 #endif
60 
61 /*****************************************************************************
62  ** Errors
63  *****************************************************************************/
64 
69 {
70 public:
76  SocketError(const ErrorFlag& flag = UnknownError) : Error(flag)
77  {}
78 protected:
79  virtual const char* invalidArgErrorString() const
80  { return "One of the arguments is invalid (usually a socket descriptor).";}
81 #ifdef ECL_IS_WIN32
82  virtual const char* notSupportedError() const
83  { return "This version of winsock is not supported on this platform.";}
84  virtual const char* interruptedErrorString() const
85  { return "Interrupted by WSACancelBlockingCall.";}
86  virtual const char* notInitialisedErrorString() const
87  { return "The underlying winsock subsystem is not initialised (needs WSAStartup).";}
88  virtual const char* blockingErrorString() const
89  { return "Marked as non-blocking, but current configuration would block.";}
90  virtual const char* busyErrorString() const
91  { return "A blocking winsock operation is in progress.";}
92  virtual const char* systemFailureErrorString() const
93  { return "The network subsystem has failed.";}
94 #elif defined(ECL_IS_POSIX)
95  virtual const char* interruptedErrorString() const
96  { return "Interrupted by a signal or an io error.";}
97  virtual const char* argNotSupportedString() const
98  { return "The specified address family or protocol is not supported on this machine.";}
99 #endif
100 };
101 
102 /*****************************************************************************
103  ** Functions
104  *****************************************************************************/
105 
139 ecl_io_PUBLIC SocketError close_socket(const socket_descriptor& sock);
155 
156 } // namespace ecl
157 
158 #endif /* ECL_IO_SOCKETS_HPP_ */
virtual const char * invalidArgErrorString() const
Definition: sockets.hpp:79
UnknownError
int socket_descriptor
Cross-platform typedef for a socket file descriptor.
Definition: sockets.hpp:58
ecl_io_PUBLIC SocketError init_sockets()
Initialise the socket subsystem.
Definition: lib/sockets.cpp:27
Macros for windows dlls.
#define ecl_io_PUBLIC
Definition: macros.hpp:28
ecl_io_PUBLIC SocketError close_socket(const socket_descriptor &sock)
Close a socket.
Definition: lib/sockets.cpp:49
SocketError(const ErrorFlag &flag=UnknownError)
Configures the error class with the specified error flag.
Definition: sockets.hpp:76
ecl_io_PUBLIC SocketError shutdown_sockets()
Shutdown the socket subsystem.
Definition: lib/sockets.cpp:74
Extends the generic error handler with socket specific error strings.
Definition: sockets.hpp:68


ecl_io
Author(s): Daniel Stonier
autogenerated on Fri Jun 7 2019 21:52:45