diff options
author | David Robillard <d@drobilla.net> | 2012-08-14 04:23:23 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-08-14 04:23:23 +0000 |
commit | 80fee5c311fdbdeda573ec81f59158a5fc87d0a1 (patch) | |
tree | 8e7e5a6c9bda32bbe0ae8e8c9f6ab23e44c7c181 /src/socket | |
parent | 058eaf65642268047a984a5c80d54a1f62a85130 (diff) | |
download | ingen-80fee5c311fdbdeda573ec81f59158a5fc87d0a1.tar.gz ingen-80fee5c311fdbdeda573ec81f59158a5fc87d0a1.tar.bz2 ingen-80fee5c311fdbdeda573ec81f59158a5fc87d0a1.zip |
Update for latest Raul.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4687 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/socket')
-rw-r--r-- | src/socket/Socket.cpp | 31 | ||||
-rw-r--r-- | src/socket/Socket.hpp | 34 | ||||
-rw-r--r-- | src/socket/SocketClient.hpp | 4 | ||||
-rw-r--r-- | src/socket/SocketListener.cpp | 6 | ||||
-rw-r--r-- | src/socket/ingen_socket_client.cpp | 11 |
5 files changed, 38 insertions, 48 deletions
diff --git a/src/socket/Socket.cpp b/src/socket/Socket.cpp index d6162df2..13a684bc 100644 --- a/src/socket/Socket.cpp +++ b/src/socket/Socket.cpp @@ -42,6 +42,7 @@ namespace Socket { Socket::Socket(Type t) : _type(t) + , _uri(t == UNIX ? "unix:" : "tcp:") , _addr(NULL) , _addr_len(0) , _sock(-1) @@ -56,11 +57,11 @@ Socket::Socket(Type t) } } -Socket::Socket(Type t, - const std::string& uri, - struct sockaddr* addr, - socklen_t addr_len, - int fd) +Socket::Socket(Type t, + const Raul::URI& uri, + struct sockaddr* addr, + socklen_t addr_len, + int fd) : _type(t) , _uri(uri) , _addr(addr) @@ -76,7 +77,7 @@ Socket::~Socket() } bool -Socket::set_addr(const std::string& uri) +Socket::set_addr(const Raul::URI& uri) { free(_addr); if (_type == UNIX && uri.substr(0, strlen("unix://")) == "unix://") { @@ -90,14 +91,14 @@ Socket::set_addr(const std::string& uri) _addr_len = sizeof(struct sockaddr_un); return true; } else if (_type == TCP && uri.find("://") != std::string::npos) { - const std::string no_scheme = uri.substr(uri.find("://") + 4); - const size_t port_sep = no_scheme.find(':'); + const std::string authority = uri.substr(uri.find("://") + 3); + const size_t port_sep = authority.find(':'); if (port_sep == std::string::npos) { return false; } - const std::string host = no_scheme.substr(0, port_sep); - const std::string port = no_scheme.substr(port_sep + 1).c_str(); + const std::string host = authority.substr(0, port_sep); + const std::string port = authority.substr(port_sep + 1).c_str(); struct addrinfo* ainfo; int st = 0; @@ -118,7 +119,7 @@ Socket::set_addr(const std::string& uri) } bool -Socket::bind(const std::string& uri) +Socket::bind(const Raul::URI& uri) { if (set_addr(uri) && ::bind(_sock, _addr, _addr_len) != -1) { return true; @@ -130,7 +131,7 @@ Socket::bind(const std::string& uri) } bool -Socket::connect(const std::string& uri) +Socket::connect(const Raul::URI& uri) { if (set_addr(uri) && ::connect(_sock, _addr, _addr_len) != -1) { return true; @@ -167,11 +168,11 @@ Socket::accept() return SharedPtr<Socket>(); } - std::string client_uri = _uri; - char host[NI_MAXHOST]; + Raul::URI client_uri = _uri; + char host[NI_MAXHOST]; if (getnameinfo(client_addr, client_addr_len, host, sizeof(host), NULL, 0, 0)) { - client_uri = _uri.substr(0, _uri.find(":") + 1) + host; + client_uri = Raul::URI(_uri.scheme() + "://" + host); } return SharedPtr<Socket>( diff --git a/src/socket/Socket.hpp b/src/socket/Socket.hpp index 13f18be8..49d03d48 100644 --- a/src/socket/Socket.hpp +++ b/src/socket/Socket.hpp @@ -18,13 +18,11 @@ #define INGEN_SOCKET_SOCKET_HPP #include <stdint.h> -#include <string.h> #include <sys/socket.h> -#include <string> - -#include "raul/SharedPtr.hpp" #include "raul/Noncopyable.hpp" +#include "raul/SharedPtr.hpp" +#include "raul/URI.hpp" namespace Ingen { namespace Socket { @@ -37,23 +35,19 @@ public: TCP }; - static Type type_from_uri(const std::string& uri) { - if (uri.substr(0, strlen("unix://")) == "unix://") { - return UNIX; - } else { - return TCP; - } + static Type type_from_uri(const Raul::URI uri) { + return (uri.scheme() == "unix") ? UNIX : TCP; } /** Create a new unbound/unconnected socket of a given type. */ explicit Socket(Type t); /** Wrap an existing open socket. */ - Socket(Type t, - const std::string& uri, - struct sockaddr* addr, - socklen_t addr_len, - int fd); + Socket(Type t, + const Raul::URI& uri, + struct sockaddr* addr, + socklen_t addr_len, + int fd); ~Socket(); @@ -61,13 +55,13 @@ public: * @param uri Address URI, e.g. unix:///tmp/foo or tcp://somehost:1234 * @return True on success. */ - bool bind(const std::string& uri); + bool bind(const Raul::URI& uri); /** Connect a client socket to a server address. * @param uri Address URI, e.g. unix:///tmp/foo or tcp://somehost:1234 * @return True on success. */ - bool connect(const std::string& uri); + bool connect(const Raul::URI& uri); /** Mark server socket as passive to listen for incoming connections. * @return True on success. @@ -82,16 +76,16 @@ public: /** Return the file descriptor for the socket. */ int fd() { return _sock; } - const std::string& uri() const { return _uri; } + const Raul::URI& uri() const { return _uri; } /** Close the socket. */ void close(); private: - bool set_addr(const std::string& uri); + bool set_addr(const Raul::URI& uri); Type _type; - std::string _uri; + Raul::URI _uri; struct sockaddr* _addr; socklen_t _addr_len; int _sock; diff --git a/src/socket/SocketClient.hpp b/src/socket/SocketClient.hpp index c316e4a4..14227c90 100644 --- a/src/socket/SocketClient.hpp +++ b/src/socket/SocketClient.hpp @@ -17,8 +17,6 @@ #ifndef INGEN_SOCKET_SOCKET_CLIENT_HPP #define INGEN_SOCKET_SOCKET_CLIENT_HPP -#include <string> - #include "SocketReader.hpp" #include "SocketWriter.hpp" @@ -30,7 +28,7 @@ class SocketClient : public SocketWriter { public: SocketClient(World& world, - const std::string& uri, + const Raul::URI& uri, SharedPtr<Socket> sock, SharedPtr<Interface> respondee) : SocketWriter(world.uri_map(), world.uris(), uri, sock) diff --git a/src/socket/SocketListener.cpp b/src/socket/SocketListener.cpp index f79c055a..6b68c36c 100644 --- a/src/socket/SocketListener.cpp +++ b/src/socket/SocketListener.cpp @@ -45,7 +45,7 @@ SocketListener::SocketListener(Ingen::World& world) { // Create UNIX socket _unix_path = world.conf().option("socket").get_string(); - const std::string unix_uri = "unix://" + _unix_path; + const Raul::URI unix_uri("unix://" + _unix_path); if (!_unix_sock.bind(unix_uri) || !_unix_sock.listen()) { LOG(Raul::error) << "Failed to create UNIX socket" << std::endl; _unix_sock.close(); @@ -54,9 +54,9 @@ SocketListener::SocketListener(Ingen::World& world) // Create TCP socket int port = world.conf().option("engine-port").get_int(); std::ostringstream ss; - ss << "tcp:///localhost:"; + ss << "tcp://localhost:"; ss << port; - if (!_net_sock.bind(ss.str()) || !_net_sock.listen()) { + if (!_net_sock.bind(Raul::URI(ss.str())) || !_net_sock.listen()) { LOG(Raul::error) << "Failed to create TCP socket" << std::endl; _net_sock.close(); } diff --git a/src/socket/ingen_socket_client.cpp b/src/socket/ingen_socket_client.cpp index 8819ea2c..148f2b2a 100644 --- a/src/socket/ingen_socket_client.cpp +++ b/src/socket/ingen_socket_client.cpp @@ -25,19 +25,16 @@ static SharedPtr<Ingen::Interface> new_socket_interface(Ingen::World* world, - const std::string& url, + const Raul::URI& uri, SharedPtr<Ingen::Interface> respondee) { SharedPtr<Ingen::Socket::Socket> sock( - new Ingen::Socket::Socket(Ingen::Socket::Socket::type_from_uri(url))); - if (!sock->connect(url)) { + new Ingen::Socket::Socket(Ingen::Socket::Socket::type_from_uri(uri))); + if (!sock->connect(uri)) { return SharedPtr<Ingen::Interface>(); } Ingen::Socket::SocketClient* client = new Ingen::Socket::SocketClient( - *world, - url, - sock, - respondee); + *world, uri, sock, respondee); return SharedPtr<Ingen::Interface>(client); } |