Working abstraction

multi_plaform
anulax1225 ago%!(EXTRA string=1 year)
parent ef1389d5d1
commit 96d928a83c
  1. 8
      bakanet/src/bakanet.h
  2. 2
      bakanet/src/bakanet/sock_layer/ip_address.h
  3. 2
      bakanet/src/bakanet/sock_layer/socket.h
  4. 4
      bakanet/src/plaform/linux/linux_ip_address.cpp
  5. 2
      bakanet/src/plaform/linux/linux_socket.cpp
  6. 4
      premake5.lua

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <bakanet/ip_address.h> #include <bakanet/sock_layer/ip_address.h>
#include <bakanet/packet.h> #include <bakanet/sock_layer/packet.h>
#include <bakanet/socket.h> #include <bakanet/sock_layer/socket.h>
#include <bakanet/dns_lookup.h> #include <bakanet/sock_layer/dns_lookup.h>

@ -10,7 +10,7 @@ namespace Bk::Net {
IpAddress(std::string ip, IpVersion ipv = IpVersion::IPv4) IpAddress(std::string ip, IpVersion ipv = IpVersion::IPv4)
: str(ip), version(ipv) { } : str(ip), version(ipv) { }
std::unique_ptr<void*> get_data(); struct in_addr get_data();
std::string str; std::string str;
IpVersion version; IpVersion version;
}; };

@ -11,7 +11,7 @@ namespace Bk::Net {
class Socket class Socket
{ {
public: public:
virtual ~Socket() { } virtual ~Socket() {}
virtual bool init() = 0; virtual bool init() = 0;
virtual bool start(int cpt_conn) = 0; virtual bool start(int cpt_conn) = 0;

@ -2,10 +2,10 @@
#include <string.h> #include <string.h>
namespace Bk::Net { namespace Bk::Net {
std::unique_ptr<void*> IpAddress::get_data() struct in_addr IpAddress::get_data()
{ {
struct in_addr addr; struct in_addr addr;
if (inet_pton(AF_INET, str.c_str(), &addr) <= 0) perror("Bad IP"); if (inet_pton(AF_INET, str.c_str(), &addr) <= 0) perror("Bad IP");
return std::make_unique<void*>(&addr); return addr;
} }
} }

@ -11,7 +11,7 @@ namespace Bk::Net {
perror("socket failed"); perror("socket failed");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
addr.sin_addr = *(struct in_addr*)*ip_addr.get_data(); addr.sin_addr = ip_addr.get_data();
addr.sin_family = (int)ip_addr.version; addr.sin_family = (int)ip_addr.version;
addr.sin_port = htons(port); addr.sin_port = htons(port);
} }

@ -15,3 +15,7 @@ IncludeDirs["bakanet"] = "%{wks.location}/bakanet/src/"
group "NetCore" group "NetCore"
include "bakanet" include "bakanet"
group "" group ""
group "Sandbox"
include "sandbox"
group ""
Loading…
Cancel
Save