2020-01-26 14:44:24 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-26 14:44:24 +01:00
|
|
|
*/
|
|
|
|
|
2020-03-15 11:41:10 +13:00
|
|
|
#include <LibCore/UDPSocket.h>
|
2020-01-26 14:44:24 +01:00
|
|
|
#include <errno.h>
|
2020-02-02 12:34:39 +01:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2020-05-23 15:31:30 +02:00
|
|
|
#ifndef SOCK_NONBLOCK
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
2020-02-02 12:34:39 +01:00
|
|
|
namespace Core {
|
2020-01-26 14:44:24 +01:00
|
|
|
|
2020-03-15 11:41:10 +13:00
|
|
|
UDPSocket::UDPSocket(Object* parent)
|
2020-02-02 12:34:39 +01:00
|
|
|
: Socket(Socket::Type::UDP, parent)
|
2020-01-26 14:44:24 +01:00
|
|
|
{
|
2020-05-23 15:31:30 +02:00
|
|
|
#ifdef SOCK_NONBLOCK
|
2020-01-26 14:44:24 +01:00
|
|
|
int fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
|
2020-05-23 15:31:30 +02:00
|
|
|
#else
|
|
|
|
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
int option = 1;
|
|
|
|
ioctl(fd, FIONBIO, &option);
|
|
|
|
#endif
|
|
|
|
|
2020-01-26 14:44:24 +01:00
|
|
|
if (fd < 0) {
|
|
|
|
set_error(errno);
|
|
|
|
} else {
|
|
|
|
set_fd(fd);
|
2021-05-12 13:56:43 +04:30
|
|
|
set_mode(OpenMode::ReadWrite);
|
2020-01-26 14:44:24 +01:00
|
|
|
set_error(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-15 11:41:10 +13:00
|
|
|
UDPSocket::~UDPSocket()
|
2020-01-26 14:44:24 +01:00
|
|
|
{
|
|
|
|
}
|
2020-02-02 12:34:39 +01:00
|
|
|
|
|
|
|
}
|