[DEV/API] change .h in .hpp

This commit is contained in:
Edouard DUPIN 2016-09-30 22:28:36 +02:00
parent 1571338fde
commit 975c124bd4
24 changed files with 148 additions and 112 deletions

View File

@ -4,6 +4,6 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <enet/debug.h> #include <enet/debug.hpp>
#include <enet/Ftp.h> #include <enet/Ftp.hpp>
#include <string.h> #include <string.h>

View File

@ -4,10 +4,10 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <enet/debug.h> #include <enet/debug.hpp>
#include <enet/Http.h> #include <enet/Http.hpp>
#include <map> #include <map>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>

View File

@ -5,11 +5,11 @@
*/ */
#pragma once #pragma once
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <vector> #include <vector>
#include <map> #include <map>
#include <thread> #include <thread>
#include <ethread/tools.h> #include <ethread/tools.hpp>
namespace enet { namespace enet {
enum class HTTPAnswerCode { enum class HTTPAnswerCode {

View File

@ -4,19 +4,22 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <enet/debug.h> #include <enet/debug.hpp>
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <sys/types.h> #include <sys/types.hpp>
#include <netdb.h> #include <netdb.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
#ifndef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
#include <sys/socket.h> #include <winsock2.h>
#include <netinet/in.h> #include <ws2tcpip.h>
#include <netinet/tcp.h> #else
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif #endif
bool enet::Tcp::setTCPNoDelay(bool _enabled) { bool enet::Tcp::setTCPNoDelay(bool _enabled) {
@ -42,13 +45,11 @@ enet::Tcp::Tcp(int32_t _idSocket, const std::string& _name) :
m_socketId(_idSocket), m_socketId(_idSocket),
m_name(_name), m_name(_name),
m_status(status::link) { m_status(status::link) {
#if 1 //Initialize the pollfd structure
//Initialize the pollfd structure memset(m_fds[0], 0 , sizeof(m_fds));
memset(m_fds, 0 , sizeof(m_fds)); //Set up the initial listening socket
//Set up the initial listening socket m_fds[0].fd = _idSocket;
m_fds[0].fd = _idSocket; m_fds[0].events = POLLIN | POLLERR;
m_fds[0].events = POLLIN | POLLERR;
#endif
} }
enet::Tcp::Tcp(Tcp&& _obj) : enet::Tcp::Tcp(Tcp&& _obj) :
@ -59,10 +60,9 @@ enet::Tcp::Tcp(Tcp&& _obj) :
_obj.m_name = ""; _obj.m_name = "";
_obj.m_status = status::error; _obj.m_status = status::error;
m_fds[0] = _obj.m_fds[0]; m_fds[0] = _obj.m_fds[0];
#if 1 memset(m_fds[0], 0 , sizeof(m_fds));
memset(_obj.m_fds, 0 , sizeof(_obj.m_fds));
#endif
} }
enet::Tcp::~Tcp() { enet::Tcp::~Tcp() {
unlink(); unlink();
} }
@ -76,9 +76,7 @@ enet::Tcp& enet::Tcp::operator = (enet::Tcp&& _obj) {
m_status = _obj.m_status; m_status = _obj.m_status;
_obj.m_status = status::error; _obj.m_status = status::error;
m_fds[0] = _obj.m_fds[0]; m_fds[0] = _obj.m_fds[0];
#if 1 memset(m_fds[0], 0 , sizeof(m_fds));
memset(_obj.m_fds, 0 , sizeof(_obj.m_fds));
#endif
return *this; return *this;
} }
@ -86,7 +84,11 @@ bool enet::Tcp::unlink() {
if (m_socketId >= 0) { if (m_socketId >= 0) {
ENET_INFO("Close socket (start)"); ENET_INFO("Close socket (start)");
shutdown(m_socketId, SHUT_RDWR); shutdown(m_socketId, SHUT_RDWR);
close(m_socketId); #ifdef __TARGET_OS__Windows
closesocket(m_socketId);
#else
close(m_socketId);
#endif
ENET_INFO("Close socket (done)"); ENET_INFO("Close socket (done)");
m_socketId = -1; m_socketId = -1;
} }

View File

@ -5,18 +5,27 @@
*/ */
#pragma once #pragma once
#include <etk/types.h> #include <etk/types.hpp>
#include <mutex> #include <mutex>
#ifndef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
#include <poll.h> #include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <poll.h>
#endif #endif
namespace enet { namespace enet {
class Tcp { class Tcp {
private: private:
int32_t m_socketId; //!< socket linux interface generic #ifdef __TARGET_OS__Windows
SOCKET m_socketId; //!< socket Windows interface generic
#else
int32_t m_socketId; //!< socket linux interface generic
#endif
#ifndef __TARGET_OS__Windows #ifndef __TARGET_OS__Windows
struct pollfd m_fds[1]; int32_t m_fds[1];
#else
struct pollfd m_fds[1];
#endif #endif
std::mutex m_mutex; std::mutex m_mutex;
public: public:

View File

@ -4,18 +4,22 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <enet/debug.h> #include <enet/debug.hpp>
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <enet/TcpClient.h> #include <enet/TcpClient.hpp>
#include <sys/types.h> #include <sys/types.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
#include <sys/socket.h> #ifdef __TARGET_OS__Windows
#else
#include <sys/socket.h>
#endif
enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry) { enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry) {
std::string tmpname; std::string tmpname;
@ -59,7 +63,11 @@ enet::Tcp enet::connectTcpClient(const std::string& _hostname, uint16_t _port, u
&& errno != ECONNREFUSED) { && errno != ECONNREFUSED) {
ENET_ERROR("ERROR connecting on : errno=" << errno << "," << strerror(errno)); ENET_ERROR("ERROR connecting on : errno=" << errno << "," << strerror(errno));
} }
close(socketId); #ifdef __TARGET_OS__Windows
closesocket(socketId);
#else
close(socketId);
#endif
socketId = -1; socketId = -1;
} }
ENET_ERROR("ERROR connecting, maybe retry ... errno=" << errno << "," << strerror(errno)); ENET_ERROR("ERROR connecting, maybe retry ... errno=" << errno << "," << strerror(errno));

View File

@ -5,7 +5,7 @@
*/ */
#pragma once #pragma once
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
namespace enet { namespace enet {
enet::Tcp connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry=5); enet::Tcp connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry=5);

View File

@ -4,17 +4,18 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <enet/debug.h> #include <enet/debug.hpp>
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <enet/TcpServer.h> #include <enet/TcpServer.hpp>
#include <sys/types.h> #include <sys/types.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h>
//https://msdn.microsoft.com/fr-fr/library/windows/desktop/ms737889(v=vs.85).aspx //https://msdn.microsoft.com/fr-fr/library/windows/desktop/ms737889(v=vs.85).aspx
#else #else
#include <sys/socket.h> #include <sys/socket.h>
@ -83,7 +84,11 @@ bool enet::TcpServer::link() {
ENET_INFO("Start binding Socket ... (can take some time ...)"); ENET_INFO("Start binding Socket ... (can take some time ...)");
if (bind(m_socketId, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) { if (bind(m_socketId, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) {
ENET_ERROR("ERROR on binding errno=" << errno << "," << strerror(errno)); ENET_ERROR("ERROR on binding errno=" << errno << "," << strerror(errno));
close(m_socketId); #ifdef __TARGET_OS__Windows
closesocket(m_socketId);
#else
close(m_socketId);
#endif
m_socketId = -1; m_socketId = -1;
return false; return false;
} }
@ -99,7 +104,11 @@ enet::Tcp enet::TcpServer::waitNext() {
int32_t socketIdClient = accept(m_socketId, (struct sockaddr *) &clientAddr, &clilen); int32_t socketIdClient = accept(m_socketId, (struct sockaddr *) &clientAddr, &clilen);
if (socketIdClient < 0) { if (socketIdClient < 0) {
ENET_ERROR("ERROR on accept errno=" << errno << "," << strerror(errno)); ENET_ERROR("ERROR on accept errno=" << errno << "," << strerror(errno));
close(m_socketId); #ifdef __TARGET_OS__Windows
closesocket(m_socketId);
#else
close(m_socketId);
#endif
m_socketId = -1; m_socketId = -1;
return enet::Tcp(); return enet::Tcp();
} }
@ -111,7 +120,11 @@ enet::Tcp enet::TcpServer::waitNext() {
bool enet::TcpServer::unlink() { bool enet::TcpServer::unlink() {
if (m_socketId >= 0) { if (m_socketId >= 0) {
ENET_INFO(" close server socket"); ENET_INFO(" close server socket");
close(m_socketId); #ifdef __TARGET_OS__Windows
closesocket(m_socketId);
#else
close(m_socketId);
#endif
m_socketId = -1; m_socketId = -1;
} }
return true; return true;

View File

@ -4,7 +4,7 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#pragma once #pragma once
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
#else #else
@ -14,7 +14,11 @@
namespace enet { namespace enet {
class TcpServer { class TcpServer {
private: private:
int32_t m_socketId; //!< socket linux interface generic #ifdef __TARGET_OS__Windows
SOCKET m_socketId; //!< socket Windows interface generic
#else
int32_t m_socketId; //!< socket linux interface generic
#endif
#ifndef __TARGET_OS__Windows #ifndef __TARGET_OS__Windows
struct pollfd m_fds[1]; struct pollfd m_fds[1];
#endif #endif

View File

@ -4,6 +4,6 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <enet/debug.h> #include <enet/debug.hpp>
#include <enet/Udp.h> #include <enet/Udp.hpp>

View File

@ -4,14 +4,14 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <enet/debug.h> #include <enet/debug.hpp>
#include <enet/WebSocket.h> #include <enet/WebSocket.hpp>
#include <map> #include <map>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
#include <string.h> #include <string.h>
#include <random> #include <random>
#include <algue/base64.h> #include <algue/base64.hpp>
#include <algue/sha1.h> #include <algue/sha1.hpp>
#include <unistd.h> #include <unistd.h>

View File

@ -5,8 +5,8 @@
*/ */
#pragma once #pragma once
#include <enet/Http.h> #include <enet/Http.hpp>
#include <ememory/memory.h> #include <ememory/memory.hpp>
#include <vector> #include <vector>
#include <map> #include <map>

View File

@ -4,7 +4,7 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <enet/debug.h> #include <enet/debug.hpp>
int32_t enet::getLogId() { int32_t enet::getLogId() {
static int32_t g_val = elog::registerInstance("enet"); static int32_t g_val = elog::registerInstance("enet");

View File

@ -5,7 +5,7 @@
*/ */
#pragma once #pragma once
#include <elog/log.h> #include <elog/log.hpp>
namespace enet { namespace enet {
int32_t getLogId(); int32_t getLogId();

View File

@ -5,10 +5,10 @@
*/ */
#pragma once #pragma once
#include <enet/Udp.h> #include <enet/Udp.hpp>
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <enet/Http.h> #include <enet/Http.hpp>
#include <enet/Ftp.h> #include <enet/Ftp.hpp>
/** /**

View File

@ -43,14 +43,14 @@ def create(target, module_name):
'enet/WebSocket.cpp', 'enet/WebSocket.cpp',
]) ])
my_module.add_header_file([ my_module.add_header_file([
'enet/debug.h', 'enet/debug.hpp',
'enet/Udp.h', 'enet/Udp.hpp',
'enet/Tcp.h', 'enet/Tcp.hpp',
'enet/TcpServer.h', 'enet/TcpServer.hpp',
'enet/TcpClient.h', 'enet/TcpClient.hpp',
'enet/Http.h', 'enet/Http.hpp',
'enet/Ftp.h', 'enet/Ftp.hpp',
'enet/WebSocket.h', 'enet/WebSocket.hpp',
]) ])
return my_module return my_module

View File

@ -4,13 +4,13 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <test-debug/debug.h> #include <test-debug/debug.hpp>
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <enet/TcpClient.h> #include <enet/TcpClient.hpp>
#include <enet/Http.h> #include <enet/Http.hpp>
#include <etk/etk.h> #include <etk/etk.hpp>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
#include <unistd.h> #include <unistd.h>
namespace appl { namespace appl {

View File

@ -4,14 +4,14 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <test-debug/debug.h> #include <test-debug/debug.hpp>
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <enet/TcpClient.h> #include <enet/TcpClient.hpp>
#include <enet/Http.h> #include <enet/Http.hpp>
#include <enet/WebSocket.h> #include <enet/WebSocket.hpp>
#include <etk/etk.h> #include <etk/etk.hpp>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
#include <unistd.h> #include <unistd.h>
namespace appl { namespace appl {

View File

@ -4,13 +4,13 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <test-debug/debug.h> #include <test-debug/debug.hpp>
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <enet/TcpClient.h> #include <enet/TcpClient.hpp>
#include <enet/Http.h> #include <enet/Http.hpp>
#include <etk/etk.h> #include <etk/etk.hpp>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
int main(int _argc, const char *_argv[]) { int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv); etk::init(_argc, _argv);

View File

@ -4,14 +4,14 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <test-debug/debug.h> #include <test-debug/debug.hpp>
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <enet/Http.h> #include <enet/Http.hpp>
#include <enet/TcpServer.h> #include <enet/TcpServer.hpp>
#include <etk/etk.h> #include <etk/etk.hpp>
#include <unistd.h> #include <unistd.hpp>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
namespace appl { namespace appl {
void onReceiveData(enet::HttpServer* _interface, std::vector<uint8_t>& _data) { void onReceiveData(enet::HttpServer* _interface, std::vector<uint8_t>& _data) {
TEST_INFO("Receive Datas : " << _data.size() << " bytes"); TEST_INFO("Receive Datas : " << _data.size() << " bytes");

View File

@ -4,15 +4,15 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <test-debug/debug.h> #include <test-debug/debug.hpp>
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <enet/Http.h> #include <enet/Http.hpp>
#include <enet/WebSocket.h> #include <enet/WebSocket.hpp>
#include <enet/TcpServer.h> #include <enet/TcpServer.hpp>
#include <etk/etk.h> #include <etk/etk.hpp>
#include <unistd.h> #include <unistd.h>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
namespace appl { namespace appl {
void onReceiveData(enet::WebSocket* _interface, std::vector<uint8_t>& _data, bool _isString) { void onReceiveData(enet::WebSocket* _interface, std::vector<uint8_t>& _data, bool _isString) {
TEST_INFO("Receive Datas : " << _data.size() << " bytes"); TEST_INFO("Receive Datas : " << _data.size() << " bytes");

View File

@ -4,13 +4,13 @@
* @license APACHE v2.0 (see license file) * @license APACHE v2.0 (see license file)
*/ */
#include <test-debug/debug.h> #include <test-debug/debug.hpp>
#include <enet/Tcp.h> #include <enet/Tcp.hpp>
#include <enet/Http.h> #include <enet/Http.hpp>
#include <etk/etk.h> #include <etk/etk.hpp>
#include <enet/TcpServer.h> #include <enet/TcpServer.hpp>
#include <etk/stdTools.h> #include <etk/stdTools.hpp>
int main(int _argc, const char *_argv[]) { int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv); etk::init(_argc, _argv);