New version

This commit is contained in:
TheDoctor
2019-10-12 18:04:36 +01:00
parent b88bed3bd0
commit 6db271bd7e
64 changed files with 2972 additions and 2222 deletions

37
include/Util.hpp Normal file
View File

@ -0,0 +1,37 @@
#pragma once
#include <vector>
#include <sstream>
#include "Net.hpp"
namespace std::net
{
inline static std::vector<std::string> Split(const std::string &str, const std::string &delimiter)
{
std::vector<std::string> splited;
if (str.empty() && delimiter.empty())
return std::vector<std::string>();
std::string::size_type lastPos = str.find_first_not_of(delimiter, 0);
std::string::size_type pos = str.find_first_of(delimiter, lastPos);
while (std::string::npos != pos || std::string::npos != lastPos)
{
splited.push_back(str.substr(lastPos, pos - lastPos));
lastPos = str.find_first_not_of(delimiter, pos);
pos = str.find_first_of(delimiter, lastPos);
}
return splited;
}
sockaddr_in CreateAddress(uint32_t address, uint16_t port)
{
sockaddr_in addr;
std::memset(&addr, 0, sizeof(addr));
addr.sin_addr.s_addr = htonl(address);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
return addr;
}
}