1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:48:12 +00:00

LibCore: Add CSocket::bind() (virtual) and CSocket::listen().

These will be useful for implementing server sockets.
This commit is contained in:
Andreas Kling 2019-07-26 22:39:16 +02:00
parent 2f373a27a2
commit be2b585ca6
7 changed files with 42 additions and 4 deletions

View file

@ -1,5 +1,6 @@
#include <LibCore/CLocalSocket.h>
#include <sys/socket.h>
#include <errno.h>
CLocalSocket::CLocalSocket(CObject* parent)
: CSocket(CSocket::Type::Local, parent)
@ -17,3 +18,11 @@ CLocalSocket::CLocalSocket(CObject* parent)
CLocalSocket::~CLocalSocket()
{
}
bool CLocalSocket::bind(const CSocketAddress& address)
{
auto un = address.to_sockaddr_un();
int rc = ::bind(fd(), (const sockaddr*)&un, sizeof(un));
set_error(errno);
return rc == 0;
}