git-svn-id: svn://db.shs.com.ru/pip@471 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-04-26 13:55:05 +00:00
parent ed059005f9
commit 9c3a2cf8ca
15 changed files with 373 additions and 202 deletions

View File

@@ -268,7 +268,7 @@ public:
static BinLogInfo getLogInfo(const PIString & path);
protected:
PIString fullPathPrefix() const {return "binlog";}
PIString fullPathPrefix() const {return PIStringAscii("binlog");}
PIString constructFullPathDevice() const;
void configureFromFullPathDevice(const PIString & full_path);
int readDevice(void *read_to, int max_size);

View File

@@ -286,7 +286,7 @@ public:
//! \}
protected:
PIString fullPathPrefix() const {return "file";}
PIString fullPathPrefix() const {return PIStringAscii("file");}
PIString constructFullPathDevice() const;
void configureFromFullPathDevice(const PIString & full_path);
int readDevice(void * read_to, int max_size);

View File

@@ -157,7 +157,7 @@ private:
int readDevice(void * read_to, int max_size) {if (dev == 0) return -1; return dev->read(read_to, max_size);}
int writeDevice(const void * data, int max_size) {if (dev == 0) return -1; return dev->write(data, max_size);}
bool threadedRead(uchar * readed, int size);
PIString fullPathPrefix() const {return "pckext";}
PIString fullPathPrefix() const {return PIStringAscii("pckext");}
PIString constructFullPathDevice() const;
bool openDevice() {if (dev == 0) return false; return dev->open();}

View File

@@ -448,11 +448,12 @@ bool PIPeer::sendInternal(const PIString & to, const PIByteArray & data) {
void PIPeer::dtReceived(const PIString & from, const PIByteArray & data) {
PIByteArray ba = data;
dataReceived(from, data);
dataReceivedEvent(from, data);
if (trust_peer.isEmpty() || trust_peer == from) {
read_buffer_mutex.lock();
if (read_buffer.size_s() < read_buffer_size) read_buffer.enqueue(data);
if (read_buffer.size_s() < read_buffer_size) read_buffer.enqueue(ba);
read_buffer_mutex.unlock();
}
}
@@ -860,10 +861,11 @@ bool PIPeer::openDevice() {
diag_d.reset();
diag_s.reset();
//piCoutObj << "open...";
PIMutexLocker ml(peers_mutex);
if (trust_peer.isEmpty())
return !peers.isEmpty();
return hasPeer(trust_peer);
return true;
// PIMutexLocker ml(peers_mutex);
// if (trust_peer.isEmpty())
// return !peers.isEmpty();
// return hasPeer(trust_peer);
}

View File

@@ -166,7 +166,7 @@ private:
bool openDevice();
bool closeDevice();
PIString fullPathPrefix() const {return "peer";}
PIString fullPathPrefix() const {return PIStringAscii("peer");}
PIString constructFullPathDevice() const;
void configureFromFullPathDevice(const PIString &full_path);
int readDevice(void * read_to, int max_size);

View File

@@ -205,7 +205,7 @@ public:
//! \}
protected:
PIString fullPathPrefix() const {return "ser";}
PIString fullPathPrefix() const {return PIStringAscii("ser");}
PIString constructFullPathDevice() const;
void configureFromFullPathDevice(const PIString & full_path);
bool configureDevice(const void * e_main, const void * e_parent = 0);

View File

@@ -54,7 +54,7 @@
*
*/
//REGISTER_DEVICE(PISharedMemory);
REGISTER_DEVICE(PISharedMemory)
PRIVATE_DEFINITION_START(PISharedMemory)
PIByteArray name;
@@ -71,7 +71,7 @@ PRIVATE_DEFINITION_END(PISharedMemory)
PISharedMemory::PISharedMemory(): PIIODevice() {
initPrivate();
dsize = -1;
dsize = 65536;
}
@@ -93,6 +93,7 @@ PISharedMemory::PISharedMemory(const PISharedMemory & other) {
bool PISharedMemory::openDevice() {
close();
piCoutObj << "try open" << path() << dsize;
#ifdef WINDOWS
DWORD m = PAGE_READWRITE;
if (!isWriteable()) m = PAGE_READONLY;
@@ -100,14 +101,14 @@ bool PISharedMemory::openDevice() {
PRIVATE->name.push_back(0);
PRIVATE->map = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, m, 0, (DWORD)dsize, (const char *)PRIVATE->name.data());
if (!PRIVATE->map) {
piCoutObj << "CreateFileMapping error," << errorString();
piCoutObj << path() << dsize << "CreateFileMapping error," << errorString();
return false;
}
if (!isWriteable()) m = FILE_MAP_READ;
else m = FILE_MAP_ALL_ACCESS;
PRIVATE->data = MapViewOfFile(PRIVATE->map, m, 0, 0, dsize);
if (!PRIVATE->data) {
piCoutObj << "MapViewOfFile error," << errorString();
piCoutObj << path() << dsize << "MapViewOfFile error," << errorString();
CloseHandle(PRIVATE->map);
return false;
}
@@ -166,6 +167,26 @@ bool PISharedMemory::closeDevice() {
}
PIString PISharedMemory::constructFullPathDevice() const {
PIString ret;
ret << path() << ":" << dsize;
return ret;
}
void PISharedMemory::configureFromFullPathDevice(const PIString & full_path) {
initPrivate();
PIStringList pl = full_path.split(":");
for (int i = 0; i < pl.size_s(); ++i) {
PIString p(pl[i]);
switch (i) {
case 0: setPath(p); break;
case 1: dsize = p.toInt(); break;
}
}
}
void PISharedMemory::initPrivate() {
#ifdef WINDOWS
PRIVATE->map = 0;

View File

@@ -71,6 +71,9 @@ public:
protected:
bool openDevice();
bool closeDevice();
PIString fullPathPrefix() const {return PIStringAscii("shm");}
PIString constructFullPathDevice() const;
void configureFromFullPathDevice(const PIString & full_path);
int readDevice(void * read_to, int max_size) {return read(read_to, max_size, 0);}
int writeDevice(const void * data, int max_size) {return write(data, max_size, 0);}

View File

@@ -61,9 +61,7 @@ int PITransparentDevice::writeDevice(const void * data, int max_size) {
}
PIString PITransparentDevice::fullPathPrefix() const {
return PIStringAscii("tr");
}
bool PITransparentDevice::openDevice() {

View File

@@ -41,7 +41,7 @@ protected:
bool closeDevice();
int readDevice(void * read_to, int max_size);
int writeDevice(const void * data, int max_size);
PIString fullPathPrefix() const;
PIString fullPathPrefix() const {return PIStringAscii("tr");}
PIMutex que_mutex;
PIQueue<PIByteArray> que;

View File

@@ -126,7 +126,7 @@ public:
void flush();
protected:
PIString fullPathPrefix() const {return "usb";}
PIString fullPathPrefix() const {return PIStringAscii("usb");}
bool configureDevice(const void * e_main, const void * e_parent = 0);
PIString constructFullPathDevice() const;
void configureFromFullPathDevice(const PIString & full_path);