piiodevice_fix #167
@@ -33,7 +33,7 @@ PICloudClient::PICloudClient(const PIString & path, PIIODevice::DeviceMode mode)
|
||||
if (is_deleted) return;
|
||||
bool need_disconn = is_connected;
|
||||
//piCoutObj << "eth disconnected";
|
||||
eth.stopThreadedRead();
|
||||
eth.softStopThreadedRead();
|
||||
opened_ = false;
|
||||
internalDisconnect();
|
||||
if (need_disconn)
|
||||
@@ -155,7 +155,7 @@ void PICloudClient::_readed(PIByteArray & ba) {
|
||||
}
|
||||
break;
|
||||
case PICloud::TCP::Disconnect:
|
||||
eth.stopThreadedRead();
|
||||
eth.softStopThreadedRead();
|
||||
opened_ = false;
|
||||
eth.close();
|
||||
break;
|
||||
|
||||
@@ -29,7 +29,7 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
|
||||
CONNECTL(ð, connected, [this](){opened_ = true; piCoutObj << "connected"; tcp.sendStart();});
|
||||
CONNECTL(ð, disconnected, [this](bool){
|
||||
piCoutObj << "disconnected";
|
||||
eth.stopThreadedRead();
|
||||
eth.softStopThreadedRead();
|
||||
opened_ = false;
|
||||
ping_timer.stop(false);
|
||||
piMSleep(100);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -382,6 +382,8 @@ public:
|
||||
//! \~russian Пишет в устройство блок памяти "mb"
|
||||
ssize_t write(const PIMemoryBlock & mb) {return write(mb.data(), mb.size());}
|
||||
|
||||
void softStopThreadedRead();
|
||||
|
||||
EVENT_VHANDLER(void, flush) {;}
|
||||
|
||||
EVENT(opened);
|
||||
@@ -463,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;}
|
||||
@@ -530,16 +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() {;}
|
||||
|
||||
void softStopThreadedRead();
|
||||
|
||||
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<PIString, PIString> nfp_cache;
|
||||
|
||||
@@ -27,13 +27,7 @@ PIString DispatcherClient::address() {
|
||||
|
||||
|
||||
void DispatcherClient::close() {
|
||||
eth->stopThreadedRead();
|
||||
eth->close();
|
||||
}
|
||||
|
||||
|
||||
void DispatcherClient::terminate() {
|
||||
eth->stop();
|
||||
eth->softStopThreadedRead();
|
||||
eth->close();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user