7 #include <sys/socket.h>
10 using STG::SGCP::UnixProto;
12 UnixProto::UnixProto()
13 : m_sock(socket(AF_UNIX, SOCK_STREAM, 0))
17 UnixProto::~UnixProto()
22 void UnixProto::connect(const std::string& address, uint16_t /*port*/)
25 addr.sun_family = AF_UNIX;
26 size_t max = sizeof(addr.sun_path);
27 strncpy(addr.sun_path, address.c_str(), max - 1);
28 addr.sun_path[max - 1] = 0; // Just in case.
29 if (::connect(m_sock, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) < 0)
30 throw Error(strerror(errno));
33 ssize_t UnixProto::write(const void* buf, size_t size)
35 return ::write(m_sock, buf, size);
38 ssize_t UnixProto::read(void* buf, size_t size)
40 return ::read(m_sock, buf, size);