|  |  | @ -1,4 +1,6 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | #include "linux_socket.h" |  |  |  | #include "linux_socket.h" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | #include <cstddef> | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | #include <unistd.h> | 
			
		
	
		
		
			
				
					
					|  |  |  | #include <netinet/in.h> |  |  |  | #include <netinet/in.h> | 
			
		
	
		
		
			
				
					
					|  |  |  | #include <sys/socket.h> |  |  |  | #include <sys/socket.h> | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -6,7 +8,6 @@ namespace Bk::Net { | 
			
		
	
		
		
			
				
					
					|  |  |  | 	LinuxSocket::LinuxSocket(int id, struct sockaddr_in client_addr, IpVersion ver, IpProtocol proto) |  |  |  | 	LinuxSocket::LinuxSocket(int id, struct sockaddr_in client_addr, IpVersion ver, IpProtocol proto) | 
			
		
	
		
		
			
				
					
					|  |  |  | 	: id(id), ip_proto(proto), addr(client_addr) |  |  |  | 	: id(id), ip_proto(proto), addr(client_addr) | 
			
		
	
		
		
			
				
					
					|  |  |  | 	{ |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 		char* myIP = inet_ntoa(addr.sin_addr); |  |  |  | 		char* myIP = inet_ntoa(addr.sin_addr); | 
			
		
	
		
		
			
				
					
					|  |  |  | 		ip_addr = IpAddress(std::string(myIP), ver); |  |  |  | 		ip_addr = IpAddress(std::string(myIP), ver); | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
	
		
		
			
				
					|  |  | @ -62,7 +63,7 @@ namespace Bk::Net { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	bool LinuxSocket::conn() |  |  |  | 	bool LinuxSocket::conn() | 
			
		
	
		
		
			
				
					
					|  |  |  | 	{ |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if (connect(id, (struct sockaddr*)&addr, sizeof(addr)) < 0) 
 |  |  |  | 		if (connect(id, (struct sockaddr*)&addr, sizeof(addr)) != 0) 
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		{ |  |  |  | 		{ | 
			
		
	
		
		
			
				
					
					|  |  |  | 			BK_CORE_ERROR("Connection failed"); |  |  |  | 			BK_CORE_ERROR("Connection failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  | 	        return false; |  |  |  | 	        return false; | 
			
		
	
	
		
		
			
				
					|  |  | @ -70,18 +71,30 @@ namespace Bk::Net { | 
			
		
	
		
		
			
				
					
					|  |  |  |     	return true; |  |  |  |     	return true; | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	bool LinuxSocket::isConnected() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		char data = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		int read_size = recv(id, &data, 1, MSG_PEEK); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		return (bool)read_size; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	void LinuxSocket::emit(std::vector<char> packet) |  |  |  | 	void LinuxSocket::emit(std::vector<char> packet) | 
			
		
	
		
		
			
				
					
					|  |  |  | 	{ |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  | 		write(id, packet.data(), packet.size()); |  |  |  | 		size_t size = send(id, packet.data(), packet.size(), 0); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	std::vector<char> LinuxSocket::obtain(int size) |  |  |  | 	std::vector<char> LinuxSocket::obtain(int size) | 
			
		
	
		
		
			
				
					
					|  |  |  | 	{ |  |  |  | 	{ | 
			
		
	
		
		
			
				
					
					|  |  |  | 		std::vector<char> buffer; |  |  |  | 		if(size > this->size) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		buffer.resize(size); |  |  |  | 		{ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		int read_size = read(id, buffer.data(), buffer.size() - 1); |  |  |  | 			delete [] buffer; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		buffer.resize(read_size); |  |  |  | 			buffer = new char[size]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		return buffer; |  |  |  | 			this->size = size; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		int read_size = recv(id, buffer, this->size - 1, 0); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		if(read_size == -1) return std::vector<char>(0); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		std::vector<char> packet(buffer, buffer + read_size); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 		return packet; | 
			
		
	
		
		
			
				
					
					|  |  |  | 	} |  |  |  | 	} | 
			
		
	
		
		
			
				
					
					|  |  |  | 	
 |  |  |  | 	
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	Socket* Socket::create(IpAddress ip, int port, IpProtocol proto) |  |  |  | 	Socket* Socket::create(IpAddress ip, int port, IpProtocol proto) | 
			
		
	
	
		
		
			
				
					|  |  | 
 |