2019-07-13 20:42:03 +03:00
|
|
|
#include <LibCore/CLocalSocket.h>
|
|
|
|
#include <sys/socket.h>
|
2019-07-26 23:39:16 +03:00
|
|
|
#include <errno.h>
|
2019-07-13 20:42:03 +03:00
|
|
|
|
2019-12-25 19:09:52 +03:00
|
|
|
#ifndef SOCK_NONBLOCK
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
2019-09-21 11:28:02 +03:00
|
|
|
CLocalSocket::CLocalSocket(int fd, CObject* parent)
|
2019-07-27 11:21:25 +03:00
|
|
|
: CSocket(CSocket::Type::Local, parent)
|
|
|
|
{
|
2019-09-22 22:46:46 +03:00
|
|
|
// NOTE: This constructor is used by CLocalServer::accept(), so the socket is already connected.
|
|
|
|
m_connected = true;
|
2019-07-27 11:21:25 +03:00
|
|
|
set_fd(fd);
|
|
|
|
set_mode(CIODevice::ReadWrite);
|
|
|
|
set_error(0);
|
|
|
|
}
|
|
|
|
|
2019-07-13 20:42:03 +03:00
|
|
|
CLocalSocket::CLocalSocket(CObject* parent)
|
|
|
|
: CSocket(CSocket::Type::Local, parent)
|
|
|
|
{
|
2019-12-25 19:09:52 +03:00
|
|
|
|
|
|
|
#ifdef SOCK_NONBLOCK
|
2019-07-16 19:00:08 +03:00
|
|
|
int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
2019-12-25 19:09:52 +03:00
|
|
|
#else
|
|
|
|
int fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
|
|
int option = 1;
|
|
|
|
ioctl(fd, FIONBIO, &option);
|
|
|
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
|
|
|
#endif
|
|
|
|
|
2019-07-13 20:42:03 +03:00
|
|
|
if (fd < 0) {
|
2019-08-17 12:07:15 +03:00
|
|
|
set_error(errno);
|
2019-07-13 20:42:03 +03:00
|
|
|
} else {
|
|
|
|
set_fd(fd);
|
|
|
|
set_mode(CIODevice::ReadWrite);
|
|
|
|
set_error(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CLocalSocket::~CLocalSocket()
|
|
|
|
{
|
|
|
|
}
|