mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-30 21:01:00 +00:00 
			
		
		
		
	 4298ba25c3
			
		
	
	
		4298ba25c3
		
	
	
	
	
		
			
			The C_OBJECT macro now also inserts a static construct(...) helper into
the class. Now we can make the constructor(s) private and instead call:
    auto socket = CTCPSocket::construct(arguments);
construct() returns an ObjectPtr<T>, which we'll later switch to being
a NonnullRefPtr<T>, once everything else in in place for ref-counting.
		
	
			
		
			
				
	
	
		
			28 lines
		
	
	
	
		
			565 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
	
		
			565 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include <LibCore/CTCPSocket.h>
 | |
| #include <sys/socket.h>
 | |
| #include <errno.h>
 | |
| 
 | |
| CTCPSocket::CTCPSocket(int fd, CObject* parent)
 | |
|     : CSocket(CSocket::Type::TCP, parent)
 | |
| {
 | |
|     set_fd(fd);
 | |
|     set_mode(CIODevice::ReadWrite);
 | |
|     set_error(0);
 | |
| }
 | |
| 
 | |
| CTCPSocket::CTCPSocket(CObject* parent)
 | |
|     : CSocket(CSocket::Type::TCP, parent)
 | |
| {
 | |
|     int fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
 | |
|     if (fd < 0) {
 | |
|         set_error(errno);
 | |
|     } else {
 | |
|         set_fd(fd);
 | |
|         set_mode(CIODevice::ReadWrite);
 | |
|         set_error(0);
 | |
|     }
 | |
| }
 | |
| 
 | |
| CTCPSocket::~CTCPSocket()
 | |
| {
 | |
| }
 |