|
|
@@ -34,14 +34,10 @@ |
|
|
|
#include <sstream> |
|
|
|
#include <cstring> |
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
#include <cstdlib> |
|
|
|
#include <cstdio> |
|
|
|
#include <cerrno> |
|
|
|
|
|
|
|
namespace CodeDweller { |
|
|
|
|
|
|
|
//// Platform specific includes... |
|
|
|
|
|
|
|
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) |
|
|
@@ -64,6 +60,8 @@ typedef SOCKET hSocket; |
|
|
|
#include <unistd.h> |
|
|
|
#include <fcntl.h> |
|
|
|
|
|
|
|
namespace CodeDweller { |
|
|
|
|
|
|
|
typedef int hSocket; // *nix uses int to handle a Socket. |
|
|
|
const hSocket INVALID_SOCKET = -1; // -1 is the invalid Socket. |
|
|
|
|
|
|
@@ -105,14 +103,14 @@ class IP4Address { |
|
|
|
IP4Address(const IP4Address&); // Constructor given an IP4Address |
|
|
|
|
|
|
|
IP4Address(const char* newIP); // Construcing with a cstring. |
|
|
|
IP4Address(const string& newIP); // Constructing with a cppstring. |
|
|
|
IP4Address(const std::string& newIP); // Constructing with a cppstring. |
|
|
|
|
|
|
|
IP4Address& operator=(const unsigned long int Right); // Convert from unsigned long int. |
|
|
|
IP4Address& operator=(const char* Right); // Convert from c string. |
|
|
|
IP4Address& operator=(const string& Right); // Convert from cpp string. |
|
|
|
IP4Address& operator=(const std::string& Right); // Convert from cpp string. |
|
|
|
|
|
|
|
operator unsigned long int() const; |
|
|
|
operator string() const; |
|
|
|
operator std::string() const; |
|
|
|
|
|
|
|
bool operator<(const IP4Address Right) const; // < Comparison. |
|
|
|
bool operator>(const IP4Address Right) const; // > Comparison. |
|
|
@@ -153,41 +151,41 @@ class Networking { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
class NotSupportedError : public runtime_error { // Thrown when something can't be done. |
|
|
|
public: NotSupportedError(const string& w):runtime_error(w) {} |
|
|
|
class NotSupportedError : public std::runtime_error { // Thrown when something can't be done. |
|
|
|
public: NotSupportedError(const std::string& w):std::runtime_error(w) {} |
|
|
|
}; |
|
|
|
class InitializationError : public runtime_error { // Thrown if initialization fails. |
|
|
|
public: InitializationError(const string& w):runtime_error(w) {} |
|
|
|
class InitializationError : public std::runtime_error { // Thrown if initialization fails. |
|
|
|
public: InitializationError(const std::string& w):std::runtime_error(w) {} |
|
|
|
}; |
|
|
|
class ControlError : public runtime_error { // Thrown if control functions fail. |
|
|
|
public: ControlError(const string& w):runtime_error(w) {} |
|
|
|
class ControlError : public std::runtime_error { // Thrown if control functions fail. |
|
|
|
public: ControlError(const std::string& w):std::runtime_error(w) {} |
|
|
|
}; |
|
|
|
class SocketCreationError : public runtime_error { // Thrown if a call to socket() fails. |
|
|
|
public: SocketCreationError(const string& w):runtime_error(w) {} |
|
|
|
class SocketCreationError : public std::runtime_error { // Thrown if a call to socket() fails. |
|
|
|
public: SocketCreationError(const std::string& w):std::runtime_error(w) {} |
|
|
|
}; |
|
|
|
class SocketSetSockOptError : public runtime_error { |
|
|
|
public: SocketSetSockOptError(const string& w):runtime_error(w) {} // Thrown if a call to setsockopt() fails. |
|
|
|
class SocketSetSockOptError : public std::runtime_error { |
|
|
|
public: SocketSetSockOptError(const std::string& w):std::runtime_error(w) {} // Thrown if a call to setsockopt() fails. |
|
|
|
}; |
|
|
|
class SocketBindError : public runtime_error { // Thrown if a call to bind() fails. |
|
|
|
public: SocketBindError(const string& w):runtime_error(w) {} |
|
|
|
class SocketBindError : public std::runtime_error { // Thrown if a call to bind() fails. |
|
|
|
public: SocketBindError(const std::string& w):std::runtime_error(w) {} |
|
|
|
}; |
|
|
|
class SocketListenError : public runtime_error { // Thrown if a call to listen() fails. |
|
|
|
public: SocketListenError(const string& w):runtime_error(w) {} |
|
|
|
class SocketListenError : public std::runtime_error { // Thrown if a call to listen() fails. |
|
|
|
public: SocketListenError(const std::string& w):std::runtime_error(w) {} |
|
|
|
}; |
|
|
|
class SocketConnectError : public runtime_error { // Thrown if a call to connect() fails. |
|
|
|
public: SocketConnectError(const string& w):runtime_error(w) {} |
|
|
|
class SocketConnectError : public std::runtime_error { // Thrown if a call to connect() fails. |
|
|
|
public: SocketConnectError(const std::string& w):std::runtime_error(w) {} |
|
|
|
}; |
|
|
|
class SocketAcceptError : public runtime_error { // Thrown if a call to accept() fails. |
|
|
|
public: SocketAcceptError(const string& w):runtime_error(w) {} |
|
|
|
class SocketAcceptError : public std::runtime_error { // Thrown if a call to accept() fails. |
|
|
|
public: SocketAcceptError(const std::string& w):std::runtime_error(w) {} |
|
|
|
}; |
|
|
|
class SocketReadError : public runtime_error { // Thrown if a socket read call fails. |
|
|
|
public: SocketReadError(const string& w):runtime_error(w) {} |
|
|
|
class SocketReadError : public std::runtime_error { // Thrown if a socket read call fails. |
|
|
|
public: SocketReadError(const std::string& w):std::runtime_error(w) {} |
|
|
|
}; |
|
|
|
class SocketWriteError : public runtime_error { // Thrown if a socket write call fails. |
|
|
|
public: SocketWriteError(const string& w):runtime_error(w) {} |
|
|
|
class SocketWriteError : public std::runtime_error { // Thrown if a socket write call fails. |
|
|
|
public: SocketWriteError(const std::string& w):std::runtime_error(w) {} |
|
|
|
}; |
|
|
|
|
|
|
|
static string DescriptiveError(string Msg, int Errno); // Form a descriptive error w/ errno. |
|
|
|
static std::string DescriptiveError(std::string Msg, int Errno); // Form a descriptive error w/ errno. |
|
|
|
|
|
|
|
Networking(); |
|
|
|
~Networking(); |