Loading src/connection.cpp +5 −14 Changes for src/connection.cpp: 5 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -51,16 +51,17 @@ void netplus::condata<char>::resize(size_t size_c){ std::move(begin()+size_c,end(),begin()); std::vector<char>::resize(rs-size_c); std::vector<char,condataAlloc<char>>::resize(rs-size_c); } void netplus::condata<char>::append(const char* data, size_t datalen){ std::copy(data,data+datalen,std::inserter<std::vector<char>>(*this,end())); std::copy(data,data+datalen,std::inserter<std::vector<char,condataAlloc<char>>>(*this,end())); } size_t netplus::condata<char>::search(const char* word){ size_t wsize=strlen(word); for(size_t i=0; i<size(); ++i){ for(size_t i=0; i<std::vector<char,condataAlloc<char>>::size(); ++i){ for(size_t ii=0; ii<=wsize; ++ii){ if(ii==wsize){ return i-wsize; Loading @@ -76,11 +77,8 @@ size_t netplus::condata<char>::search(const char* word){ } void netplus::con::sending(bool state) { _eventapi->sendReady(this,state); } netplus::con::con(){ Lock.store(false); state=0; } netplus::con::con(eventapi *eapi) : con(){ Loading @@ -90,10 +88,3 @@ netplus::con::con(eventapi *eapi) : con(){ netplus::con::~con(){ } bool netplus::con::lock(){ return std::atomic_exchange_explicit(&Lock, true, std::memory_order_acquire); } void netplus::con::unlock(){ std::atomic_store_explicit(&Lock, false, std::memory_order_release); } src/connection.h +87 −9 Changes for src/connection.h: 87 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -28,16 +28,96 @@ #include <vector> #include <memory> #include <atomic> #include <limits> #pragma once namespace netplus { class eventapi; class pollapi; template <class T> class condataAlloc { public: // type definitions typedef T value_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; // rebind allocator to type U template <class U> struct rebind { typedef condataAlloc<U> other; }; // return address of values pointer address (reference value) const { return &value; } const_pointer address (const_reference value) const { return &value; } /* constructors and destructor * - nothing to do because the allocator has no state */ condataAlloc() throw() { } condataAlloc(const condataAlloc&) throw() { } template <class U> condataAlloc (const condataAlloc<U>&) throw() { } ~condataAlloc() throw() { } // return maximum number of elements that can be allocated size_type max_size () const throw() { return std::numeric_limits<std::size_t>::max() / sizeof(T); } // allocate but don't initialize num elements of type T pointer allocate (size_type num, const void* = 0) { pointer ret = (pointer)(::operator new(num*sizeof(T))); return ret; } // initialize elements of allocated storage p with value value void construct (pointer p, const T& value) { new((void*)p)T(value); } // destroy elements of initialized storage p void destroy (pointer p) { p->~T(); } // deallocate storage p of deleted elements void deallocate (pointer p, size_type num) { ::operator delete((void*)p); } }; // return that all specializations of this allocator are interchangeable template <class T1, class T2> bool operator== (const condataAlloc<T1>&, const condataAlloc<T2>&) throw() { return true; } template <class T1, class T2> bool operator!= (const condataAlloc<T1>&, const condataAlloc<T2>&) throw() { return false; } template <typename T> class condata; template <> class condata<char> : public std::vector<char>{ template <> class condata<char> : public std::vector<char,condataAlloc<char>>{ public: void resize(size_t size_c); void append(const char *data,size_t datalen); Loading @@ -51,23 +131,21 @@ namespace netplus { ~con(); /*clientsocket*/ std::shared_ptr<socket> csock; /*set sending state*/ void sending(bool state); socket *csock; bool lock(); void unlock(); /*event stauts*/ int state; /*connection Data*/ condata<char> RecvData; condata<char> SendData; protected: con(); int lasteventime; private: std::atomic<bool> Lock; eventapi *_eventapi; pollapi *_pollapi; friend class poll; }; }; src/eventapi.h +5 −7 Changes for src/eventapi.h: 5 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <thread> #include <vector> #include <memory> #include "socket.h" Loading @@ -47,25 +49,21 @@ namespace netplus { /*memory allocation*/ virtual void CreateConnetion(con **curon)=0; virtual void deleteConnetion(con *curon)=0; /*Connection Ready to send Data * DANGEROUS to burnout your cpu *only use this if know what you do!*/ virtual void sendReady(con *curcon,bool ready)=0; }; class event : public eventapi{ public: event(socket *serversocket,int timeout = 60); void runEventloop(); void sendReady(con* curcon, bool ready); static void *WorkerThread(void *wrkevent); virtual ~event(); static bool _Run; static bool _Restart; private: pollapi *_Poll; socket *_ServerSocket; int _Timeout; int _pollFD; friend class EventWorker; }; }; src/exception.cpp +6 −0 Changes for src/exception.cpp: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -27,9 +27,13 @@ #include <stdlib.h> #include <string.h> #include <mutex> #include "exception.h" namespace netplus { std::mutex g_exception; }; netplus::NetException::NetException() { curCType=Note; Loading @@ -52,6 +56,7 @@ const char* netplus::NetException::what(){ } netplus::NetException& netplus::NetException::append(const char *src){ const std::lock_guard<std::mutex> lock(g_exception); msg.append(src); return *this; } Loading @@ -66,6 +71,7 @@ netplus::NetException& netplus::NetException::operator<<(const char *src){ }; netplus::NetException& netplus::NetException::operator<<(int src){ const std::lock_guard<std::mutex> lock(g_exception); char buffer[255]; snprintf(buffer,255,"%d",src); msg.append(buffer); Loading src/linux/event.cpp +144 −203 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
src/connection.cpp +5 −14 Changes for src/connection.cpp: 5 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -51,16 +51,17 @@ void netplus::condata<char>::resize(size_t size_c){ std::move(begin()+size_c,end(),begin()); std::vector<char>::resize(rs-size_c); std::vector<char,condataAlloc<char>>::resize(rs-size_c); } void netplus::condata<char>::append(const char* data, size_t datalen){ std::copy(data,data+datalen,std::inserter<std::vector<char>>(*this,end())); std::copy(data,data+datalen,std::inserter<std::vector<char,condataAlloc<char>>>(*this,end())); } size_t netplus::condata<char>::search(const char* word){ size_t wsize=strlen(word); for(size_t i=0; i<size(); ++i){ for(size_t i=0; i<std::vector<char,condataAlloc<char>>::size(); ++i){ for(size_t ii=0; ii<=wsize; ++ii){ if(ii==wsize){ return i-wsize; Loading @@ -76,11 +77,8 @@ size_t netplus::condata<char>::search(const char* word){ } void netplus::con::sending(bool state) { _eventapi->sendReady(this,state); } netplus::con::con(){ Lock.store(false); state=0; } netplus::con::con(eventapi *eapi) : con(){ Loading @@ -90,10 +88,3 @@ netplus::con::con(eventapi *eapi) : con(){ netplus::con::~con(){ } bool netplus::con::lock(){ return std::atomic_exchange_explicit(&Lock, true, std::memory_order_acquire); } void netplus::con::unlock(){ std::atomic_store_explicit(&Lock, false, std::memory_order_release); }
src/connection.h +87 −9 Changes for src/connection.h: 87 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -28,16 +28,96 @@ #include <vector> #include <memory> #include <atomic> #include <limits> #pragma once namespace netplus { class eventapi; class pollapi; template <class T> class condataAlloc { public: // type definitions typedef T value_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; // rebind allocator to type U template <class U> struct rebind { typedef condataAlloc<U> other; }; // return address of values pointer address (reference value) const { return &value; } const_pointer address (const_reference value) const { return &value; } /* constructors and destructor * - nothing to do because the allocator has no state */ condataAlloc() throw() { } condataAlloc(const condataAlloc&) throw() { } template <class U> condataAlloc (const condataAlloc<U>&) throw() { } ~condataAlloc() throw() { } // return maximum number of elements that can be allocated size_type max_size () const throw() { return std::numeric_limits<std::size_t>::max() / sizeof(T); } // allocate but don't initialize num elements of type T pointer allocate (size_type num, const void* = 0) { pointer ret = (pointer)(::operator new(num*sizeof(T))); return ret; } // initialize elements of allocated storage p with value value void construct (pointer p, const T& value) { new((void*)p)T(value); } // destroy elements of initialized storage p void destroy (pointer p) { p->~T(); } // deallocate storage p of deleted elements void deallocate (pointer p, size_type num) { ::operator delete((void*)p); } }; // return that all specializations of this allocator are interchangeable template <class T1, class T2> bool operator== (const condataAlloc<T1>&, const condataAlloc<T2>&) throw() { return true; } template <class T1, class T2> bool operator!= (const condataAlloc<T1>&, const condataAlloc<T2>&) throw() { return false; } template <typename T> class condata; template <> class condata<char> : public std::vector<char>{ template <> class condata<char> : public std::vector<char,condataAlloc<char>>{ public: void resize(size_t size_c); void append(const char *data,size_t datalen); Loading @@ -51,23 +131,21 @@ namespace netplus { ~con(); /*clientsocket*/ std::shared_ptr<socket> csock; /*set sending state*/ void sending(bool state); socket *csock; bool lock(); void unlock(); /*event stauts*/ int state; /*connection Data*/ condata<char> RecvData; condata<char> SendData; protected: con(); int lasteventime; private: std::atomic<bool> Lock; eventapi *_eventapi; pollapi *_pollapi; friend class poll; }; };
src/eventapi.h +5 −7 Changes for src/eventapi.h: 5 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <thread> #include <vector> #include <memory> #include "socket.h" Loading @@ -47,25 +49,21 @@ namespace netplus { /*memory allocation*/ virtual void CreateConnetion(con **curon)=0; virtual void deleteConnetion(con *curon)=0; /*Connection Ready to send Data * DANGEROUS to burnout your cpu *only use this if know what you do!*/ virtual void sendReady(con *curcon,bool ready)=0; }; class event : public eventapi{ public: event(socket *serversocket,int timeout = 60); void runEventloop(); void sendReady(con* curcon, bool ready); static void *WorkerThread(void *wrkevent); virtual ~event(); static bool _Run; static bool _Restart; private: pollapi *_Poll; socket *_ServerSocket; int _Timeout; int _pollFD; friend class EventWorker; }; };
src/exception.cpp +6 −0 Changes for src/exception.cpp: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -27,9 +27,13 @@ #include <stdlib.h> #include <string.h> #include <mutex> #include "exception.h" namespace netplus { std::mutex g_exception; }; netplus::NetException::NetException() { curCType=Note; Loading @@ -52,6 +56,7 @@ const char* netplus::NetException::what(){ } netplus::NetException& netplus::NetException::append(const char *src){ const std::lock_guard<std::mutex> lock(g_exception); msg.append(src); return *this; } Loading @@ -66,6 +71,7 @@ netplus::NetException& netplus::NetException::operator<<(const char *src){ }; netplus::NetException& netplus::NetException::operator<<(int src){ const std::lock_guard<std::mutex> lock(g_exception); char buffer[255]; snprintf(buffer,255,"%d",src); msg.append(buffer); Loading
src/linux/event.cpp +144 −203 File changed.Preview size limit exceeded, changes collapsed. Show changes