ladybird/Libraries/LibCore/CTCPSocket.cpp
Andreas Kling 4298ba25c3 LibCore: Convert CTCPSocket to ObjectPtr, add construct() helper
The C_OBJECT macro now also inserts a static construct(...) helper into
the class. Now we can make the constructor(s) private and instead call:

    auto socket = CTCPSocket::construct(arguments);

construct() returns an ObjectPtr<T>, which we'll later switch to being
a NonnullRefPtr<T>, once everything else in in place for ref-counting.
2019-09-21 15:25:08 +02:00

28 lines
565 B
C++

#include <LibCore/CTCPSocket.h>
#include <sys/socket.h>
#include <errno.h>
CTCPSocket::CTCPSocket(int fd, CObject* parent)
: CSocket(CSocket::Type::TCP, parent)
{
set_fd(fd);
set_mode(CIODevice::ReadWrite);
set_error(0);
}
CTCPSocket::CTCPSocket(CObject* parent)
: CSocket(CSocket::Type::TCP, parent)
{
int fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (fd < 0) {
set_error(errno);
} else {
set_fd(fd);
set_mode(CIODevice::ReadWrite);
set_error(0);
}
}
CTCPSocket::~CTCPSocket()
{
}