lundi 2 mars 2015

Permission refused when connecting to domain socket created by Boost.Asio

I'm trying to create a server that receives connections via domain sockets. I can start the server and I can see the socket being created on the filesystem. But whenever I try to connect to it via socat I get the following error:


2015/03/02 14:00:10 socat[62720] E connect(3, LEN=19 AF=1 "/var/tmp/rpc.sock", 19): Connection refused


This is my Asio code (only the .cpp files). Despite the post title I'm using the Boost-free version of Asio but I don't think that would be a problem.



namespace myapp {

DomainListener::DomainListener(const string& addr) : socket{this->service}, Listener{addr} {
remove(this->address.c_str());
stream_protocol::endpoint ep(this->address);
stream_protocol::acceptor acceptor(this->service, ep);
acceptor.async_accept(this->socket, ep, bind(&DomainListener::accept_callback, this, _1));
}

DomainListener::~DomainListener() {
this->service.stop();
remove(this->address.c_str());
}

void DomainListener::accept_callback(const error_code& ec) noexcept {
this->socket.async_read_some(asio::buffer(this->data), bind(&DomainListener::read_data, this, _1, _2));
}

void DomainListener::read_data(const error_code& ec, size_t length) noexcept {
//std::cerr << "AAA" << std::endl;
//std::cerr << this->data[0] << std::endl;
//std::cerr << "BBB" << std::endl;
}

}



Listener::Listener(const string& addr) : work{asio::io_service::work(this->service)} {
this->address = addr;
}

void Listener::listen() {
this->service.run();
}

Listener::~Listener() {
}


In the code that uses these classes I call listen() whenever I want to start listening to the socket for connections.


I've managed to get this to work with lib and changed to Asio because I thought it would make for more readable code but I'm finding the documentation to be very ambiguous.


Aucun commentaire:

Enregistrer un commentaire