diff options
author | David Robillard <d@drobilla.net> | 2013-01-11 04:47:21 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-01-11 04:47:21 +0000 |
commit | 10e9a3a800a35916872abf9e354be4c554338e4e (patch) | |
tree | d6be3ce7993f5d8efd525629fd321b32a6341633 /src/socket | |
parent | 684eaf6b58e41f6758b160b882a6313faf0cff18 (diff) | |
download | ingen-10e9a3a800a35916872abf9e354be4c554338e4e.tar.gz ingen-10e9a3a800a35916872abf9e354be4c554338e4e.tar.bz2 ingen-10e9a3a800a35916872abf9e354be4c554338e4e.zip |
Use type safe enumerations.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4918 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/socket')
-rw-r--r-- | src/socket/Socket.cpp | 10 | ||||
-rw-r--r-- | src/socket/Socket.hpp | 4 | ||||
-rw-r--r-- | src/socket/SocketListener.cpp | 4 |
3 files changed, 9 insertions, 9 deletions
diff --git a/src/socket/Socket.cpp b/src/socket/Socket.cpp index 4f3592cd..2de88226 100644 --- a/src/socket/Socket.cpp +++ b/src/socket/Socket.cpp @@ -38,16 +38,16 @@ namespace Socket { Socket::Socket(Type t) : _type(t) - , _uri(t == UNIX ? "unix:" : "tcp:") + , _uri(t == Type::UNIX ? "unix:" : "tcp:") , _addr(NULL) , _addr_len(0) , _sock(-1) { switch (t) { - case UNIX: + case Type::UNIX: _sock = socket(AF_UNIX, SOCK_STREAM, 0); break; - case TCP: + case Type::TCP: _sock = socket(AF_INET, SOCK_STREAM, 0); break; } @@ -76,7 +76,7 @@ bool Socket::set_addr(const Raul::URI& uri) { free(_addr); - if (_type == UNIX && uri.substr(0, strlen("unix://")) == "unix://") { + if (_type == Type::UNIX && uri.substr(0, strlen("unix://")) == "unix://") { const std::string path = uri.substr(strlen("unix://")); struct sockaddr_un* uaddr = (struct sockaddr_un*)calloc( 1, sizeof(struct sockaddr_un)); @@ -86,7 +86,7 @@ Socket::set_addr(const Raul::URI& uri) _addr = (sockaddr*)uaddr; _addr_len = sizeof(struct sockaddr_un); return true; - } else if (_type == TCP && uri.find("://") != std::string::npos) { + } else if (_type == Type::TCP && uri.find("://") != std::string::npos) { const std::string authority = uri.substr(uri.find("://") + 3); const size_t port_sep = authority.find(':'); if (port_sep == std::string::npos) { diff --git a/src/socket/Socket.hpp b/src/socket/Socket.hpp index 1406d87e..ed2ddb74 100644 --- a/src/socket/Socket.hpp +++ b/src/socket/Socket.hpp @@ -30,13 +30,13 @@ namespace Socket { /** A safe and simple interface for UNIX or TCP sockets. */ class Socket : public Raul::Noncopyable { public: - enum Type { + enum class Type { UNIX, TCP }; static Type type_from_uri(const Raul::URI uri) { - return (uri.scheme() == "unix") ? UNIX : TCP; + return (uri.scheme() == "unix") ? Type::UNIX : Type::TCP; } /** Create a new unbound/unconnected socket of a given type. */ diff --git a/src/socket/SocketListener.cpp b/src/socket/SocketListener.cpp index 13049a24..0628b7a5 100644 --- a/src/socket/SocketListener.cpp +++ b/src/socket/SocketListener.cpp @@ -38,8 +38,8 @@ namespace Socket { SocketListener::SocketListener(Ingen::World& world) : Raul::Thread() , _world(world) - , _unix_sock(Socket::UNIX) - , _net_sock(Socket::TCP) + , _unix_sock(Socket::Type::UNIX) + , _net_sock(Socket::Type::TCP) { // Create UNIX socket _unix_path = world.conf().option("socket").get_string(); |