piiodevice_fix #167
@@ -33,7 +33,7 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
|
|||||||
if (is_deleted) return;
|
if (is_deleted) return;
|
||||||
bool need_disconn = is_connected;
|
bool need_disconn = is_connected;
|
||||||
//piCoutObj << "eth disconnected";
|
//piCoutObj << "eth disconnected";
|
||||||
eth.stopThreadedRead();
|
eth.softStopThreadedRead();
|
||||||
opened_ = false;
|
opened_ = false;
|
||||||
internalDisconnect();
|
internalDisconnect();
|
||||||
if (need_disconn)
|
if (need_disconn)
|
||||||
@@ -155,7 +155,7 @@ void PICloudClient::_readed(PIByteArray & ba) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PICloud::TCP::Disconnect:
|
case PICloud::TCP::Disconnect:
|
||||||
eth.stopThreadedRead();
|
eth.softStopThreadedRead();
|
||||||
opened_ = false;
|
opened_ = false;
|
||||||
eth.close();
|
eth.close();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
|
|||||||
CONNECTL(ð, connected, [this](){opened_ = true; piCoutObj << "connected"; tcp.sendStart();});
|
CONNECTL(ð, connected, [this](){opened_ = true; piCoutObj << "connected"; tcp.sendStart();});
|
||||||
CONNECTL(ð, disconnected, [this](bool){
|
CONNECTL(ð, disconnected, [this](bool){
|
||||||
piCoutObj << "disconnected";
|
piCoutObj << "disconnected";
|
||||||
eth.stopThreadedRead();
|
eth.softStopThreadedRead();
|
||||||
opened_ = false;
|
opened_ = false;
|
||||||
ping_timer.stop(false);
|
ping_timer.stop(false);
|
||||||
piMSleep(100);
|
piMSleep(100);
|
||||||
|
|||||||
@@ -311,7 +311,6 @@ protected:
|
|||||||
bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
void propertyChanged(const char * s) override;
|
void propertyChanged(const char * s) override;
|
||||||
bool threadedRead(const uchar *readed, ssize_t size) override;
|
bool threadedRead(const uchar *readed, ssize_t size) override;
|
||||||
void threadedReadTerminated() override {pausemutex.unlock();}
|
|
||||||
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -477,7 +477,7 @@ protected:
|
|||||||
virtual void received(const void * data, int size) {;}
|
virtual void received(const void * data, int size) {;}
|
||||||
|
|
||||||
void construct();
|
void construct();
|
||||||
bool init() override;
|
bool init();
|
||||||
bool openDevice() override;
|
bool openDevice() override;
|
||||||
bool closeDevice() override;
|
bool closeDevice() override;
|
||||||
void closeSocket(int & sd);
|
void closeSocket(int & sd);
|
||||||
|
|||||||
@@ -112,7 +112,7 @@
|
|||||||
REGISTER_DEVICE(PIFile)
|
REGISTER_DEVICE(PIFile)
|
||||||
|
|
||||||
PRIVATE_DEFINITION_START(PIFile)
|
PRIVATE_DEFINITION_START(PIFile)
|
||||||
FILE * fd;
|
FILE * fd = nullptr;
|
||||||
PRIVATE_DEFINITION_END(PIFile)
|
PRIVATE_DEFINITION_END(PIFile)
|
||||||
|
|
||||||
|
|
||||||
@@ -146,8 +146,7 @@ PIString PIFile::FileInfo::dir() const {
|
|||||||
if (path.isEmpty()) return PIString();
|
if (path.isEmpty()) return PIString();
|
||||||
int ind = path.findLast(PIDir::separator);
|
int ind = path.findLast(PIDir::separator);
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (ind >= 0)
|
if (ind >= 0) ret = path.mid(0, ind);
|
||||||
ret = path.mid(0, ind);
|
|
||||||
if (ret.isEmpty()) ret = ".";
|
if (ret.isEmpty()) ret = ".";
|
||||||
return ret + PIDir::separator;
|
return ret + PIDir::separator;
|
||||||
}
|
}
|
||||||
@@ -156,14 +155,11 @@ PIString PIFile::FileInfo::dir() const {
|
|||||||
|
|
||||||
|
|
||||||
PIFile::PIFile(): PIIODevice() {
|
PIFile::PIFile(): PIIODevice() {
|
||||||
_init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIFile::PIFile(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(path, mode) {
|
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;
|
if (!rc) return false;
|
||||||
tp = rc;
|
tp = rc;
|
||||||
#endif
|
#endif
|
||||||
while (isExists(tp))
|
while (isExists(tp)) {
|
||||||
tp += PIString::fromNumber(randomi() % 10);
|
tp += PIString::fromNumber(randomi() % 10);
|
||||||
|
}
|
||||||
return open(tp, mode);
|
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() {
|
void PIFile::flush() {
|
||||||
if (isOpened()) fflush(PRIVATE->fd);
|
if (isOpened()) fflush(PRIVATE->fd);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -320,11 +320,10 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
PIString strType(const PIIODevice::DeviceMode type);
|
PIString strType(const PIIODevice::DeviceMode type);
|
||||||
void _init();
|
|
||||||
|
|
||||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||||
int fdi;
|
int fdi = -1;
|
||||||
llong _size;
|
llong _size = -1;
|
||||||
PIString prec_str;
|
PIString prec_str;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ void PIIODevice::startThreadedRead(ReadRetFunc func) {
|
|||||||
void PIIODevice::stopThreadedRead() {
|
void PIIODevice::stopThreadedRead() {
|
||||||
if (!isThreadedRead()) return;
|
if (!isThreadedRead()) return;
|
||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
read_thread.stop(true);
|
read_thread.stop();
|
||||||
#else
|
#else
|
||||||
if (reading_now) {
|
if (reading_now) {
|
||||||
read_thread.terminate();
|
read_thread.terminate();
|
||||||
@@ -241,15 +241,7 @@ void PIIODevice::startThreadedWrite() {
|
|||||||
|
|
||||||
void PIIODevice::stopThreadedWrite() {
|
void PIIODevice::stopThreadedWrite() {
|
||||||
if (!write_thread.isRunning()) return;
|
if (!write_thread.isRunning()) return;
|
||||||
#ifdef MICRO_PIP
|
|
||||||
write_thread.stop(true);
|
|
||||||
#else
|
|
||||||
write_thread.stop();
|
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() {
|
void PIIODevice::_init() {
|
||||||
reading_now = false;
|
reading_now = false;
|
||||||
opened_ = init_ = thread_started_ = false;
|
opened_ = thread_started_ = false;
|
||||||
raise_threaded_read_ = true;
|
raise_threaded_read_ = true;
|
||||||
func_read = nullptr;
|
func_read = nullptr;
|
||||||
ret_data_ = nullptr;
|
ret_data_ = nullptr;
|
||||||
@@ -319,7 +311,6 @@ void PIIODevice::_init() {
|
|||||||
setReopenTimeout(1000);
|
setReopenTimeout(1000);
|
||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
threaded_read_buffer_size = 512;
|
threaded_read_buffer_size = 512;
|
||||||
//setThreadedReadBufferSize(512);
|
|
||||||
#else
|
#else
|
||||||
threaded_read_buffer_size = 4096;
|
threaded_read_buffer_size = 4096;
|
||||||
#endif
|
#endif
|
||||||
@@ -408,7 +399,6 @@ ullong PIIODevice::writeThreaded(const PIByteArray & data) {
|
|||||||
|
|
||||||
|
|
||||||
bool PIIODevice::open() {
|
bool PIIODevice::open() {
|
||||||
if (!init_) init();
|
|
||||||
buffer_tr.resize(threaded_read_buffer_size);
|
buffer_tr.resize(threaded_read_buffer_size);
|
||||||
opened_ = openDevice();
|
opened_ = openDevice();
|
||||||
if (opened_) opened();
|
if (opened_) opened();
|
||||||
|
|||||||
@@ -382,6 +382,8 @@ public:
|
|||||||
//! \~russian Пишет в устройство блок памяти "mb"
|
//! \~russian Пишет в устройство блок памяти "mb"
|
||||||
ssize_t write(const PIMemoryBlock & mb) {return write(mb.data(), mb.size());}
|
ssize_t write(const PIMemoryBlock & mb) {return write(mb.data(), mb.size());}
|
||||||
|
|
||||||
|
void softStopThreadedRead();
|
||||||
|
|
||||||
EVENT_VHANDLER(void, flush) {;}
|
EVENT_VHANDLER(void, flush) {;}
|
||||||
|
|
||||||
EVENT(opened);
|
EVENT(opened);
|
||||||
@@ -463,11 +465,6 @@ public:
|
|||||||
//! \}
|
//! \}
|
||||||
|
|
||||||
protected:
|
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*
|
//! \~english Reimplement to configure device from entries "e_main" and "e_parent", cast arguments to \a PIConfig::Entry*
|
||||||
//! \~russian
|
//! \~russian
|
||||||
virtual bool configureDevice(const void * e_main, const void * e_parent = 0) {return true;}
|
virtual bool configureDevice(const void * e_main, const void * e_parent = 0) {return true;}
|
||||||
@@ -530,16 +527,6 @@ protected:
|
|||||||
//! \~russian Переопределите для применения нового \a threadedReadBufferSize()
|
//! \~russian Переопределите для применения нового \a threadedReadBufferSize()
|
||||||
virtual void threadedReadBufferSizeChanged() {;}
|
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() {;}
|
|
||||||
|
|
||||||
void softStopThreadedRead();
|
|
||||||
|
|
||||||
static PIIODevice * newDeviceByPrefix(const char * prefix);
|
static PIIODevice * newDeviceByPrefix(const char * prefix);
|
||||||
|
|
||||||
|
|
||||||
@@ -567,7 +554,7 @@ private:
|
|||||||
ssize_t readed_;
|
ssize_t readed_;
|
||||||
uint threaded_read_buffer_size, reopen_timeout = 1000;
|
uint threaded_read_buffer_size, reopen_timeout = 1000;
|
||||||
std::atomic_bool reading_now;
|
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 PIMutex nfp_mutex;
|
||||||
static PIMap<PIString, PIString> nfp_cache;
|
static PIMap<PIString, PIString> nfp_cache;
|
||||||
|
|||||||
@@ -27,13 +27,7 @@ PIString DispatcherClient::address() {
|
|||||||
|
|
||||||
|
|
||||||
void DispatcherClient::close() {
|
void DispatcherClient::close() {
|
||||||
eth->stopThreadedRead();
|
eth->softStopThreadedRead();
|
||||||
eth->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DispatcherClient::terminate() {
|
|
||||||
eth->stop();
|
|
||||||
eth->close();
|
eth->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ public:
|
|||||||
~DispatcherClient();
|
~DispatcherClient();
|
||||||
void start();
|
void start();
|
||||||
void close();
|
void close();
|
||||||
void terminate();
|
|
||||||
void sendConnected(uint client_id);
|
void sendConnected(uint client_id);
|
||||||
void sendDisconnected(uint client_id);
|
void sendDisconnected(uint client_id);
|
||||||
void sendData(const PIByteArray & data);
|
void sendData(const PIByteArray & data);
|
||||||
|
|||||||
Reference in New Issue
Block a user