Skip to content

Commit

Permalink
libraries: libcore[tcpsocket]
Browse files Browse the repository at this point in the history
  • Loading branch information
krishpranav committed Oct 2, 2023
1 parent 74b26bb commit 6ed0e3e
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions libraries/libcore/tcpsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,49 @@
# include <sys/ioctl.h>
#endif

namespace Core
namespace Core
{

/**
* @brief Construct a new TCPSocket::TCPSocket object
*
* @param fd
* @param parent
*/
TCPSocket::TCPSocket(int fd, Object* parent)
: Socket(Socket::Type::TCP, parent)
: Socket(Socket::Type::TCP, parent)
{
m_connected = true;
set_fd(fd);
set_mode(IODevice::ReadWrite);
set_error(0);
}

/**
* @brief Construct a new TCPSocket::TCPSocket object
*
* @param parent
*/
TCPSocket::TCPSocket(Object* parent)
: Socket(Socket::Type::TCP, parent)
{
#ifdef SOCK_NONBLOCK
int fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
#else
int fd = socket(AF_INET, SOCK_STREAM, 0);
int option = 1;
ioctl(fd, FIONBIO, &option);
#endif
if (fd < 0) {
set_error(errno);
} else {
set_fd(fd);
set_mode(IODevice::ReadWrite);
set_error(0);
}
}

/// @brief Destroy the TCPSocket::TCPSocket object
TCPSocket::~TCPSocket()
{}
{ }

} // namespace Core
} // namesapce Core

0 comments on commit 6ed0e3e

Please sign in to comment.