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