From 638f0e0181f621584fc950d50878b806769dc047 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 23 Oct 2022 19:22:36 +0300 Subject: [PATCH] PIIODevice remove init picloud dispatcher fix --- libs/main/io_devices/pibinarylog.h | 1 - libs/main/io_devices/piethernet.h | 2 +- libs/main/io_devices/pifile.cpp | 20 +++++--------------- libs/main/io_devices/pifile.h | 5 ++--- libs/main/io_devices/piiodevice.cpp | 14 ++------------ libs/main/io_devices/piiodevice.h | 15 +-------------- utils/cloud_dispatcher/dispatcherclient.cpp | 8 +------- utils/cloud_dispatcher/dispatcherclient.h | 1 - 8 files changed, 12 insertions(+), 54 deletions(-) diff --git a/libs/main/io_devices/pibinarylog.h b/libs/main/io_devices/pibinarylog.h index c7f4a956..5f827a8a 100644 --- a/libs/main/io_devices/pibinarylog.h +++ b/libs/main/io_devices/pibinarylog.h @@ -311,7 +311,6 @@ protected: bool closeDevice() override; void propertyChanged(const char * s) override; bool threadedRead(const uchar *readed, ssize_t size) override; - void threadedReadTerminated() override {pausemutex.unlock();} DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;} private: diff --git a/libs/main/io_devices/piethernet.h b/libs/main/io_devices/piethernet.h index f7f6d00f..95f350bc 100644 --- a/libs/main/io_devices/piethernet.h +++ b/libs/main/io_devices/piethernet.h @@ -477,7 +477,7 @@ protected: virtual void received(const void * data, int size) {;} void construct(); - bool init() override; + bool init(); bool openDevice() override; bool closeDevice() override; void closeSocket(int & sd); diff --git a/libs/main/io_devices/pifile.cpp b/libs/main/io_devices/pifile.cpp index e894ea22..3e246ffa 100644 --- a/libs/main/io_devices/pifile.cpp +++ b/libs/main/io_devices/pifile.cpp @@ -112,7 +112,7 @@ REGISTER_DEVICE(PIFile) PRIVATE_DEFINITION_START(PIFile) - FILE * fd; + FILE * fd = nullptr; PRIVATE_DEFINITION_END(PIFile) @@ -146,8 +146,7 @@ PIString PIFile::FileInfo::dir() const { if (path.isEmpty()) return PIString(); int ind = path.findLast(PIDir::separator); PIString ret; - if (ind >= 0) - ret = path.mid(0, ind); + if (ind >= 0) ret = path.mid(0, ind); if (ret.isEmpty()) ret = "."; return ret + PIDir::separator; } @@ -156,14 +155,11 @@ PIString PIFile::FileInfo::dir() const { PIFile::PIFile(): PIIODevice() { - _init(); } PIFile::PIFile(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(path, mode) { - _init(); - if (!path.isEmpty()) - open(); + if (!path.isEmpty()) open(); } @@ -176,8 +172,9 @@ bool PIFile::openTemporary(PIIODevice::DeviceMode mode) { if (!rc) return false; tp = rc; #endif - while (isExists(tp)) + while (isExists(tp)) { tp += PIString::fromNumber(randomi() % 10); + } return open(tp, mode); } @@ -350,13 +347,6 @@ PIString PIFile::strType(const PIIODevice::DeviceMode type) { } -void PIFile::_init() { - PRIVATE->fd = 0; - fdi = -1; - _size = -1; -} - - void PIFile::flush() { if (isOpened()) fflush(PRIVATE->fd); } diff --git a/libs/main/io_devices/pifile.h b/libs/main/io_devices/pifile.h index aea75c4f..f2ea08ca 100644 --- a/libs/main/io_devices/pifile.h +++ b/libs/main/io_devices/pifile.h @@ -320,11 +320,10 @@ protected: private: PIString strType(const PIIODevice::DeviceMode type); - void _init(); PRIVATE_DECLARATION(PIP_EXPORT) - int fdi; - llong _size; + int fdi = -1; + llong _size = -1; PIString prec_str; }; diff --git a/libs/main/io_devices/piiodevice.cpp b/libs/main/io_devices/piiodevice.cpp index 540a2e3d..8b8d3cda 100644 --- a/libs/main/io_devices/piiodevice.cpp +++ b/libs/main/io_devices/piiodevice.cpp @@ -211,7 +211,7 @@ void PIIODevice::startThreadedRead(ReadRetFunc func) { void PIIODevice::stopThreadedRead() { if (!isThreadedRead()) return; #ifdef MICRO_PIP - read_thread.stop(true); + read_thread.stop(); #else if (reading_now) { read_thread.terminate(); @@ -241,15 +241,7 @@ void PIIODevice::startThreadedWrite() { void PIIODevice::stopThreadedWrite() { if (!write_thread.isRunning()) return; -#ifdef MICRO_PIP - write_thread.stop(true); -#else write_thread.stop(); - if (!write_thread.waitForFinish(100)) { - write_thread.terminate(); - threadedWriteTerminated(); - } -#endif } @@ -309,7 +301,7 @@ ssize_t PIIODevice::write(const void * data, ssize_t max_size) { void PIIODevice::_init() { reading_now = false; - opened_ = init_ = thread_started_ = false; + opened_ = thread_started_ = false; raise_threaded_read_ = true; func_read = nullptr; ret_data_ = nullptr; @@ -319,7 +311,6 @@ void PIIODevice::_init() { setReopenTimeout(1000); #ifdef MICRO_PIP threaded_read_buffer_size = 512; - //setThreadedReadBufferSize(512); #else threaded_read_buffer_size = 4096; #endif @@ -408,7 +399,6 @@ ullong PIIODevice::writeThreaded(const PIByteArray & data) { bool PIIODevice::open() { - if (!init_) init(); buffer_tr.resize(threaded_read_buffer_size); opened_ = openDevice(); if (opened_) opened(); diff --git a/libs/main/io_devices/piiodevice.h b/libs/main/io_devices/piiodevice.h index 4e6b6bef..31889c93 100644 --- a/libs/main/io_devices/piiodevice.h +++ b/libs/main/io_devices/piiodevice.h @@ -465,11 +465,6 @@ public: //! \} protected: - - //! \~english Function executed before first \a openDevice() or from constructor - //! \~russian Метод вызывается перед первым \a openDevice() или из конструктора - virtual bool init() {return true;} - //! \~english Reimplement to configure device from entries "e_main" and "e_parent", cast arguments to \a PIConfig::Entry* //! \~russian virtual bool configureDevice(const void * e_main, const void * e_parent = 0) {return true;} @@ -532,14 +527,6 @@ protected: //! \~russian Переопределите для применения нового \a threadedReadBufferSize() virtual void threadedReadBufferSizeChanged() {;} - //! \~english Invoked after hard read thread stop - //! \~russian Вызывается после жесткой остановки потока чтения - virtual void threadedReadTerminated() {;} - - //! \~english Invoked after hard write thread stop - //! \~russian Вызывается после жесткой остановки потока записи - virtual void threadedWriteTerminated() {;} - static PIIODevice * newDeviceByPrefix(const char * prefix); @@ -567,7 +554,7 @@ private: ssize_t readed_; uint threaded_read_buffer_size, reopen_timeout = 1000; std::atomic_bool reading_now; - bool init_, thread_started_, raise_threaded_read_, reopen_enabled = true; + bool thread_started_, raise_threaded_read_, reopen_enabled = true; static PIMutex nfp_mutex; static PIMap nfp_cache; diff --git a/utils/cloud_dispatcher/dispatcherclient.cpp b/utils/cloud_dispatcher/dispatcherclient.cpp index 9e6118a9..b2d53fd4 100644 --- a/utils/cloud_dispatcher/dispatcherclient.cpp +++ b/utils/cloud_dispatcher/dispatcherclient.cpp @@ -27,13 +27,7 @@ PIString DispatcherClient::address() { void DispatcherClient::close() { - eth->stopThreadedRead(); - eth->close(); -} - - -void DispatcherClient::terminate() { - eth->stop(); + eth->softStopThreadedRead(); eth->close(); } diff --git a/utils/cloud_dispatcher/dispatcherclient.h b/utils/cloud_dispatcher/dispatcherclient.h index 9fb5bdbf..92497e4d 100644 --- a/utils/cloud_dispatcher/dispatcherclient.h +++ b/utils/cloud_dispatcher/dispatcherclient.h @@ -13,7 +13,6 @@ public: ~DispatcherClient(); void start(); void close(); - void terminate(); void sendConnected(uint client_id); void sendDisconnected(uint client_id); void sendData(const PIByteArray & data);