Skip to content

Commit

Permalink
libraries: libcore[udpsocket]
Browse files Browse the repository at this point in the history
  • Loading branch information
krishpranav committed Oct 3, 2023
1 parent 52a510a commit e0146d9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions libraries/libcore/udpsocket.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @file udpsocket.cpp
* @author Krisna Pranav
* @brief udpsocket
* @version 6.0
* @date 2023-10-03
*
* @copyright Copyright (c) 2021 - 2023 pranaOS Developers, Krisna Pranav
*
*/

#include <errno.h>
#include <libcore/udpsocket.h>
#include <sys/socket.h>

#ifndef SOCK_NONBLOCK
# include <sys/ioctl.h>
#endif

namespace Core
{
/**
* @param parent
*/
UDPSocket::UDPSocket(Object* parent)
: Socket(Socket::Type::UDP, parent)
{
int fd = socket(AF_INET, SOCK_DGRAM, 0);
int option = 1;
ioctl(fd, FIONBIO, &option);

if (fd < 0) {
set_error(errno);
} else {
set_fd(fd);
set_error(0);
}
}

/// @brief Destroy the UDPSocket::UDPSocket object
UDPSocket::~UDPSocket()
{}
} // namespace Core

0 comments on commit e0146d9

Please sign in to comment.