diff --git a/src/io/piconfig.cpp b/src/io/piconfig.cpp index 5aa64160..1e749c94 100755 --- a/src/io/piconfig.cpp +++ b/src/io/piconfig.cpp @@ -706,7 +706,7 @@ void PIConfig::parse() { if (!isOpened()) return; _seekToBeginDev(); other.clear(); - lines = centry = 0; + lines = 0; while (!_isEndDev()) { other.push_back(PIString()); src = str = parseLine(_readLineDev()); diff --git a/src/io/piconfig.h b/src/io/piconfig.h index 30e3daab..84f70b80 100755 --- a/src/io/piconfig.h +++ b/src/io/piconfig.h @@ -487,7 +487,6 @@ private: PIString parseLine(PIString v); void parse(); - int centry; bool own_dev, internal; PIVector includes, inc_devs; Branch all_includes; diff --git a/src/io/piconnection.cpp b/src/io/piconnection.cpp index b65261a0..5cc23bde 100755 --- a/src/io/piconnection.cpp +++ b/src/io/piconnection.cpp @@ -790,6 +790,12 @@ void PIConnection::stopAllSenders() { } +void PIConnection::destroy() { + stop(); + removeAllDevices(); +} + + PIDiagnostics * PIConnection::diagnostic(const PIString & full_path_name) const { PIIODevice * dev = deviceByFullPath(full_path_name); if (dev == 0) dev = device_names.value(full_path_name, 0); @@ -1010,6 +1016,7 @@ PIConnection::DevicePool::DeviceData::~DeviceData() { rthread = 0; } if (dev != 0) { + dev->close(); delete dev; dev = 0; } diff --git a/src/io/piconnection.h b/src/io/piconnection.h index d2c2e2d3..6606cc0d 100755 --- a/src/io/piconnection.h +++ b/src/io/piconnection.h @@ -240,6 +240,7 @@ public: //! Stop all read threads and senders void stop() {stopAllThreadedReads(); stopAllSenders();} + void destroy(); //! Returns if there are no devices in this connection bool isEmpty() const {return device_modes.isEmpty();} diff --git a/src/io/piethernet.cpp b/src/io/piethernet.cpp index 3b69256c..2d288f83 100755 --- a/src/io/piethernet.cpp +++ b/src/io/piethernet.cpp @@ -134,9 +134,9 @@ PIEthernet::PIEthernet(int sock_, PIString ip_port): PIIODevice("", ReadWrite) { PIEthernet::~PIEthernet() { //piCoutObj << "~PIEthernet ..."; - piMonitor.ethernets--; stop(); closeDevice(); + piMonitor.ethernets--; //piCoutObj << "~PIEthernet done"; } diff --git a/src/io/piethernet.h b/src/io/piethernet.h index 0f4392ff..0f2fbee4 100755 --- a/src/io/piethernet.h +++ b/src/io/piethernet.h @@ -399,10 +399,10 @@ protected: void applyOptInt(int level, int opt, int val); PRIVATE_DECLARATION - int sock, sock_s, wrote; - mutable int port_, port_s, port_c, port_r; + int sock, sock_s; + mutable int port_, port_s, port_r; bool connected_, connecting_, listen_threaded, server_bounded; - mutable PIString ip_, ip_s, ip_c, ip_r; + mutable PIString ip_, ip_s, ip_r; PIThread server_thread_; PIMutex clients_mutex; PIVector clients_; diff --git a/src/io/pifile.h b/src/io/pifile.h index a3125ca6..5a414d61 100755 --- a/src/io/pifile.h +++ b/src/io/pifile.h @@ -88,7 +88,7 @@ public: PIFile(const PIFile & other); - ~PIFile() {close();} + ~PIFile() {closeDevice();} //PIFile & operator =(const PIFile & f) {path_ = f.path_; type_ = f.type_; return *this;} diff --git a/src/io/pifiletransfer.cpp b/src/io/pifiletransfer.cpp index 5decdd1e..1803bc2a 100644 --- a/src/io/pifiletransfer.cpp +++ b/src/io/pifiletransfer.cpp @@ -49,15 +49,15 @@ bool PIFileTransfer::send(PIVector entries) { allEntries.back().dest_path = entries[i].name(); if (entries[i].isDir()) { cur_file_string = "scanning ... "; - d.setDir(entries[i].path); + scan_dir.setDir(entries[i].path); scanning = true; - PIVector fls = d.allEntries(); + PIVector fls = scan_dir.allEntries(); scanning = false; - d.up(); + scan_dir.up(); //piCout << "files rel to" << d.absolutePath(); for (int j = 0; j < fls.size(); j++) { allEntries << PFTFileInfo(fls[j]); - allEntries.back().dest_path = d.relative(fls[j].path); + allEntries.back().dest_path = scan_dir.relative(fls[j].path); //piCout << " abs path" << fls[j].path; //piCout << " rel path" << allEntries.back().dest_path; } @@ -249,7 +249,7 @@ void PIFileTransfer::receivePart(PIBaseTransfer::Part fi, PIByteArray ba, PIByte PIString PIFileTransfer::curFile() const { if (scanning) - return cur_file_string + d.scanDir(); + return cur_file_string + scan_dir.scanDir(); return cur_file_string; } diff --git a/src/io/pifiletransfer.h b/src/io/pifiletransfer.h index f2429588..d2c5e26d 100644 --- a/src/io/pifiletransfer.h +++ b/src/io/pifiletransfer.h @@ -93,7 +93,7 @@ private: PIDir dir; PIFile work_file; PIByteArray desc; - PIDir d; + PIDir scan_dir; bool started_, scanning; bool sendFiles(const PIVector &files); diff --git a/src/io/piiostring.cpp b/src/io/piiostring.cpp index daf994a8..1c13b37b 100644 --- a/src/io/piiostring.cpp +++ b/src/io/piiostring.cpp @@ -40,10 +40,6 @@ PIIOString::PIIOString(const PIString & string) { } -PIIOString::~PIIOString() { -} - - bool PIIOString::open(PIString * string, PIIODevice::DeviceMode mode_) { str = string; return PIIODevice::open(mode_); diff --git a/src/io/piiostring.h b/src/io/piiostring.h index 7110721a..7181d595 100644 --- a/src/io/piiostring.h +++ b/src/io/piiostring.h @@ -37,8 +37,7 @@ public: //! Contructs %PIIOString with \"string\" content only for read PIIOString(const PIString & string); - ~PIIOString(); - + ~PIIOString() {closeDevice();} //! Returns content PIString * string() const {return str;} diff --git a/src/io/pipacketextractor.cpp b/src/io/pipacketextractor.cpp index e4af3329..ae75ff3d 100755 --- a/src/io/pipacketextractor.cpp +++ b/src/io/pipacketextractor.cpp @@ -99,7 +99,7 @@ void PIPacketExtractor::construct() { setDevice(0); setPacketSize(0); setSplitMode(None); - allReaded = addSize = curInd = missed = missed_packets = footerInd = 0; + missed = missed_packets = footerInd = 0; header_found = false; } diff --git a/src/io/pipacketextractor.h b/src/io/pipacketextractor.h index 7f599672..306161a8 100755 --- a/src/io/pipacketextractor.h +++ b/src/io/pipacketextractor.h @@ -118,11 +118,6 @@ public: // //! Returns pointer to \a missedPackets() count. Useful for output to PIConsole const ullong * missedPackets_ptr() const {return &missed_packets;} - - - // //! Returns last successfully validated header as byte array - PIByteArray lastHeader() {return mheader;} - //! Directly call \a read() function of child %device int read(void * read_to, int max_size) {if (dev == 0) return -1; return dev->read(read_to, max_size);} @@ -172,11 +167,11 @@ private: bool openDevice() {if (dev == 0) return false; return dev->open();} PIIODevice * dev; - PIByteArray mheader, buffer, sbuffer, tmpbuf, src_header, src_footer, trbuf; + PIByteArray buffer, sbuffer, tmpbuf, src_header, src_footer, trbuf; PacketExtractorCheckFunc ret_func_header, ret_func_footer; SplitMode mode_; void * data; - int buffer_size, dataSize, packetSize_hf, allReaded, addSize, curInd, footerInd, packetSize_; + int buffer_size, dataSize, packetSize_hf, footerInd, packetSize_; double time_; bool header_found; ullong missed, missed_packets; diff --git a/src/io/pipeer.cpp b/src/io/pipeer.cpp index b7605bff..49e9b313 100755 --- a/src/io/pipeer.cpp +++ b/src/io/pipeer.cpp @@ -143,13 +143,13 @@ PIPeer::PIPeer(const PIString & n): PIIODevice() { //joinMulticastGroup("239.240.241.242"); srand(uint(PISystemTime::current(true).toMicroseconds())); //id_ = self_info.name + "_" + PIString::fromNumber(rand()); - CONNECTU(&timer, tickEvent, this, timerEvent); + CONNECTU(&sync_timer, tickEvent, this, timerEvent); prev_ifaces = PIEthernet::interfaces(); no_timer = false; // initNetwork(); sendSelfInfo(); - timer.addDelimiter(5); - timer.start(1000); + sync_timer.addDelimiter(5); + sync_timer.start(1000); } @@ -162,7 +162,7 @@ PIPeer::~PIPeer() { p._data->dt_out.stop(); p._data->t.stop(true); } - timer.stop(); + sync_timer.stop(); diag_s.stop(); diag_d.stop(); destroyEths(); diff --git a/src/io/pipeer.h b/src/io/pipeer.h index 725ef5d5..e9b5ed83 100755 --- a/src/io/pipeer.h +++ b/src/io/pipeer.h @@ -92,7 +92,6 @@ public: void init(); void destroy(); - PIString nearest_address; int sync, cnt, trace; bool was_update; PISystemTime time; @@ -200,7 +199,7 @@ private: PIVector eths_traffic, eths_mcast, eths_bcast; PIEthernet::InterfaceList prev_ifaces; PIEthernet eth_send, eth_lo; - PITimer timer; + PITimer sync_timer; PeerInfo self_info; PIVector peers; PIMap peers_map; @@ -208,7 +207,6 @@ private: PIMap > removed; PIDiagnostics diag_s, diag_d; bool destroyed, no_timer; - PIString id_; PIString trust_peer; PIMutex read_buffer_mutex; PIQueue read_buffer; diff --git a/src/io/piprotocol.h b/src/io/piprotocol.h index 138fc672..1ddab2bd 100755 --- a/src/io/piprotocol.h +++ b/src/io/piprotocol.h @@ -176,7 +176,7 @@ public: void * sendData() {return sendDataPtr;} PIPacketExtractor * packetExtractor() {return packet_ext;} - PIByteArray lastHeader() {return packet_ext->lastHeader();} +// PIByteArray lastHeader() {return packet_ext->lastHeader();} EVENT0(receiverStarted) EVENT0(receiverStopped) diff --git a/src/io/piserial.cpp b/src/io/piserial.cpp index 172006c5..7c9675d9 100755 --- a/src/io/piserial.cpp +++ b/src/io/piserial.cpp @@ -153,6 +153,7 @@ PISerial::PISerial(const PIString & device_, PISerial::Speed speed_, PIFlagshCom, ×) == -1) piCoutObj << "Unable to set timeouts for \"" << path() << "\""; GetCommMask(PRIVATE->hCom, &PRIVATE->mask); @@ -591,8 +592,8 @@ void PISerial::setReadIsBlocking(bool yes) { times.ReadIntervalTimeout = block_read ? vtime : MAXDWORD; times.ReadTotalTimeoutConstant = block_read ? 0 : 1; times.ReadTotalTimeoutMultiplier = block_read ? 0 : MAXDWORD; - times.WriteTotalTimeoutConstant = 0; - times.WriteTotalTimeoutMultiplier = block_write ? 0 : 1; + times.WriteTotalTimeoutConstant = 10; + times.WriteTotalTimeoutMultiplier = 1;//block_write ? 0 : 1; if (isOpened()) SetCommTimeouts(PRIVATE->hCom, ×); #else if (isOpened()) fcntl(fd, F_SETFL, yes ? 0 : O_NONBLOCK); @@ -619,7 +620,7 @@ int PISerial::read(void * read_to, int max_size) { int PISerial::write(const void * data, int max_size, bool wait) { -// piCoutObj << "send " << max_size;// << ": " << PIString((char*)data, max_size); + piCoutObj << "send " << max_size;// << ": " << PIString((char*)data, max_size); if (fd == -1 || !canWrite()) { //piCoutObj << "Can`t write to uninitialized COM"; return -1; @@ -636,9 +637,9 @@ int PISerial::write(const void * data, int max_size, bool wait) { wrote = ::write(fd, data, max_size); if (wait) tcdrain(fd); #endif + piCoutObj << "Wrote " << wrote << " bytes in " << path(); return (int)wrote; //piCoutObj << "Error while sending"; - //piCoutObj << "Wrote " << wrote << " bytes in " << path_; } diff --git a/src/io/piusb.cpp b/src/io/piusb.cpp index f80d4987..0caf8941 100755 --- a/src/io/piusb.cpp +++ b/src/io/piusb.cpp @@ -17,6 +17,7 @@ PIUSB::PIUSB(ushort vid, ushort pid): PIIODevice("", ReadWrite) { pid_ = pid; intefrace_ = 0; hdev = 0; + timeout_r = timeout_w = 0; interface_claimed = -1; setPath(PIString::fromNumber(vid_, 16).expandLeftTo(4, "0") + ":" + PIString::fromNumber(pid_, 16).expandLeftTo(4, "0")); setDeviceNumber(1); diff --git a/src/io/piusb.h b/src/io/piusb.h index 4e7095be..e9dc5f93 100755 --- a/src/io/piusb.h +++ b/src/io/piusb.h @@ -32,6 +32,7 @@ class PIP_EXPORT PIUSB: public PIIODevice PIIODEVICE(PIUSB) public: PIUSB(ushort vid = 0, ushort pid = 0); + ~PIUSB() {closeDevice();} struct Endpoint { Endpoint(uchar a = 0, uchar at = 0, ushort mps = 0) {address = a; attributes = at; max_packet_size = mps; parse();}