[DEV] continue removing stl

This commit is contained in:
Edouard DUPIN 2017-08-28 00:04:49 +02:00
parent 54a5b66436
commit 29607a6d46
17 changed files with 194 additions and 194 deletions

View File

@ -6,19 +6,19 @@
#include <enet/debug.hpp>
#include <enet/Http.hpp>
#include <map>
#include <etk/Map.hpp>
#include <etk/stdTools.hpp>
#include <cstring>
static std::string escapeChar(const std::string& _value) {
static etk::String escapeChar(const etk::String& _value) {
return _value;
}
static std::string unEscapeChar(const std::string& _value) {
static etk::String unEscapeChar(const etk::String& _value) {
return _value;
}
static std::string removeStartAndStopSpace(const std::string& _value) {
std::string out;
static etk::String removeStartAndStopSpace(const etk::String& _value) {
etk::String out;
out.reserve(_value.size());
bool findSpace = false;
for (auto &it : _value) {
@ -36,7 +36,7 @@ static std::string removeStartAndStopSpace(const std::string& _value) {
return out;
}
static std::map<enet::HTTPAnswerCode, std::string> protocolName = {
static etk::Map<enet::HTTPAnswerCode, etk::String> protocolName = {
{enet::HTTPAnswerCode::c100_continue, "Continue"},
{enet::HTTPAnswerCode::c101_switchingProtocols, "Switching Protocols"},
{enet::HTTPAnswerCode::c103_checkpoint, "Checkpoint"},
@ -84,14 +84,14 @@ static std::map<enet::HTTPAnswerCode, std::string> protocolName = {
static std::map<int32_t, std::string> getErrorList() {
static std::map<int32_t, std::string> g_list;
static etk::Map<int32_t, etk::String> getErrorList() {
static etk::Map<int32_t, etk::String> g_list;
return g_list;
}
enet::Http::Http(enet::Tcp _connection, bool _isServer) :
m_isServer(_isServer),
m_connection(std::move(_connection)),
m_connection(etk::move(_connection)),
m_headerIsSend(false),
m_thread(nullptr),
m_threadRunning(false) {
@ -178,9 +178,9 @@ void enet::Http::stop(bool _inThreadStop){
}
/*
void enet::Http::writeAnswerHeader(enum enet::HTTPAnswerCode _value) {
std::string out;
etk::String out;
out = "HTTP/1.1 ";
out += etk::to_string(int32_t(_value));
out += etk::toString(int32_t(_value));
auto it = protocolName.find(_value);
if (it == protocolName.end() ) {
out += " ???";
@ -194,10 +194,10 @@ void enet::Http::writeAnswerHeader(enum enet::HTTPAnswerCode _value) {
*/
namespace etk {
template <>
bool from_string<enum enet::HTTPAnswerCode>(enum enet::HTTPAnswerCode& _variableRet, const std::string& _value) {
bool from_string<enum enet::HTTPAnswerCode>(enum enet::HTTPAnswerCode& _variableRet, const etk::String& _value) {
_variableRet = enet::HTTPAnswerCode::c000_unknow;
for (auto &it : protocolName) {
if (etk::to_string(int32_t(it.first)) == _value) {
if (etk::toString(int32_t(it.first)) == _value) {
_variableRet = it.first;
return true;
}
@ -205,11 +205,11 @@ namespace etk {
return false;
}
template <>
std::string to_string<enum enet::HTTPAnswerCode>(const enum enet::HTTPAnswerCode& _value) {
return etk::to_string(int32_t(_value));
etk::String toString<enum enet::HTTPAnswerCode>(const enum enet::HTTPAnswerCode& _value) {
return etk::toString(int32_t(_value));
}
template <>
bool from_string<enum enet::HTTPReqType>(enum enet::HTTPReqType& _variableRet, const std::string& _value) {
bool from_string<enum enet::HTTPReqType>(enum enet::HTTPReqType& _variableRet, const etk::String& _value) {
_variableRet = enet::HTTPReqType::HTTP_GET;
if (_value == "GET") {
_variableRet = enet::HTTPReqType::HTTP_GET;
@ -230,7 +230,7 @@ namespace etk {
return false;
}
template <>
std::string to_string<enum enet::HTTPReqType>(const enum enet::HTTPReqType& _value) {
etk::String toString<enum enet::HTTPReqType>(const enum enet::HTTPReqType& _value) {
switch (_value) {
case enet::HTTPReqType::HTTP_GET: return "GET";
case enet::HTTPReqType::HTTP_HEAD: return "HEAD";
@ -241,7 +241,7 @@ namespace etk {
return "UNKNOW";
}
template <>
bool from_string<enum enet::HTTPProtocol>(enum enet::HTTPProtocol& _variableRet, const std::string& _value) {
bool from_string<enum enet::HTTPProtocol>(enum enet::HTTPProtocol& _variableRet, const etk::String& _value) {
_variableRet = enet::HTTPProtocol::http_0_1;
if (_value == "HTTP/0.1") { _variableRet = enet::HTTPProtocol::http_0_1; return true; }
if (_value == "HTTP/0.2") { _variableRet = enet::HTTPProtocol::http_0_2; return true; }
@ -289,7 +289,7 @@ namespace etk {
return false;
}
template <>
std::string to_string<enum enet::HTTPProtocol>(const enum enet::HTTPProtocol& _value) {
etk::String toString<enum enet::HTTPProtocol>(const enum enet::HTTPProtocol& _value) {
switch (_value) {
case enet::HTTPProtocol::http_0_1: return "HTTP/0.1";
case enet::HTTPProtocol::http_0_2: return "HTTP/0.2";
@ -345,7 +345,7 @@ void enet::Http::setRequestHeader(const enet::HttpRequest& _req) {
if (m_requestHeader.getKey("User-Agent") == "") {
m_requestHeader.setKey("User-Agent", "e-net (ewol network interface)");
}
std::string value = m_requestHeader.generate();
etk::String value = m_requestHeader.generate();
write(value, false);
}
@ -354,14 +354,14 @@ void enet::Http::setAnswerHeader(const enet::HttpAnswer& _req) {
if (m_requestHeader.getKey("User-Agent") == "") {
m_requestHeader.setKey("User-Agent", "e-net (ewol network interface)");
}
std::string value = m_answerHeader.generate();
etk::String value = m_answerHeader.generate();
write(value, false);
}
void enet::Http::getHeader() {
ENET_VERBOSE("Read HTTP Header [START]");
bool headerEnded = false;
std::string header;
etk::String header;
while (m_connection.getConnectionStatus() == enet::Tcp::status::link) {
char type = '?';
int32_t len = m_connection.read(&type, 1);
@ -396,7 +396,7 @@ void enet::Http::getHeader() {
ENET_VERBOSE("Read HTTP Header [STOP] : '" << header << "'");
m_headerIsSend = true;
// parse header :
std::vector<std::string> list = etk::split(header, '\n');
etk::Vector<etk::String> list = etk::split(header, '\n');
for (auto &it : list) {
if ( it.size()>0
&& it[it.size()-1] == '\r') {
@ -404,7 +404,7 @@ void enet::Http::getHeader() {
}
}
//parse first element:
std::vector<std::string> listLineOne = etk::split(list[0], ' ');
etk::Vector<etk::String> listLineOne = etk::split(list[0], ' ');
if (listLineOne.size() < 2) {
ENET_ERROR("can not parse answear : " << listLineOne);
// answer bad request and close connection ...
@ -459,7 +459,7 @@ void enet::Http::getHeader() {
m_answerHeader.setErrorCode(valueErrorCode);
// get comment:
std::string comment;
etk::String comment;
for (size_t iii=2; iii<listLineOne.size(); ++iii) {
if (comment.size() != 0) {
comment += " ";
@ -478,13 +478,13 @@ void enet::Http::getHeader() {
}
for (size_t iii=1; iii<list.size(); ++iii) {
size_t found = list[iii].find(":");
if (found == std::string::npos) {
if (found == etk::String::npos) {
// nothing
continue;
}
std::string key = unEscapeChar(std::string(list[iii], 0, found));
etk::String key = unEscapeChar(etk::String(list[iii], 0, found));
key = removeStartAndStopSpace(key);
std::string value = unEscapeChar(std::string(list[iii], found+2));
etk::String value = unEscapeChar(etk::String(list[iii], found+2));
value = removeStartAndStopSpace(value);
ENET_VERBOSE("header : key='" << key << "' value='" << value << "'");
if (m_isServer == false) {
@ -511,9 +511,9 @@ void enet::Http::getHeader() {
/*
bool enet::Http::get(const std::string& _address) {
bool enet::Http::get(const etk::String& _address) {
m_header.m_map.clear();
std::string req = "GET http://" + m_connection.getName();
etk::String req = "GET http://" + m_connection.getName();
if (_address != "") {
req += "/";
req += _address;
@ -538,10 +538,10 @@ bool enet::Http::get(const std::string& _address) {
return false;
}
bool enet::Http::post(const std::string& _address, const std::map<std::string, std::string>& _values) {
bool enet::Http::post(const etk::String& _address, const etk::Map<etk::String, etk::String>& _values) {
m_header.m_map.clear();
// First create body :
std::string body;
etk::String body;
for (auto &it : _values) {
if (body.size() > 0) {
body += "&";
@ -551,16 +551,16 @@ bool enet::Http::post(const std::string& _address, const std::map<std::string, s
return post(_address, "application/x-www-form-urlencoded", body);
}
bool enet::Http::post(const std::string& _address, const std::string& _contentType, const std::string& _data) {
bool enet::Http::post(const etk::String& _address, const etk::String& _contentType, const etk::String& _data) {
m_header.m_map.clear();
std::string req = "POST http://" + m_connection.getName();
etk::String req = "POST http://" + m_connection.getName();
if (_address != "") {
req += "/";
req += _address;
}
req += " HTTP/1.0\n";
setSendHeaderProperties("Content-Type", _contentType);
setSendHeaderProperties("Content-Length", etk::to_string(_data.size()));
setSendHeaderProperties("Content-Length", etk::toString(_data.size()));
// add header properties :
for (auto &it : m_header.m_map) {
req += escapeChar(it.first) + ": " + escapeChar(it.second) + "\r\n";
@ -585,7 +585,7 @@ int32_t enet::Http::write(const void* _data, int32_t _len) {
}
void enet::HttpHeader::setKey(const std::string& _key, const std::string& _value) {
void enet::HttpHeader::setKey(const etk::String& _key, const etk::String& _value) {
auto it = m_map.find(_key);
if (it == m_map.end()) {
m_map.insert(make_pair(_key, _value));
@ -594,14 +594,14 @@ void enet::HttpHeader::setKey(const std::string& _key, const std::string& _value
}
}
void enet::HttpHeader::rmKey(const std::string& _key) {
void enet::HttpHeader::rmKey(const etk::String& _key) {
auto it = m_map.find(_key);
if (it != m_map.end()) {
m_map.erase(it);
}
}
std::string enet::HttpHeader::getKey(const std::string& _key) const {
etk::String enet::HttpHeader::getKey(const etk::String& _key) const {
auto it = m_map.find(_key);
if (it != m_map.end()) {
return it->second;
@ -609,8 +609,8 @@ std::string enet::HttpHeader::getKey(const std::string& _key) const {
return "";
}
std::string enet::HttpHeader::generateKeys() const {
std::string out;
etk::String enet::HttpHeader::generateKeys() const {
etk::String out;
for (auto &it : m_map) {
if ( it.first != ""
&& it.second != "") {
@ -629,7 +629,7 @@ enet::HttpHeader::HttpHeader():
// -----------------------------------------------------------------------------------------
enet::HttpAnswer::HttpAnswer(enum HTTPAnswerCode _code, const std::string& _help):
enet::HttpAnswer::HttpAnswer(enum HTTPAnswerCode _code, const etk::String& _help):
m_what(_code),
m_helpMessage(_help) {
@ -649,11 +649,11 @@ void enet::HttpAnswer::display() const {
}
}
std::string enet::HttpAnswer::generate() const {
std::string out;
out += etk::to_string(m_protocol);
etk::String enet::HttpAnswer::generate() const {
etk::String out;
out += etk::toString(m_protocol);
out += " ";
out += etk::to_string(int32_t(m_what));
out += etk::toString(int32_t(m_what));
out += " ";
if (m_helpMessage != "") {
out += escapeChar(m_helpMessage);
@ -671,12 +671,12 @@ std::string enet::HttpAnswer::generate() const {
return out;
}
enet::HttpServer::HttpServer(enet::Tcp _connection) :
enet::Http(std::move(_connection), true) {
enet::Http(etk::move(_connection), true) {
}
enet::HttpClient::HttpClient(enet::Tcp _connection) :
enet::Http(std::move(_connection), false) {
enet::Http(etk::move(_connection), false) {
}
// -----------------------------------------------------------------------------------------
@ -701,13 +701,13 @@ void enet::HttpRequest::display() const {
}
}
std::string enet::HttpRequest::generate() const {
std::string out;
out += etk::to_string(m_req);
etk::String enet::HttpRequest::generate() const {
etk::String out;
out += etk::toString(m_req);
out += " ";
out += m_uri;
out += " ";
out += etk::to_string(m_protocol);
out += etk::toString(m_protocol);
out += "\r\n";
out += generateKeys();
out += "\r\n";
@ -715,17 +715,17 @@ std::string enet::HttpRequest::generate() const {
}
std::ostream& enet::operator <<(std::ostream& _os, enum enet::HTTPProtocol _obj) {
_os << "enet::HTTPProtocol::" <<etk::to_string(_obj);
etk::Stream& enet::operator <<(etk::Stream& _os, enum enet::HTTPProtocol _obj) {
_os << "enet::HTTPProtocol::" <<etk::toString(_obj);
return _os;
}
std::ostream& enet::operator <<(std::ostream& _os, enum enet::HTTPAnswerCode _obj) {
_os << "enet::HTTPAnswerCode::" << etk::to_string(_obj);
etk::Stream& enet::operator <<(etk::Stream& _os, enum enet::HTTPAnswerCode _obj) {
_os << "enet::HTTPAnswerCode::" << etk::toString(_obj);
return _os;
}
std::ostream& enet::operator <<(std::ostream& _os, enum enet::HTTPReqType _obj) {
_os << "enet::HTTPReqType::" << etk::to_string(_obj);
etk::Stream& enet::operator <<(etk::Stream& _os, enum enet::HTTPReqType _obj) {
_os << "enet::HTTPReqType::" << etk::toString(_obj);
return _os;
}

View File

@ -6,8 +6,8 @@
#pragma once
#include <enet/Tcp.hpp>
#include <vector>
#include <map>
#include <etk/Vector.hpp>
#include <etk/Map.hpp>
#include <thread>
#include <ethread/tools.hpp>
#include <functional>
@ -64,7 +64,7 @@ namespace enet {
c505_httpVersionNotSupported, //!< The server does not support the HTTP protocol version used in the request
c511_networkAuthenticationRequired, //!< The client needs to authenticate to gain network access
};
std::ostream& operator <<(std::ostream& _os, enum enet::HTTPAnswerCode _obj);
etk::Stream& operator <<(etk::Stream& _os, enum enet::HTTPAnswerCode _obj);
enum class HTTPProtocol {
http_0_1,
@ -111,18 +111,18 @@ namespace enet {
http_3_9,
http_3_10,
};
std::ostream& operator <<(std::ostream& _os, enum enet::HTTPProtocol _obj);
etk::Stream& operator <<(etk::Stream& _os, enum enet::HTTPProtocol _obj);
class HttpHeader {
protected:
// key, val
std::map<std::string, std::string> m_map;
etk::Map<etk::String, etk::String> m_map;
enum HTTPProtocol m_protocol;
public:
void setKey(const std::string& _key, const std::string& _value);
void rmKey(const std::string& _key);
std::string getKey(const std::string& _key) const;
void setKey(const etk::String& _key, const etk::String& _value);
void rmKey(const etk::String& _key);
etk::String getKey(const etk::String& _key) const;
protected:
std::string generateKeys() const;
etk::String generateKeys() const;
public:
enum HTTPProtocol getProtocol() const {
return m_protocol;
@ -132,27 +132,27 @@ namespace enet {
}
HttpHeader();
virtual ~HttpHeader() = default;
virtual std::string generate() const = 0;
virtual etk::String generate() const = 0;
};
class HttpAnswer : public HttpHeader {
private:
enet::HTTPAnswerCode m_what;
std::string m_helpMessage;
etk::String m_helpMessage;
public:
HttpAnswer(enum HTTPAnswerCode _code = enet::HTTPAnswerCode::c400_badRequest, const std::string& _help="");
HttpAnswer(enum HTTPAnswerCode _code = enet::HTTPAnswerCode::c400_badRequest, const etk::String& _help="");
void display() const;
std::string generate() const;
etk::String generate() const;
void setErrorCode(enum HTTPAnswerCode _value) {
m_what = _value;
}
enum HTTPAnswerCode getErrorCode() const {
return m_what;
}
void setHelp(const std::string& _value) {
void setHelp(const etk::String& _value) {
m_helpMessage = _value;
}
const std::string& getHelp() const {
const etk::String& getHelp() const {
return m_helpMessage;
}
};
@ -163,26 +163,26 @@ namespace enet {
HTTP_PUT,
HTTP_DELETE,
};
std::ostream& operator <<(std::ostream& _os, enum enet::HTTPReqType _obj);
etk::Stream& operator <<(etk::Stream& _os, enum enet::HTTPReqType _obj);
class HttpRequest : public HttpHeader {
private:
// key, val
enum HTTPReqType m_req;
std::string m_uri;
etk::String m_uri;
public:
HttpRequest(enum enet::HTTPReqType _type=enet::HTTPReqType::HTTP_GET);
void display() const;
std::string generate() const;
etk::String generate() const;
void setType(enum enet::HTTPReqType _value) {
m_req = _value;
}
enum enet::HTTPReqType getType() const{
return m_req;
}
void setUri(const std::string& _value) {
void setUri(const etk::String& _value) {
m_uri = _value;
}
const std::string& getUri() const {
const etk::String& getUri() const {
return m_uri;
}
};
@ -218,7 +218,7 @@ namespace enet {
bool m_headerIsSend;
std::thread* m_thread;
bool m_threadRunning;
std::vector<uint8_t> m_temporaryBuffer;
etk::Vector<uint8_t> m_temporaryBuffer;
private:
void threadCallback();
private:
@ -230,7 +230,7 @@ namespace enet {
return m_connection.getConnectionStatus() == enet::Tcp::status::link;
}
public:
using Observer = std::function<void(std::vector<uint8_t>&)>; //!< Define an Observer: function pointer
using Observer = std::function<void(etk::Vector<uint8_t>&)>; //!< Define an Observer: function pointer
Observer m_observer;
/**
* @brief Connect an function member on the signal with the shared_ptr object.
@ -239,8 +239,8 @@ namespace enet {
* @param[in] _args Argument optinnal the user want to add.
*/
template<class CLASS_TYPE>
void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(std::vector<uint8_t>&)) {
m_observer = [=](std::vector<uint8_t>& _value){
void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(etk::Vector<uint8_t>&)) {
m_observer = [=](etk::Vector<uint8_t>& _value){
(*_class.*_func)(_value);
};
}
@ -289,7 +289,7 @@ namespace enet {
* @return >0 byte size on the socket write
* @return -1 an error occured.
*/
int32_t write(const std::string& _data, bool _writeBackSlashZero = true) {
int32_t write(const etk::String& _data, bool _writeBackSlashZero = true) {
if (_data.size() == 0) {
return 0;
}
@ -306,7 +306,7 @@ namespace enet {
* @return -1 an error occured.
*/
template <class T>
int32_t write(const std::vector<T>& _data) {
int32_t write(const etk::Vector<T>& _data) {
if (_data.size() == 0) {
return 0;
}
@ -326,9 +326,9 @@ namespace enet {
setRequestHeader(_header);
}
public:
//bool get(const std::string& _address);
//bool post(const std::string& _address, const std::map<std::string, std::string>& _values);
//bool post(const std::string& _address, const std::string& _contentType, const std::string& _data);
//bool get(const etk::String& _address);
//bool post(const etk::String& _address, const etk::Map<etk::String, etk::String>& _values);
//bool post(const etk::String& _address, const etk::String& _contentType, const etk::String& _data);
public:
/**
* @brief Connect an function member on the signal with the shared_ptr object.

View File

@ -51,15 +51,15 @@ enet::Tcp::Tcp() :
}
#ifdef __TARGET_OS__Windows
enet::Tcp::Tcp(SOCKET _idSocket, const std::string& _name) :
enet::Tcp::Tcp(SOCKET _idSocket, const etk::String& _name) :
#else
enet::Tcp::Tcp(int32_t _idSocket, const std::string& _name) :
enet::Tcp::Tcp(int32_t _idSocket, const etk::String& _name) :
#endif
m_socketId(_idSocket),
m_name(_name),
m_status(status::link) {
#ifdef ENET_STORE_INPUT
m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::to_string(baseID++) + ".tcp");
m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::toString(baseID++) + ".tcp");
m_nodeStoreInput.fileOpenWrite();
#endif
}
@ -69,7 +69,7 @@ enet::Tcp::Tcp(Tcp&& _obj) :
m_name(_obj.m_name),
m_status(_obj.m_status) {
#ifdef ENET_STORE_INPUT
m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::to_string(baseID++) + ".tcp");
m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::toString(baseID++) + ".tcp");
m_nodeStoreInput.fileOpenWrite();
#endif
#ifdef __TARGET_OS__Windows
@ -88,7 +88,7 @@ enet::Tcp::~Tcp() {
enet::Tcp& enet::Tcp::operator = (enet::Tcp&& _obj) {
unlink();
#ifdef ENET_STORE_INPUT
m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::to_string(baseID++) + ".tcp");
m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::toString(baseID++) + ".tcp");
m_nodeStoreInput.fileOpenWrite();
#endif
m_socketId = _obj.m_socketId;

View File

@ -34,9 +34,9 @@ namespace enet {
public:
Tcp();
#ifdef __TARGET_OS__Windows
Tcp(SOCKET _idSocket, const std::string& _name);
Tcp(SOCKET _idSocket, const etk::String& _name);
#else
Tcp(int32_t _idSocket, const std::string& _name);
Tcp(int32_t _idSocket, const etk::String& _name);
#endif
// move constructor
Tcp(Tcp&& _obj);
@ -46,13 +46,13 @@ namespace enet {
Tcp& operator= (Tcp& _obj) = delete;
virtual ~Tcp();
private:
std::string m_name; //!< hostname/IP:port.
etk::String m_name; //!< hostname/IP:port.
public:
/**
* @brief Get the decriptive name hot the host:port
* @return the string requested
*/
const std::string& getName() {
const etk::String& getName() {
return m_name;
}
public:
@ -102,7 +102,7 @@ namespace enet {
* @return >0 byte size on the socket write
* @return -1 an error occured.
*/
int32_t write(const std::string& _data, bool _writeBackSlashZero = true) {
int32_t write(const etk::String& _data, bool _writeBackSlashZero = true) {
if (_data.size() == 0) {
return 0;
}
@ -119,7 +119,7 @@ namespace enet {
* @return -1 an error occured.
*/
template <class T>
int32_t write(const std::vector<T>& _data) {
int32_t write(const etk::Vector<T>& _data) {
if (_data.size() == 0) {
return 0;
}

View File

@ -24,26 +24,26 @@
#endif
enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) {
std::string tmpname;
tmpname = etk::to_string(_ip1);
etk::String tmpname;
tmpname = etk::toString(_ip1);
tmpname += ".";
tmpname += etk::to_string(_ip2);
tmpname += etk::toString(_ip2);
tmpname += ".";
tmpname += etk::to_string(_ip3);
tmpname += etk::toString(_ip3);
tmpname += ".";
tmpname += etk::to_string(_ip4);
return std::move(enet::connectTcpClient(tmpname, _port, _numberRetry, _timeOut));
tmpname += etk::toString(_ip4);
return etk::move(enet::connectTcpClient(tmpname, _port, _numberRetry, _timeOut));
}
#ifdef __TARGET_OS__Windows
enet::Tcp enet::connectTcpClient(const std::string& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) {
enet::Tcp enet::connectTcpClient(const etk::String& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) {
if (enet::isInit() == false) {
ENET_ERROR("Need call enet::init(...) before accessing to the socket");
return std::move(enet::Tcp());
return etk::move(enet::Tcp());
}
if (_hostname == "") {
ENET_ERROR("get connection wihtout hostname");
return std::move(enet::Tcp());
return etk::move(enet::Tcp());
}
SOCKET socketId = INVALID_SOCKET;
ENET_INFO("Start connection on " << _hostname << ":" << _port);
@ -67,7 +67,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8
// Resolve the server address and port
struct addrinfo* result = nullptr;
std::string portValue = etk::to_string(_port);
etk::String portValue = etk::toString(_port);
int iResult = getaddrinfo(_hostname.c_str(), portValue.c_str(), &hints, &result);
if (iResult != 0) {
ENET_ERROR("getaddrinfo failed with error: " << iResult);
@ -106,21 +106,21 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8
}
if (socketId == INVALID_SOCKET) {
ENET_ERROR("ERROR connecting ... (after all try)");
return std::move(enet::Tcp());
return etk::move(enet::Tcp());
}
ENET_DEBUG("Connection done");
return std::move(enet::Tcp(socketId, _hostname + ":" + etk::to_string(_port)));
return etk::move(enet::Tcp(socketId, _hostname + ":" + etk::toString(_port)));
}
#else
#include <sys/socket.h>
enet::Tcp enet::connectTcpClient(const std::string& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) {
enet::Tcp enet::connectTcpClient(const etk::String& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) {
if (enet::isInit() == false) {
ENET_ERROR("Need call enet::init(...) before accessing to the socket");
return std::move(enet::Tcp());
return etk::move(enet::Tcp());
}
if (_hostname == "") {
ENET_ERROR("get connection wihtout hostname");
return std::move(enet::Tcp());
return etk::move(enet::Tcp());
}
int32_t socketId = -1;
ENET_INFO("Start connection on " << _hostname << ":" << _port);
@ -147,7 +147,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8
addr.s_addr = inet_addr(_hostname.c_str());
if (addr.s_addr == INADDR_NONE) {
ENET_ERROR("The IPv4 address entered must be a legal address" << _hostname.c_str());
return std::move(enet::Tcp());
return etk::move(enet::Tcp());
} else {
// TODO : This is deprecated use getaddrinfo like windows ...
server = gethostbyaddr((char *) &addr, 4, AF_INET);
@ -183,10 +183,10 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8
}
if (socketId<0) {
ENET_ERROR("ERROR connecting ... (after all try)");
return std::move(enet::Tcp());
return etk::move(enet::Tcp());
}
ENET_INFO("Connection done");
return std::move(enet::Tcp(socketId, _hostname + ":" + etk::to_string(_port)));
return etk::move(enet::Tcp(socketId, _hostname + ":" + etk::toString(_port)));
}
#endif

View File

@ -10,5 +10,5 @@
namespace enet {
enet::Tcp connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry=5, echrono::Duration _timeOut = echrono::seconds(1));
enet::Tcp connectTcpClient(const std::string& _hostname, uint16_t _port, uint32_t _numberRetry=5, echrono::Duration _timeOut = echrono::seconds(1));
enet::Tcp connectTcpClient(const etk::String& _hostname, uint16_t _port, uint32_t _numberRetry=5, echrono::Duration _timeOut = echrono::seconds(1));
}

View File

@ -37,18 +37,18 @@ enet::TcpServer::~TcpServer() {
}
void enet::TcpServer::setIpV4(uint8_t _fist, uint8_t _second, uint8_t _third, uint8_t _quatro) {
std::string tmpname;
tmpname = etk::to_string(_fist);
etk::String tmpname;
tmpname = etk::toString(_fist);
tmpname += ".";
tmpname += etk::to_string(_second);
tmpname += etk::toString(_second);
tmpname += ".";
tmpname += etk::to_string(_third);
tmpname += etk::toString(_third);
tmpname += ".";
tmpname += etk::to_string(_quatro);
tmpname += etk::toString(_quatro);
setHostNane(tmpname);
}
void enet::TcpServer::setHostNane(const std::string& _name) {
void enet::TcpServer::setHostNane(const etk::String& _name) {
if (_name == m_host) {
return;
}
@ -79,7 +79,7 @@ void enet::TcpServer::setPort(uint16_t _port) {
hints.ai_flags = AI_PASSIVE;
// Resolve the server address and port
std::string portValue = etk::to_string(m_port);
etk::String portValue = etk::toString(m_port);
int iResult = getaddrinfo(nullptr, portValue.c_str(), &hints, &result);
if (iResult != 0) {
ENET_ERROR("getaddrinfo failed with error: " << iResult);
@ -153,7 +153,7 @@ void enet::TcpServer::setPort(uint16_t _port) {
enet::Tcp enet::TcpServer::waitNext() {
if (enet::isInit() == false) {
ENET_ERROR("Need call enet::init(...) before accessing to the socket");
return std::move(enet::Tcp());
return etk::move(enet::Tcp());
}
ENET_INFO("End binding Socket ... (start listen)");
#ifdef __TARGET_OS__Windows
@ -182,7 +182,7 @@ enet::Tcp enet::TcpServer::waitNext() {
return enet::Tcp();
}
ENET_INFO("End configuring Socket ... Find New one");
return enet::Tcp(socketIdClient, m_host + ":" + etk::to_string(m_port));
return enet::Tcp(socketIdClient, m_host + ":" + etk::toString(m_port));
}

View File

@ -26,7 +26,7 @@ namespace enet {
TcpServer();
virtual ~TcpServer();
private:
std::string m_host; //!< hostname/IP to connect with.
etk::String m_host; //!< hostname/IP to connect with.
public:
/**
* @brief Set the connection IP id.
@ -40,12 +40,12 @@ namespace enet {
* @brief set the Host name is the same things as set an Ip adress, but in test mode "127.0.0.1" or "localhost".
* @param[in] _name Host name to connect.
*/
void setHostNane(const std::string& _name);
void setHostNane(const etk::String& _name);
/**
* @brief Get the decriptive name hot the host
* @return the string requested
*/
const std::string& getHostName() {
const etk::String& getHostName() {
return m_host;
}
private:

View File

@ -6,7 +6,7 @@
#include <enet/debug.hpp>
#include <enet/WebSocket.hpp>
#include <map>
#include <etk/Map.hpp>
#include <etk/stdTools.hpp>
#include <cstring>
#include <random>
@ -40,19 +40,19 @@ enet::WebSocket::WebSocket(enet::Tcp _connection, bool _isServer) :
m_interface(nullptr),
m_observer(nullptr),
m_observerUriCheck(nullptr) {
setInterface(std::move(_connection), _isServer);
setInterface(etk::move(_connection), _isServer);
}
void enet::WebSocket::setInterface(enet::Tcp _connection, bool _isServer) {
_connection.setTCPNoDelay(true);
if (_isServer == true) {
ememory::SharedPtr<enet::HttpServer> interface = ememory::makeShared<enet::HttpServer>(std::move(_connection));
ememory::SharedPtr<enet::HttpServer> interface = ememory::makeShared<enet::HttpServer>(etk::move(_connection));
m_interface = interface;
if (interface != nullptr) {
interface->connectHeader(this, &enet::WebSocket::onReceiveRequest);
}
} else {
ememory::SharedPtr<enet::HttpClient> interface = ememory::makeShared<enet::HttpClient>(std::move(_connection));
ememory::SharedPtr<enet::HttpClient> interface = ememory::makeShared<enet::HttpClient>(etk::move(_connection));
m_interface = interface;
if (interface != nullptr) {
interface->connectHeader(this, &enet::WebSocket::onReceiveAnswer);
@ -72,7 +72,7 @@ enet::WebSocket::~WebSocket() {
stop(true);
}
static std::string generateKey() {
static etk::String generateKey() {
// create dynamic key:
std::random_device rd;
std::mt19937 e2(rd());
@ -84,13 +84,13 @@ static std::string generateKey() {
return algue::base64::encode(dataKey, 16);
}
static std::string generateCheckKey(const std::string& _key) {
std::string out = _key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
std::vector<uint8_t> keyData = algue::sha1::encode(out);
static etk::String generateCheckKey(const etk::String& _key) {
etk::String out = _key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
etk::Vector<uint8_t> keyData = algue::sha1::encode(out);
return algue::base64::encode(keyData);
}
void enet::WebSocket::start(const std::string& _uri, const std::vector<std::string>& _listProtocols) {
void enet::WebSocket::start(const etk::String& _uri, const etk::Vector<etk::String>& _listProtocols) {
if (m_interface == nullptr) {
ENET_ERROR("Nullptr interface ...");
return;
@ -108,7 +108,7 @@ void enet::WebSocket::start(const std::string& _uri, const std::vector<std::stri
req.setKey("Sec-WebSocket-Version", "13");
req.setKey("Pragma", "no-cache");
req.setKey("Cache-Control", "no-cache");
std::string protocolList;
etk::String protocolList;
for (auto &it : _listProtocols) {
if (it == "") {
continue;
@ -307,8 +307,8 @@ void enet::WebSocket::onReceiveData(enet::Tcp& _connection) {
ENET_ERROR("ReadRaw [STOP] (no opcode manage ... " << int32_t(opcode & 0x0F));
}
static std::string removeStartAndStopSpace(const std::string& _value) {
std::string out;
static etk::String removeStartAndStopSpace(const etk::String& _value) {
etk::String out;
out.reserve(_value.size());
bool findSpace = false;
for (auto &it : _value) {
@ -366,7 +366,7 @@ void enet::WebSocket::onReceiveRequest(const enet::HttpRequest& _data) {
return;
}
// parse all protocols:
std::vector<std::string> listProtocol;
etk::Vector<etk::String> listProtocol;
if (_data.getKey("Sec-WebSocket-Protocol") != "") {
listProtocol = etk::split(_data.getKey("Sec-WebSocket-Protocol"),',');
for (size_t iii=0; iii<listProtocol.size(); ++iii) {
@ -388,7 +388,7 @@ void enet::WebSocket::onReceiveRequest(const enet::HttpRequest& _data) {
answer.setProtocol(enet::HTTPProtocol::http_1_1);
answer.setKey("Upgrade", "websocket");
answer.setKey("Connection", "Upgrade");
std::string answerKey = generateCheckKey(_data.getKey("Sec-WebSocket-Key"));
etk::String answerKey = generateCheckKey(_data.getKey("Sec-WebSocket-Key"));
answer.setKey("Sec-WebSocket-Accept", answerKey);
if (m_protocol != "") {
answer.setKey("Sec-WebSocket-Protocol", m_protocol);

View File

@ -8,17 +8,17 @@
#include <enet/Http.hpp>
#include <ememory/memory.hpp>
#include <echrono/Steady.hpp>
#include <vector>
#include <map>
#include <etk/Vector.hpp>
#include <etk/Map.hpp>
namespace enet {
class WebSocket {
protected:
std::vector<uint8_t> m_sendBuffer;
etk::Vector<uint8_t> m_sendBuffer;
bool m_connectionValidate;
ememory::SharedPtr<enet::Http> m_interface;
std::vector<uint8_t> m_buffer;
std::string m_checkKey;
etk::Vector<uint8_t> m_buffer;
etk::String m_checkKey;
echrono::Steady m_lastReceive;
echrono::Steady m_lastSend;
std::mutex m_mutex;
@ -34,7 +34,7 @@ namespace enet {
WebSocket(enet::Tcp _connection, bool _isServer=false);
void setInterface(enet::Tcp _connection, bool _isServer=false);
virtual ~WebSocket();
void start(const std::string& _uri="", const std::vector<std::string>& _listProtocols=std::vector<std::string>());
void start(const etk::String& _uri="", const etk::Vector<etk::String>& _listProtocols=etk::Vector<etk::String>());
void stop(bool _inThread=false);
bool isAlive() const {
if (m_interface == nullptr) {
@ -46,13 +46,13 @@ namespace enet {
void onReceiveRequest(const enet::HttpRequest& _data);
void onReceiveAnswer(const enet::HttpAnswer& _data);
protected:
std::string m_protocol;
etk::String m_protocol;
public:
void setProtocol(const std::string& _protocol) {
void setProtocol(const etk::String& _protocol) {
m_protocol = _protocol;
}
public:
using Observer = std::function<void(std::vector<uint8_t>&, bool)>; //!< Define an Observer: function pointer
using Observer = std::function<void(etk::Vector<uint8_t>&, bool)>; //!< Define an Observer: function pointer
protected:
Observer m_observer;
public:
@ -63,8 +63,8 @@ namespace enet {
* @param[in] _args Argument optinnal the user want to add.
*/
template<class CLASS_TYPE>
void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(std::vector<uint8_t>&, bool)) {
m_observer = [=](std::vector<uint8_t>& _value, bool _isString){
void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(etk::Vector<uint8_t>&, bool)) {
m_observer = [=](etk::Vector<uint8_t>& _value, bool _isString){
(*_class.*_func)(_value, _isString);
};
}
@ -73,7 +73,7 @@ namespace enet {
}
// Only server:
public:
using ObserverUriCheck = std::function<bool(const std::string&, const std::vector<std::string>&)>; //!< Define an Observer: function pointer
using ObserverUriCheck = std::function<bool(const etk::String&, const etk::Vector<etk::String>&)>; //!< Define an Observer: function pointer
protected:
ObserverUriCheck m_observerUriCheck;
public:
@ -84,8 +84,8 @@ namespace enet {
* @param[in] _args Argument optinnal the user want to add.
*/
template<class CLASS_TYPE>
void connectUri(CLASS_TYPE* _class, bool (CLASS_TYPE::*_func)(const std::string&, const std::vector<std::string>&)) {
m_observerUriCheck = [=](const std::string& _value, const std::vector<std::string>& _protocols){
void connectUri(CLASS_TYPE* _class, bool (CLASS_TYPE::*_func)(const etk::String&, const etk::Vector<etk::String>&)) {
m_observerUriCheck = [=](const etk::String& _value, const etk::Vector<etk::String>& _protocols){
return (*_class.*_func)(_value, _protocols);
};
}
@ -98,7 +98,7 @@ namespace enet {
uint8_t m_dataMask[4];
public:
std::unique_lock<std::mutex> getScopeLock() {
return std::move(std::unique_lock<std::mutex>(m_mutex));
return etk::move(std::unique_lock<std::mutex>(m_mutex));
}
/**
* Compose the local header inside a temporary buffer ==> must lock external to prevent multiple simultaneous access
@ -128,7 +128,7 @@ namespace enet {
* @return >0 byte size on the socket write
* @return -1 an error occured.
*/
int32_t write(const std::string& _data, bool _writeBackSlashZero = true) {
int32_t write(const etk::String& _data, bool _writeBackSlashZero = true) {
if (_data.size() == 0) {
return 0;
}
@ -145,7 +145,7 @@ namespace enet {
* @return -1 an error occured.
*/
template <class T>
int32_t write(const std::vector<T>& _data) {
int32_t write(const etk::Vector<T>& _data) {
if (_data.size() == 0) {
return 0;
}

View File

@ -19,7 +19,7 @@ static bool& getInitSatatus() {
void enet::init(int _argc, const char** _argv) {
for (int32_t iii=0; iii<_argc; ++iii) {
std::string value = _argv[iii];
etk::String value = _argv[iii];
if (etk::start_with(value, "--enet") == true) {
ENET_ERROR("Unknow parameter type: '" << value << "'");
}

View File

@ -15,7 +15,7 @@
namespace appl {
void onReceiveData(std::vector<uint8_t>& _data) {
void onReceiveData(etk::Vector<uint8_t>& _data) {
TEST_INFO("Receive Datas : " << _data.size() << " bytes");
TEST_INFO("data:" << (char*)&_data[0] << "");
}
@ -25,7 +25,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
etk::String data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -38,11 +38,11 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("== Test HTTP client ==");
TEST_INFO("==================================");
// connect on TCP server:
enet::Tcp tcpConnection = std::move(enet::connectTcpClient("127.0.0.1", 12345));
enet::Tcp tcpConnection = etk::move(enet::connectTcpClient("127.0.0.1", 12345));
// TODO : Check if connection is valid ...
// Create a HTTP connection in Client mode
enet::HttpClient connection(std::move(tcpConnection));
enet::HttpClient connection(etk::move(tcpConnection));
// Set callbacks:
connection.connect(appl::onReceiveData);

View File

@ -16,7 +16,7 @@
namespace appl {
void onReceiveData(std::vector<uint8_t>& _data, bool _isString) {
void onReceiveData(etk::Vector<uint8_t>& _data, bool _isString) {
TEST_INFO("Receive Datas : " << _data.size() << " bytes");
if (_isString == true) {
_data.resize(_data.size()+1);
@ -32,7 +32,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
etk::String data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -45,19 +45,19 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("== Test WebSocket client ==");
TEST_INFO("==================================");
// connect on TCP server:
enet::Tcp tcpConnection = std::move(enet::connectTcpClient("127.0.0.1", 12345));
enet::Tcp tcpConnection = etk::move(enet::connectTcpClient("127.0.0.1", 12345));
// TODO : Check if connection is valid ...
// Create a HTTP connection in Client mode
enet::WebSocket connection(std::move(tcpConnection), false);
enet::WebSocket connection(etk::move(tcpConnection), false);
// Set callbacks:
connection.connect(appl::onReceiveData);
// start http connection (the actual state is just TCP start ...)
std::vector<std::string> protocols;
protocols.push_back("test1526/1.0");
protocols.push_back("test1526/1.5");
protocols.push_back("Hello");
etk::Vector<etk::String> protocols;
protocols.pushBack("test1526/1.0");
protocols.pushBack("test1526/1.5");
protocols.pushBack("Hello");
connection.start("/plop.txt", protocols);
// send some data to play ...

View File

@ -17,7 +17,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
etk::String data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -31,7 +31,7 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("==================================");
// client mode ...
// connect on TCP server:
enet::Tcp connection = std::move(enet::connectTcpClient("127.0.0.1", 12345));
enet::Tcp connection = etk::move(enet::connectTcpClient("127.0.0.1", 12345));
TEST_INFO("CLIENT connect ...");
if (connection.getConnectionStatus() != enet::Tcp::status::link) {
TEST_ERROR("can not link to the socket...");

View File

@ -14,7 +14,7 @@
#include <etk/stdTools.hpp>
namespace appl {
void onReceiveData(enet::HttpServer* _interface, std::vector<uint8_t>& _data) {
void onReceiveData(enet::HttpServer* _interface, etk::Vector<uint8_t>& _data) {
TEST_INFO("Receive Datas : " << _data.size() << " bytes");
}
void onReceiveHeader(enet::HttpServer* _interface, const enet::HttpRequest& _data) {
@ -23,8 +23,8 @@ namespace appl {
if (_data.getType() == enet::HTTPReqType::HTTP_GET) {
if (_data.getUri() == "plop.txt") {
enet::HttpAnswer answer(enet::HTTPAnswerCode::c200_ok);
std::string data = "<html><head></head></body>coucou</body></html>";
answer.setKey("Content-Length", etk::to_string(data.size()));
etk::String data = "<html><head></head></body>coucou</body></html>";
answer.setKey("Content-Length", etk::toString(data.size()));
_interface->setHeader(answer);
_interface->write(data);
_interface->stop(true);
@ -42,7 +42,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
etk::String data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -62,16 +62,16 @@ int main(int _argc, const char *_argv[]) {
// Start listening ...
interface.link();
// Wait a new connection ..
enet::Tcp tcpConnection = std::move(interface.waitNext());
enet::Tcp tcpConnection = etk::move(interface.waitNext());
// Free Connected port
interface.unlink();
// TODO : Check if connection is valid ...
// Create a HTTP connection in Server mode
enet::HttpServer connection(std::move(tcpConnection));
enet::HttpServer connection(etk::move(tcpConnection));
enet::HttpServer* tmp = &connection;
// Set callbacks:
connection.connect([=](std::vector<uint8_t>& _value){
connection.connect([=](etk::Vector<uint8_t>& _value){
appl::onReceiveData(tmp, _value);
});
connection.connectHeader([=](const enet::HttpRequest& _value){
@ -97,8 +97,8 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("----------------------------");
TEST_INFO("POST data : ");
std::map<std::string, std::string> values;
values.insert(std::make_pair<std::string, std::string>("plop", "valuePlop"));
etk::Map<etk::String, etk::String> values;
values.insert(etk::makePair<etk::String, etk::String>("plop", "valuePlop"));
if (connection.post("", values) == false) {
TEST_ERROR("can not POST data...");
return -1;
@ -107,7 +107,7 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("----------------------------");
TEST_INFO("POST xml : ");
if (connection.post("", "text/xml; charset=utf-8", "<plop><string>value1</string></plop>") == false) {
if (connection.post("", "text/xml; charset=utf-8", "<plop><etk/String.hpp>value1</string></plop>") == false) {
TEST_ERROR("can not POST XML data...");
return -1;
}

View File

@ -15,7 +15,7 @@
#include <etk/stdTools.hpp>
namespace appl {
void onReceiveData(enet::WebSocket* _interface, std::vector<uint8_t>& _data, bool _isString) {
void onReceiveData(enet::WebSocket* _interface, etk::Vector<uint8_t>& _data, bool _isString) {
TEST_INFO("Receive Datas : " << _data.size() << " bytes");
if (_isString == true) {
_data.resize(_data.size()+1);
@ -26,7 +26,7 @@ namespace appl {
TEST_INFO("binary data: ... ");
}
}
bool onReceiveUri(enet::WebSocket* _interface, const std::string& _uri, const std::vector<std::string>& _protocols) {
bool onReceiveUri(enet::WebSocket* _interface, const etk::String& _uri, const etk::Vector<etk::String>& _protocols) {
TEST_INFO("Receive Header uri: " << _uri);
for (auto &it : _protocols) {
if (it == "test1526/1.5") {
@ -45,7 +45,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
etk::String data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -65,19 +65,19 @@ int main(int _argc, const char *_argv[]) {
// Start listening ...
interface.link();
// Wait a new connection ..
enet::Tcp tcpConnection = std::move(interface.waitNext());
enet::Tcp tcpConnection = etk::move(interface.waitNext());
// Free Connected port
interface.unlink();
// TODO : Check if connection is valid ...
// Create a HTTP connection in Server mode
enet::WebSocket connection(std::move(tcpConnection), true);
enet::WebSocket connection(etk::move(tcpConnection), true);
enet::WebSocket* tmp = &connection;
// Set callbacks:
connection.connect([=](std::vector<uint8_t>& _value, bool _isString){
connection.connect([=](etk::Vector<uint8_t>& _value, bool _isString){
appl::onReceiveData(tmp, _value, _isString);
});
connection.connectUri([=](const std::string& _value, const std::vector<std::string>& _protocols){
connection.connectUri([=](const etk::String& _value, const etk::Vector<etk::String>& _protocols){
return appl::onReceiveUri(tmp, _value, _protocols);
});

View File

@ -17,7 +17,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii];
etk::String data = _argv[iii];
if ( data == "-h"
|| data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -37,13 +37,13 @@ int main(int _argc, const char *_argv[]) {
// Start listening ...
interface.link();
// Wait a new connection ..
enet::Tcp tcpConnection = std::move(interface.waitNext());
enet::Tcp tcpConnection = etk::move(interface.waitNext());
// Free Connected port
interface.unlink();
int32_t iii = 0;
while (tcpConnection.getConnectionStatus() == enet::Tcp::status::link) {
int32_t len = tcpConnection.write("plop" + etk::to_string(iii));
int32_t len = tcpConnection.write("plop" + etk::toString(iii));
TEST_INFO("write len=" << len);
char data[1024];
len = tcpConnection.read(data, 1024);