CLocalSocket.cpp 724 B

123456789101112131415161718192021222324252627282930
  1. #include <LibCore/CLocalSocket.h>
  2. #include <sys/socket.h>
  3. #include <errno.h>
  4. CLocalSocket::CLocalSocket(int fd, CObject* parent)
  5. : CSocket(CSocket::Type::Local, parent)
  6. {
  7. // NOTE: This constructor is used by CLocalServer::accept(), so the socket is already connected.
  8. m_connected = true;
  9. set_fd(fd);
  10. set_mode(CIODevice::ReadWrite);
  11. set_error(0);
  12. }
  13. CLocalSocket::CLocalSocket(CObject* parent)
  14. : CSocket(CSocket::Type::Local, parent)
  15. {
  16. int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
  17. if (fd < 0) {
  18. set_error(errno);
  19. } else {
  20. set_fd(fd);
  21. set_mode(CIODevice::ReadWrite);
  22. set_error(0);
  23. }
  24. }
  25. CLocalSocket::~CLocalSocket()
  26. {
  27. }