summaryrefslogtreecommitdiffstats
path: root/src/socket
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-08-17 02:14:07 +0000
committerDavid Robillard <d@drobilla.net>2012-08-17 02:14:07 +0000
commit318b37d8b556add13b3f156f31c9e72eca339a16 (patch)
treeca7b881f8980a41eca77602b474f29964b5c89db /src/socket
parenta42744e1068a8630d8034df73bb344ca21a53b32 (diff)
downloadingen-318b37d8b556add13b3f156f31c9e72eca339a16.tar.gz
ingen-318b37d8b556add13b3f156f31c9e72eca339a16.tar.bz2
ingen-318b37d8b556add13b3f156f31c9e72eca339a16.zip
Implement real logging system, LV2 log extension support, and purge evil/ugly/untranslatable C++ stream printing.
Remove coloured log stuff from Raul. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4717 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/socket')
-rw-r--r--src/socket/Socket.cpp14
-rw-r--r--src/socket/SocketListener.cpp13
-rw-r--r--src/socket/SocketReader.cpp20
-rw-r--r--src/socket/ingen_socket_client.cpp6
-rw-r--r--src/socket/ingen_socket_server.cpp2
5 files changed, 23 insertions, 32 deletions
diff --git a/src/socket/Socket.cpp b/src/socket/Socket.cpp
index 998d1cdb..d8329fef 100644
--- a/src/socket/Socket.cpp
+++ b/src/socket/Socket.cpp
@@ -24,12 +24,8 @@
#include <string>
-#include "raul/log.hpp"
-
#include "Socket.hpp"
-#define LOG(s) (s("[Socket] "))
-
namespace Ingen {
namespace Socket {
@@ -103,8 +99,6 @@ Socket::set_addr(const Raul::URI& uri)
struct addrinfo* ainfo;
int st = 0;
if ((st = getaddrinfo(host.c_str(), port.c_str(), NULL, &ainfo))) {
- LOG(Raul::error)(Raul::fmt("Error in getaddrinfo: %1%\n")
- % gai_strerror(st));
return false;
}
@@ -125,8 +119,6 @@ Socket::bind(const Raul::URI& uri)
return true;
}
- LOG(Raul::error)(Raul::fmt("Failed to bind <%1%> (%2%)\n")
- % _uri % strerror(errno));
return false;
}
@@ -137,8 +129,6 @@ Socket::connect(const Raul::URI& uri)
return true;
}
- LOG(Raul::error)(Raul::fmt("Failed to connect <%1%> (%2%)\n")
- % _uri % strerror(errno));
return false;
}
@@ -146,10 +136,8 @@ bool
Socket::listen()
{
if (::listen(_sock, 64) == -1) {
- LOG(Raul::error)(Raul::fmt("Failed to listen on %1%\n") % _uri);
return false;
} else {
- LOG(Raul::info)(Raul::fmt("Listening on %1%\n") % _uri);
return true;
}
}
@@ -163,8 +151,6 @@ Socket::accept()
int conn = ::accept(_sock, client_addr, &client_addr_len);
if (conn == -1) {
- LOG(Raul::error)(Raul::fmt("Error accepting connection: %1%\n")
- % strerror(errno));
return SharedPtr<Socket>();
}
diff --git a/src/socket/SocketListener.cpp b/src/socket/SocketListener.cpp
index f272513e..76afb4fd 100644
--- a/src/socket/SocketListener.cpp
+++ b/src/socket/SocketListener.cpp
@@ -19,9 +19,10 @@
#include <sstream>
-#include "ingen/Interface.hpp"
#include "ingen/AtomReader.hpp"
#include "ingen/Configuration.hpp"
+#include "ingen/Interface.hpp"
+#include "ingen/Log.hpp"
#include "ingen/World.hpp"
#include "sord/sordmm.hpp"
#include "sratom/sratom.h"
@@ -31,8 +32,6 @@
#include "SocketListener.hpp"
#include "SocketServer.hpp"
-#define LOG(s) s << "[SocketListener] "
-
namespace Ingen {
namespace Socket {
@@ -46,7 +45,7 @@ SocketListener::SocketListener(Ingen::World& world)
_unix_path = world.conf().option("socket").get_string();
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;
+ _world.log().error("Failed to create UNIX socket\n");
_unix_sock.close();
}
@@ -56,7 +55,7 @@ SocketListener::SocketListener(Ingen::World& world)
ss << "tcp://localhost:";
ss << port;
if (!_net_sock.bind(Raul::URI(ss.str())) || !_net_sock.listen()) {
- LOG(Raul::error) << "Failed to create TCP socket" << std::endl;
+ _world.log().error("Failed to create TCP socket\n");
_net_sock.close();
}
@@ -100,10 +99,10 @@ SocketListener::_run()
if (_exit_flag) {
break;
} else if (ret == -1) {
- LOG(Raul::error) << "Poll error: " << strerror(errno) << std::endl;
+ _world.log().error(Raul::fmt("Poll error: %1%\n") % strerror(errno));
break;
} else if (ret == 0) {
- LOG(Raul::error) << "Poll returned with no data" << std::endl;
+ _world.log().error("Poll returned with no data\n");
continue;
}
diff --git a/src/socket/SocketReader.cpp b/src/socket/SocketReader.cpp
index 8b580b18..c1e8dfd3 100644
--- a/src/socket/SocketReader.cpp
+++ b/src/socket/SocketReader.cpp
@@ -17,8 +17,9 @@
#include <errno.h>
#include <poll.h>
-#include "ingen/Interface.hpp"
#include "ingen/AtomReader.hpp"
+#include "ingen/Interface.hpp"
+#include "ingen/Log.hpp"
#include "ingen/URIMap.hpp"
#include "ingen/World.hpp"
#include "sord/sordmm.hpp"
@@ -26,8 +27,6 @@
#include "SocketReader.hpp"
-#define LOG(s) s << "[SocketReader] "
-
namespace Ingen {
namespace Socket {
@@ -121,8 +120,8 @@ SocketReader::_run()
// Read directly from the connection with serd
FILE* f = fdopen(_socket->fd(), "r");
if (!f) {
- LOG(Raul::error) << "Failed to open connection "
- << "(" << strerror(errno) << ")" << std::endl;
+ _world.log().error(Raul::fmt("Failed to open connection (%1%)\n")
+ % strerror(errno));
// Connection gone, exit
_socket.reset();
return;
@@ -131,7 +130,11 @@ SocketReader::_run()
serd_reader_start_stream(reader, f, (const uint8_t*)"(socket)", false);
// Make an AtomReader to call Ingen Interface methods based on Atom
- AtomReader ar(_world.uri_map(), _world.uris(), _world.forge(), _iface);
+ AtomReader ar(_world.uri_map(),
+ _world.uris(),
+ _world.log(),
+ _world.forge(),
+ _iface);
struct pollfd pfd;
pfd.fd = _socket->fd();
@@ -156,10 +159,11 @@ SocketReader::_run()
if (st == SERD_FAILURE) {
continue; // Read nothing, e.g. just whitespace
} else if (st) {
- LOG(Raul::error) << "Read error: " << serd_strerror(st) << std::endl;
+ _world.log().error(Raul::fmt("Read error: %1%\n")
+ % serd_strerror(st));
continue;
} else if (!_msg_node) {
- LOG(Raul::error) << "Received empty message" << std::endl;
+ _world.log().error("Received empty message\n");
continue;
}
diff --git a/src/socket/ingen_socket_client.cpp b/src/socket/ingen_socket_client.cpp
index 0e8c95bf..e835adc8 100644
--- a/src/socket/ingen_socket_client.cpp
+++ b/src/socket/ingen_socket_client.cpp
@@ -14,9 +14,11 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <errno.h>
+
+#include "ingen/Log.hpp"
#include "ingen/Module.hpp"
#include "ingen/World.hpp"
-#include "raul/log.hpp"
#include "Socket.hpp"
#include "SocketClient.hpp"
@@ -29,6 +31,8 @@ new_socket_interface(Ingen::World* world,
SharedPtr<Ingen::Socket::Socket> sock(
new Ingen::Socket::Socket(Ingen::Socket::Socket::type_from_uri(uri)));
if (!sock->connect(uri)) {
+ world->log().error(Raul::fmt("Failed to connect <%1%> (%2%)\n")
+ % sock->uri() % strerror(errno));
return SharedPtr<Ingen::Interface>();
}
Ingen::Socket::SocketClient* client = new Ingen::Socket::SocketClient(
diff --git a/src/socket/ingen_socket_server.cpp b/src/socket/ingen_socket_server.cpp
index aa13eebd..45c587ce 100644
--- a/src/socket/ingen_socket_server.cpp
+++ b/src/socket/ingen_socket_server.cpp
@@ -14,8 +14,6 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "raul/log.hpp"
-
#include "ingen/Module.hpp"
#include "ingen/World.hpp"