[DEV] continue removing STL

This commit is contained in:
Edouard DUPIN 2017-09-14 00:59:21 +02:00
parent 73c73ef1f5
commit cb097b3ce5
14 changed files with 49 additions and 52 deletions

View File

@ -6,4 +6,3 @@
#include <enet/debug.hpp>
#include <enet/Ftp.hpp>
#include <cstring>

View File

@ -8,7 +8,9 @@
#include <enet/Http.hpp>
#include <etk/Map.hpp>
#include <etk/stdTools.hpp>
#include <cstring>
extern "C" {
#include <string.h>
}
static etk::String escapeChar(const etk::String& _value) {
@ -147,7 +149,7 @@ void enet::Http::start() {
}
while ( m_threadRunning == true
&& m_connection.getConnectionStatus() != enet::Tcp::status::link) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
ethread::sleepMilliSeconds((50));
}
//ethread::setPriority(*m_receiveThread, -6);
ENET_DEBUG("connect [STOP]");
@ -366,7 +368,7 @@ void enet::Http::getHeader() {
char type = '?';
int32_t len = m_connection.read(&type, 1);
if (len == 0) {
std::this_thread::sleep_for(std::chrono::microseconds(1));
ethread::sleepMilliSeconds(1);
continue;
}
header += type;

View File

@ -10,7 +10,7 @@
#include <etk/Map.hpp>
#include <ethread/Thread.hpp>
#include <ethread/tools.hpp>
#include <functional>
#include <etk/Function.hpp>
namespace enet {
enum class HTTPAnswerCode {

View File

@ -7,9 +7,11 @@
#include <enet/debug.hpp>
#include <enet/Tcp.hpp>
#include <sys/types.h>
#include <cerrno>
#include <unistd.h>
#include <cstring>
extern "C" {
#include <errno.h>
#include <unistd.h>
#include <string.h>
}
#include <etk/stdTools.hpp>
#include <ethread/tools.hpp>
@ -112,13 +114,13 @@ bool enet::Tcp::unlink() {
#ifdef __TARGET_OS__Windows
shutdown(m_socketId, SD_BOTH);
// Release hand of the socket to permit the Select to exit ... ==> otherwise it lock ...
std::this_thread::sleep_for(std::chrono::milliseconds(20));
ethread::sleepMilliSeconds((20));
closesocket(m_socketId);
m_socketId = INVALID_SOCKET;
#else
shutdown(m_socketId, SHUT_RDWR);
// Release hand of the socket to permit the Select to exit ... ==> otherwise it lock ...
std::this_thread::sleep_for(std::chrono::milliseconds(20));
ethread::sleepMilliSeconds((20));
close(m_socketId);
m_socketId = -1;
#endif
@ -164,7 +166,7 @@ int32_t enet::Tcp::read(void* _data, int32_t _maxLen) {
// Receive data on this connection until the recv fails with EWOULDBLOCK.
// If any other failure occurs, we will close the connection.
{
std::unique_lock<ethread::Mutex> lock(m_mutex);
ethread::UniqueLock lock(m_mutex);
rc = recv(m_socketId, (char *)_data, _maxLen, 0);
}
if (rc < 0) {
@ -216,7 +218,7 @@ int32_t enet::Tcp::write(const void* _data, int32_t _len) {
//ENET_DEBUG("write on socketid = " << m_socketId << " data@=" << int64_t(_data) << " size=" << _len );
int32_t size;
{
std::unique_lock<ethread::Mutex> lock(m_mutex);
ethread::UniqueLock lock(m_mutex);
size = ::send(m_socketId, (const char *)_data, _len, 0);
}
if ( size != _len

View File

@ -7,7 +7,7 @@
#include <etk/types.hpp>
#include <ethread/Mutex.hpp>
#include <functional>
#include <etk/Function.hpp>
#ifdef __TARGET_OS__Windows
#include <winsock2.h>
#include <ws2tcpip.h>

View File

@ -8,10 +8,12 @@
#include <enet/Tcp.hpp>
#include <enet/TcpClient.hpp>
#include <enet/enet.hpp>
#include <sys/types.h>
#include <cerrno>
#include <unistd.h>
#include <cstring>
extern "C" {
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
}
#include <etk/stdTools.hpp>
#ifdef __TARGET_OS__Windows
@ -49,7 +51,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8
ENET_INFO("Start connection on " << _hostname << ":" << _port);
for(int32_t iii=0; iii<_numberRetry ;iii++) {
if (iii > 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
ethread::sleepMilliSeconds((200));
}
// open in Socket normal mode
socketId = socket(AF_INET, SOCK_STREAM, 0);
@ -126,7 +128,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8
ENET_INFO("Start connection on " << _hostname << ":" << _port);
for(int32_t iii=0; iii<_numberRetry ;iii++) {
if (iii > 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
ethread::sleepMilliSeconds((200));
}
// open in Socket normal mode
socketId = socket(AF_INET, SOCK_STREAM, 0);

View File

@ -8,10 +8,12 @@
#include <enet/Tcp.hpp>
#include <enet/TcpServer.hpp>
#include <enet/enet.hpp>
#include <sys/types.h>
#include <cerrno>
#include <unistd.h>
#include <cstring>
extern "C" {
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
}
#include <etk/stdTools.hpp>
#ifdef __TARGET_OS__Windows

View File

@ -8,8 +8,8 @@
#include <enet/WebSocket.hpp>
#include <etk/Map.hpp>
#include <etk/stdTools.hpp>
#include <cstring>
#include <random>
#include <etk/String.hpp>
#include <etk/tool.hpp>
#include <algue/base64.hpp>
#include <algue/sha1.hpp>
@ -74,12 +74,8 @@ enet::WebSocket::~WebSocket() {
static etk::String generateKey() {
// create dynamic key:
std::random_device rd;
std::mt19937 e2(rd());
std::uniform_real_distribution<> dist(0, 0xFF);
uint8_t dataKey[16];
for (size_t iii=0; iii<16; ++iii) {
dataKey[iii] = uint8_t(dist(e2));
dataKey[iii] = uint8_t(etk::tool::urand(0,255));
}
return algue::base64::encode(dataKey, 16);
}
@ -130,7 +126,7 @@ void enet::WebSocket::start(const etk::String& _uri, const etk::Vector<etk::Stri
|| m_interface->isAlive() == false) {
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
ethread::sleepMilliSeconds((10));
timeout--;
}
if ( m_connectionValidate == false
@ -435,15 +431,10 @@ bool enet::WebSocket::configHeader(bool _isString, bool _mask) {
m_sendBuffer.clear();
m_sendBuffer.resize(ZEUS_BASE_OFFSET_HEADER, 0);
if (_mask == true) {
std::random_device rd;
// Engine
std::mt19937 e2(rd());
// Distribtuions
std::uniform_real_distribution<> dist(0, 0xFF);
m_dataMask[0] = uint8_t(dist(e2));
m_dataMask[1] = uint8_t(dist(e2));
m_dataMask[2] = uint8_t(dist(e2));
m_dataMask[3] = uint8_t(dist(e2));
m_dataMask[0] = uint8_t(etk::tool::urand(0,255));
m_dataMask[1] = uint8_t(etk::tool::urand(0,255));
m_dataMask[2] = uint8_t(etk::tool::urand(0,255));
m_dataMask[3] = uint8_t(etk::tool::urand(0,255));
}
return true;
}
@ -505,7 +496,7 @@ int32_t enet::WebSocket::send() {
}
int32_t enet::WebSocket::write(const void* _data, int32_t _len, bool _isString, bool _mask) {
std::unique_lock<ethread::Mutex> lock(m_mutex);
ethread::UniqueLock lock(m_mutex);
if (configHeader(_isString, _mask) == false) {
return -1;
}
@ -518,7 +509,7 @@ void enet::WebSocket::controlPing() {
ENET_ERROR("Nullptr interface ...");
return;
}
std::unique_lock<ethread::Mutex> lock(m_mutex);
ethread::UniqueLock lock(m_mutex);
uint8_t header = enet::websocket::FLAG_FIN
| enet::websocket::OPCODE_FRAME_PING;
m_lastSend = echrono::Steady::now();
@ -532,7 +523,7 @@ void enet::WebSocket::controlPong() {
ENET_ERROR("Nullptr interface ...");
return;
}
std::unique_lock<ethread::Mutex> lock(m_mutex);
ethread::UniqueLock lock(m_mutex);
uint8_t header = enet::websocket::FLAG_FIN
| enet::websocket::OPCODE_FRAME_PONG;
m_lastSend = echrono::Steady::now();
@ -546,7 +537,7 @@ void enet::WebSocket::controlClose() {
ENET_ERROR("Nullptr interface ...");
return;
}
std::unique_lock<ethread::Mutex> lock(m_mutex);
ethread::UniqueLock lock(m_mutex);
uint8_t header = enet::websocket::FLAG_FIN
| enet::websocket::OPCODE_FRAME_CLOSE;
m_lastSend = echrono::Steady::now();

View File

@ -97,8 +97,8 @@ namespace enet {
bool m_haveMask;
uint8_t m_dataMask[4];
public:
std::unique_lock<ethread::Mutex> getScopeLock() {
return etk::move(std::unique_lock<ethread::Mutex>(m_mutex));
ethread::UniqueLock getScopeLock() {
return etk::move(ethread::UniqueLock(m_mutex));
}
/**
* Compose the local header inside a temporary buffer ==> must lock external to prevent multiple simultaneous access

View File

@ -53,7 +53,7 @@ int main(int _argc, const char *_argv[]) {
connection.setHeader(req);
while (connection.isAlive() == true) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
ethread::sleepMilliSeconds((100));
}
return 0;
}

View File

@ -66,7 +66,7 @@ int main(int _argc, const char *_argv[]) {
int32_t timeout = 20;
while (connection.isAlive() == true
&& timeout > 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
ethread::sleepMilliSeconds((100));
timeout--;
}
return 0;

View File

@ -10,7 +10,6 @@
#include <enet/TcpClient.hpp>
#include <enet/Http.hpp>
#include <etk/etk.hpp>
#include <iostream>
#include <etk/stdTools.hpp>
int main(int _argc, const char *_argv[]) {
@ -45,7 +44,7 @@ int main(int _argc, const char *_argv[]) {
int32_t len = connection.read(data, 1024);
TEST_INFO("read len=" << len << " data='" << data << "'");
//if (data[len-1] == '2') {
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
ethread::sleepMilliSeconds((delay));
delay--;
if (delay == 0) {
delay = 500;

View File

@ -82,7 +82,7 @@ int main(int _argc, const char *_argv[]) {
connection.start();
while (connection.isAlive() == true) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
ethread::sleepMilliSeconds((100));
}

View File

@ -85,7 +85,7 @@ int main(int _argc, const char *_argv[]) {
connection.start();
while (connection.isAlive() == true) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
ethread::sleepMilliSeconds((100));
}
return 0;
}