diff --git a/contrib/onelab2/CMakeLists.txt b/contrib/onelab2/CMakeLists.txt index 64e683f0f0e1466120903a3de05e130b39bfd05f..8d494a81d56e0d90f5f7e8b4ea38b3156a6a2b36 100644 --- a/contrib/onelab2/CMakeLists.txt +++ b/contrib/onelab2/CMakeLists.txt @@ -9,6 +9,18 @@ set(SRC GmshNetworkClient.cpp GmshLocalClient.cpp) +if(HAVE_FLTK) +set(SRC + ${SRC} + OnelabWindow.cpp) +endif(HAVE_FLTK) + +if(NOT ENABLE_UDT) +set(SRC + ${SRC} + noudt.cpp) +endif(ENABLE_UDT) + file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) append_gmsh_src(contrib/onelab2 "${SRC};${HDR}") diff --git a/contrib/onelab2/NetworkUtils.h b/contrib/onelab2/NetworkUtils.h index 3b44e30008687ad919aeae17ea22d5aa9855a73c..d6eab1d82c509dd9ed0991d26b6f86996594401a 100644 --- a/contrib/onelab2/NetworkUtils.h +++ b/contrib/onelab2/NetworkUtils.h @@ -19,6 +19,11 @@ typedef int socklen_t; typedef int Socket; #endif +#include "GmshConfig.h" +#ifndef HAVE_UDT +#include "noudt.h" +#endif + typedef unsigned char UInt8; typedef unsigned short UInt16; typedef unsigned int UInt32; @@ -26,6 +31,8 @@ typedef unsigned long long UInt64; typedef struct {unsigned char bytes[16];} UInt128; typedef struct {UInt32 address; UInt16 port;} IPv4; +// TODO check double/float size + // host to network (and network to host) order, Reference RFC 791 #define hton64 ntoh64 #define hton32 htonl @@ -153,4 +160,9 @@ void ip4_socket_timeout(Socket d, long tos, long tous=0); inline void ip4_socket_reuse_address(Socket fd, bool reuse=true) {setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof reuse);} inline void ip4_socket_close(Socket fd) {/*if(-1 == */close(fd);} +Socket unix_socket(int socketType); +void unix_socket_listen(Socket fd, const char *sockname, int maxconnection=1024); +Socket unix_socket_accept(Socket fd); +Socket unix_socket_connect(Socket fd, const char *sockname); + #endif diff --git a/contrib/onelab2/noudt.cpp b/contrib/onelab2/noudt.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b59ab6e90289b9c81d4578ba24b7d7a758bc4b8b --- /dev/null +++ b/contrib/onelab2/noudt.cpp @@ -0,0 +1,74 @@ +#include "noudt.h" + +#include <sys/select.h> +#include <sys/types.h> + +namespace UDT { + + class Epoll + { + private: + std::set<SYSSOCKET> _fds; + static Epoll *_instance; + + public: + Epoll() {} + static Epoll* epoll() { + if(!_instance) _instance = new Epoll(); + return _instance; + } + + void add_ssock(SYSSOCKET s) {_fds.insert(s);} + void remove_ssock(SYSSOCKET s) { + _fds.erase(s); + } + std::set<int>::iterator begin() {return _fds.begin();} + std::set<int>::iterator end() {return _fds.end();} + }; + + Epoll *Epoll::_instance = NULL; + + int startup() + { + return 1; + } + + int cleanup() + { + return 1; + } + + int epoll_create() + { + return 1; + } + + int epoll_add_ssock(int eid, SYSSOCKET s) + { + Epoll::epoll()->add_ssock(s); + return 1; + } + + int epoll_remove_ssock(int eid, SYSSOCKET s) + { + Epoll::epoll()->remove_ssock(s); + return 1; + } + int epoll_wait(int eid, void* readfds, void* writefds, long msTimeOut, + std::set<SYSSOCKET>* lrfds, std::set<SYSSOCKET>* wrfds) + { + fd_set fds; + FD_ZERO(&fds); + for(std::set<SYSSOCKET>::const_iterator i = Epoll::epoll()->begin(); i != Epoll::epoll()->end(); i++) + FD_SET(*i, &fds); + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 0; + if(select(*Epoll::epoll()->begin()+1, &fds, NULL, NULL, /*&timeout*/NULL) > 0) { + for(std::set<SYSSOCKET>::const_iterator i = Epoll::epoll()->begin(); i != Epoll::epoll()->end(); i++) { + lrfds->insert(*i); + } + } + return 1; + } +} diff --git a/contrib/onelab2/noudt.h b/contrib/onelab2/noudt.h new file mode 100644 index 0000000000000000000000000000000000000000..82f4fee7f2a828d4c464d48ee06406d0c3779342 --- /dev/null +++ b/contrib/onelab2/noudt.h @@ -0,0 +1,25 @@ +#include <set> +#include <cstddef> + +#ifdef WIN32 + #ifndef __MINGW__ + typedef SOCKET SYSSOCKET; + #else + typedef int SYSSOCKET; + #endif +#else + typedef int SYSSOCKET; +#endif + + +namespace UDT { + const int ERROR = -1; + + int startup(); + int cleanup(); + int epoll_create(); + int epoll_add_ssock(int eid, SYSSOCKET s); + int epoll_remove_ssock(int eid, SYSSOCKET s); + int epoll_wait(int eid, void* readfds, void* writefds, long msTimeOut, + std::set<SYSSOCKET>* lrfds = NULL, std::set<SYSSOCKET>* wrfds = NULL); +}