lib45d
45Drives C++ Library API Documentation
|
23 #include <45d/socket/SocketBase.hpp>
46 , socket_path_(path) {
57 for (
int connection : connections_) {
60 unlink(socket_path_.c_str());
69 int connection_fd = accept(
fd_, NULL, NULL);
70 if (connection_fd == -1) {
74 connections_.push_back(connection_fd);
80 const std::string socket_path_;
81 struct sockaddr_un sock_addr_;
82 std::vector<int> connections_;
88 memset(&sock_addr_, 0,
sizeof(sock_addr_));
89 sock_addr_.sun_family = domain_;
90 if (socket_path_.length() >=
sizeof(sock_addr_.sun_path))
92 strncpy(sock_addr_.sun_path, socket_path_.c_str(),
sizeof(sock_addr_.sun_path) - 1);
93 int res = ::bind(
fd_, (sockaddr *)&sock_addr_,
sizeof(sock_addr_));
104 void listen(
int backlog) {
105 int res = ::listen(
fd_, backlog);
108 throw SocketListenException(strerror(error), error);
int io_fd_
Connection fd.
Definition: SocketBase.hpp:278
Unix Socket Server class. Used for IPC through a named socket inode.
Definition: UnixSocketServer.hpp:35
Thrown when bind() fails.
Definition: Exceptions.hpp:66
const int _backlog_default
Number of connections to queue.
Definition: SocketBase.hpp:39
Thrown when the socket address is too long.
Definition: Exceptions.hpp:57
45Drives namespace
Definition: Bytes.hpp:27
~UnixSocketServer()
Destroy the Unix Socket Server object.
Definition: UnixSocketServer.hpp:56
Base Unix Socket Class for opening and closing the socket.
Definition: SocketBase.hpp:57
int fd_
File descriptor of socket.
Definition: SocketBase.hpp:277
UnixSocketServer(const std::string &path, int backlog=Socket::_backlog_default)
Construct a new Unix Socket Server object.
Definition: UnixSocketServer.hpp:43
int wait_for_connection()
Uses accept() to block and wait for a connection, returning a file descriptor to the connection....
Definition: UnixSocketServer.hpp:68
Thrown when accept() fails.
Definition: Exceptions.hpp:80