PIDir windows drives support
git-svn-id: svn://db.shs.com.ru/pip@55 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
#include "piscreentypes.h"
|
#include "piscreentypes.h"
|
||||||
#include "pistring.h"
|
#include "pistring.h"
|
||||||
|
|
||||||
class PIScreenDrawer
|
class PIP_EXPORT PIScreenDrawer
|
||||||
{
|
{
|
||||||
friend class PIScreen;
|
friend class PIScreen;
|
||||||
PIScreenDrawer(PIVector<PIVector<PIScreenTypes::Cell> > & c): cells(c) {}
|
PIScreenDrawer(PIVector<PIVector<PIScreenTypes::Cell> > & c): cells(c) {}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
class PIScreenDrawer;
|
class PIScreenDrawer;
|
||||||
|
|
||||||
class PIScreenTile: public PIObject {
|
class PIP_EXPORT PIScreenTile: public PIObject {
|
||||||
friend class PIScreen;
|
friend class PIScreen;
|
||||||
PIOBJECT_SUBCLASS(PIScreenTile, PIObject)
|
PIOBJECT_SUBCLASS(PIScreenTile, PIObject)
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include "piscreentile.h"
|
#include "piscreentile.h"
|
||||||
|
|
||||||
|
|
||||||
class TileSimple: public PIScreenTile {
|
class PIP_EXPORT TileSimple: public PIScreenTile {
|
||||||
public:
|
public:
|
||||||
TileSimple(const PIString & n = PIString());
|
TileSimple(const PIString & n = PIString());
|
||||||
typedef PIPair<PIString, PIScreenTypes::CellFormat> Row;
|
typedef PIPair<PIString, PIScreenTypes::CellFormat> Row;
|
||||||
@@ -40,7 +40,7 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TileList: public PIScreenTile {
|
class PIP_EXPORT TileList: public PIScreenTile {
|
||||||
public:
|
public:
|
||||||
TileList(const PIString & n = PIString());
|
TileList(const PIString & n = PIString());
|
||||||
enum SelectionMode {
|
enum SelectionMode {
|
||||||
@@ -68,7 +68,7 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TileButton: public PIScreenTile {
|
class PIP_EXPORT TileButton: public PIScreenTile {
|
||||||
public:
|
public:
|
||||||
TileButton(const PIString & n = PIString());
|
TileButton(const PIString & n = PIString());
|
||||||
enum EventType {
|
enum EventType {
|
||||||
@@ -85,7 +85,7 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TileButtons: public PIScreenTile {
|
class PIP_EXPORT TileButtons: public PIScreenTile {
|
||||||
public:
|
public:
|
||||||
TileButtons(const PIString & n = PIString());
|
TileButtons(const PIString & n = PIString());
|
||||||
enum EventType {
|
enum EventType {
|
||||||
@@ -103,7 +103,7 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TileCheck: public PIScreenTile {
|
class PIP_EXPORT TileCheck: public PIScreenTile {
|
||||||
public:
|
public:
|
||||||
TileCheck(const PIString & n = PIString());
|
TileCheck(const PIString & n = PIString());
|
||||||
enum EventType {
|
enum EventType {
|
||||||
@@ -121,7 +121,7 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TileProgress: public PIScreenTile {
|
class PIP_EXPORT TileProgress: public PIScreenTile {
|
||||||
public:
|
public:
|
||||||
TileProgress(const PIString & n = PIString());
|
TileProgress(const PIString & n = PIString());
|
||||||
PIScreenTypes::CellFormat format;
|
PIScreenTypes::CellFormat format;
|
||||||
@@ -137,7 +137,7 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TilePICout: public TileList {
|
class PIP_EXPORT TilePICout: public TileList {
|
||||||
public:
|
public:
|
||||||
TilePICout(const PIString & n = PIString());
|
TilePICout(const PIString & n = PIString());
|
||||||
PIScreenTypes::CellFormat format;
|
PIScreenTypes::CellFormat format;
|
||||||
|
|||||||
@@ -54,14 +54,12 @@ const PIChar PIDir::separator = '/';
|
|||||||
|
|
||||||
|
|
||||||
PIDir::PIDir(const PIString & dir) {
|
PIDir::PIDir(const PIString & dir) {
|
||||||
path_ = dir;
|
setDir(dir);
|
||||||
cleanPath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIDir::PIDir(const PIFile & file) {
|
PIDir::PIDir(const PIFile & file) {
|
||||||
path_ = file.path();
|
setDir(file.path());
|
||||||
cleanPath();
|
|
||||||
if (isExists()) return;
|
if (isExists()) return;
|
||||||
int pos = path_.findLast(separator);
|
int pos = path_.findLast(separator);
|
||||||
path_.cutRight(path_.size_s() - pos);
|
path_.cutRight(path_.size_s() - pos);
|
||||||
@@ -75,18 +73,42 @@ bool PIDir::operator ==(const PIDir & d) const {
|
|||||||
|
|
||||||
bool PIDir::isAbsolute() const {
|
bool PIDir::isAbsolute() const {
|
||||||
if (path_.isEmpty()) return false;
|
if (path_.isEmpty()) return false;
|
||||||
#ifdef WINDOWS
|
/*#ifdef WINDOWS
|
||||||
if (path_.size_s() < 2) return false;
|
if (path_.size_s() < 2) return false;
|
||||||
return (path_.mid(1, 2).contains(":"));
|
return (path_.mid(1, 2).contains(":"));
|
||||||
#else
|
#else
|
||||||
return (path_[0] == separator);
|
return (path_[0] == separator);
|
||||||
|
#endif*/
|
||||||
|
return (path_[0] == separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIString PIDir::path() const {
|
||||||
|
#ifdef WINDOWS
|
||||||
|
if (path_.startsWith(separator)) {
|
||||||
|
if (path_.length() == 1)
|
||||||
|
return separator;
|
||||||
|
else
|
||||||
|
return path_.mid(1);
|
||||||
|
} else
|
||||||
#endif
|
#endif
|
||||||
|
return path_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIString PIDir::absolutePath() const {
|
PIString PIDir::absolutePath() const {
|
||||||
if (isAbsolute()) return path_;
|
if (isAbsolute()) {
|
||||||
return PIDir(PIDir::current().path_ + separator + path_).path_;
|
#ifdef WINDOWS
|
||||||
|
if (path_.startsWith(separator)) {
|
||||||
|
if (path_.length() == 1)
|
||||||
|
return separator;
|
||||||
|
else
|
||||||
|
return path_.mid(1);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
return path_;
|
||||||
|
}
|
||||||
|
return PIDir(PIDir::current().path() + separator + path_).path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -96,13 +118,10 @@ PIDir & PIDir::cleanPath() {
|
|||||||
path_ = ".";
|
path_ = ".";
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
path_.replaceAll(PIString(separator) + PIString(separator), PIString(separator));
|
PIString sep = PIString(separator);
|
||||||
|
path_.replaceAll(sep + sep, sep);
|
||||||
bool is_abs = isAbsolute();
|
bool is_abs = isAbsolute();
|
||||||
PIStringList l = PIString(p).split(separator);
|
PIStringList l = PIString(p).split(separator);
|
||||||
#ifdef WINDOWS
|
|
||||||
PIString letter;
|
|
||||||
if (is_abs) letter = l.take_front();
|
|
||||||
#endif
|
|
||||||
l.removeAll(".");
|
l.removeAll(".");
|
||||||
l.removeAll("");
|
l.removeAll("");
|
||||||
for (int i = 0; i < l.size_s() - 1; ++i) {
|
for (int i = 0; i < l.size_s() - 1; ++i) {
|
||||||
@@ -120,12 +139,8 @@ PIDir & PIDir::cleanPath() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
path_ = l.join(separator);
|
path_ = l.join(separator);
|
||||||
if (is_abs) {
|
if (is_abs)
|
||||||
path_.prepend(separator);
|
path_.prepend(separator);
|
||||||
#ifdef WINDOWS
|
|
||||||
path_.prepend(letter);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
if (path_.isEmpty()) path_ = ".";
|
if (path_.isEmpty()) path_ = ".";
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -149,6 +164,11 @@ PIString PIDir::relative(const PIString & path) const {
|
|||||||
|
|
||||||
PIDir & PIDir::setDir(const PIString & path) {
|
PIDir & PIDir::setDir(const PIString & path) {
|
||||||
path_ = path;
|
path_ = path;
|
||||||
|
#ifdef WINDOWS
|
||||||
|
if (path_.length() > 2)
|
||||||
|
if (path_.mid(1, 2).contains(":"))
|
||||||
|
path_.prepend(separator);
|
||||||
|
#endif
|
||||||
cleanPath();
|
cleanPath();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -167,7 +187,7 @@ bool PIDir::make(bool withParents) {
|
|||||||
PIString tp;
|
PIString tp;
|
||||||
bool is_abs = isAbsolute();
|
bool is_abs = isAbsolute();
|
||||||
if (withParents) {
|
if (withParents) {
|
||||||
PIStringList l = d.path_.split(separator);
|
PIStringList l = d.path().split(separator);
|
||||||
for (int i = l.size_s() - 1; i >= 0; --i) {
|
for (int i = l.size_s() - 1; i >= 0; --i) {
|
||||||
if (i > 1) tp = PIStringList(l).remove(i, l.size_s() - i).join(separator);
|
if (i > 1) tp = PIStringList(l).remove(i, l.size_s() - i).join(separator);
|
||||||
else {
|
else {
|
||||||
@@ -187,7 +207,7 @@ bool PIDir::make(bool withParents) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
if (makeDir(d.path_)) return true;
|
if (makeDir(d.path())) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,15 +221,41 @@ PIVector<PIFile::FileInfo> PIDir::entries() {
|
|||||||
else if (!dp.endsWith(separator)) dp += separator;
|
else if (!dp.endsWith(separator)) dp += separator;
|
||||||
//piCout << "entries from" << p;
|
//piCout << "entries from" << p;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
if (dp == separator) {
|
||||||
|
char letters[1024];
|
||||||
|
PIFile::FileInfo fi;
|
||||||
|
DWORD ll = GetLogicalDriveStrings(1023, letters);
|
||||||
|
PIString clet;
|
||||||
|
for (int i = 0; i < ll; ++i) {
|
||||||
|
if (letters[i] == '\0') {
|
||||||
|
clet.resize(2);
|
||||||
|
fi.path = clet;
|
||||||
|
fi.flags = PIFile::FileInfo::Dir;
|
||||||
|
l << fi;
|
||||||
|
clet.clear();
|
||||||
|
} else
|
||||||
|
clet += PIChar(letters[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
WIN32_FIND_DATA fd; memset(&fd, 0, sizeof(fd));
|
WIN32_FIND_DATA fd; memset(&fd, 0, sizeof(fd));
|
||||||
p += "\\*";
|
p += "\\*";
|
||||||
void * hf = FindFirstFile((LPCTSTR)(p.data()), &fd);
|
void * hf = FindFirstFile((LPCTSTR)(p.data()), &fd);
|
||||||
if (!hf) return l;
|
if (!hf) return l;
|
||||||
|
bool hdd = false;
|
||||||
do {
|
do {
|
||||||
l << PIFile::fileInfo(dp + PIString(fd.cFileName));
|
PIString fn(fd.cFileName);
|
||||||
|
if (fn == "..") hdd = true;
|
||||||
|
l << PIFile::fileInfo(dp + fn);
|
||||||
memset(&fd, 0, sizeof(fd));
|
memset(&fd, 0, sizeof(fd));
|
||||||
} while (FindNextFile(hf, &fd) != 0);
|
} while (FindNextFile(hf, &fd) != 0);
|
||||||
FindClose(hf);
|
FindClose(hf);
|
||||||
|
if (!hdd) {
|
||||||
|
PIFile::FileInfo fi;
|
||||||
|
fi.path = "..";
|
||||||
|
fi.flags = PIFile::FileInfo::Dir | PIFile::FileInfo::DotDot;
|
||||||
|
l.push_front(fi);
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
dirent ** list;
|
dirent ** list;
|
||||||
int cnt = scandir(
|
int cnt = scandir(
|
||||||
@@ -260,6 +306,7 @@ PIDir PIDir::current() {
|
|||||||
if (GetCurrentDirectory(1024, (LPTSTR)rc) == 0) return PIString();
|
if (GetCurrentDirectory(1024, (LPTSTR)rc) == 0) return PIString();
|
||||||
PIString ret(rc);
|
PIString ret(rc);
|
||||||
ret.replaceAll("\\", PIDir::separator);
|
ret.replaceAll("\\", PIDir::separator);
|
||||||
|
ret.prepend(separator);
|
||||||
return PIDir(ret);
|
return PIDir(ret);
|
||||||
#else
|
#else
|
||||||
if (getcwd(rc, 1024) == 0) return PIString();
|
if (getcwd(rc, 1024) == 0) return PIString();
|
||||||
@@ -280,6 +327,7 @@ PIDir PIDir::home() {
|
|||||||
PIString s(rc);
|
PIString s(rc);
|
||||||
s.replaceAll("\\", PIDir::separator);
|
s.replaceAll("\\", PIDir::separator);
|
||||||
delete[] rc;
|
delete[] rc;
|
||||||
|
s.prepend(separator);
|
||||||
return PIDir(s);
|
return PIDir(s);
|
||||||
#else
|
#else
|
||||||
rc = getenv("HOME");
|
rc = getenv("HOME");
|
||||||
@@ -302,6 +350,7 @@ PIDir PIDir::temporary() {
|
|||||||
PIString s(rc);
|
PIString s(rc);
|
||||||
s.replaceAll("\\", PIDir::separator);
|
s.replaceAll("\\", PIDir::separator);
|
||||||
delete[] rc;
|
delete[] rc;
|
||||||
|
s.prepend(separator);
|
||||||
return PIDir(s);
|
return PIDir(s);
|
||||||
#else
|
#else
|
||||||
rc = tmpnam(0);
|
rc = tmpnam(0);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//! Returns if this directory is exists
|
//! Returns if this directory is exists
|
||||||
bool isExists() const {return PIDir::isExists(path_);}
|
bool isExists() const {return PIDir::isExists(path());}
|
||||||
|
|
||||||
//! Returns if path of this directory is absolute
|
//! Returns if path of this directory is absolute
|
||||||
bool isAbsolute() const;
|
bool isAbsolute() const;
|
||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//! Returns path of this directory
|
//! Returns path of this directory
|
||||||
const PIString & path() const {return path_;}
|
PIString path() const;
|
||||||
|
|
||||||
//! Returns absolute path of this directory
|
//! Returns absolute path of this directory
|
||||||
PIString absolutePath() const;
|
PIString absolutePath() const;
|
||||||
@@ -60,7 +60,7 @@ public:
|
|||||||
PIDir & cleanPath();
|
PIDir & cleanPath();
|
||||||
|
|
||||||
//! Returns %PIDir with simplified path of this directory
|
//! Returns %PIDir with simplified path of this directory
|
||||||
PIDir cleanedPath() const {PIDir d(path_); d.cleanPath(); return d;}
|
PIDir cleanedPath() const {PIDir d(path()); d.cleanPath(); return d;}
|
||||||
|
|
||||||
//! Returns relative to this directory path "path"
|
//! Returns relative to this directory path "path"
|
||||||
PIString relative(const PIString & path) const;
|
PIString relative(const PIString & path) const;
|
||||||
@@ -69,13 +69,14 @@ public:
|
|||||||
PIDir & setDir(const PIString & path);
|
PIDir & setDir(const PIString & path);
|
||||||
|
|
||||||
//! Set this directory path as current for application
|
//! Set this directory path as current for application
|
||||||
bool setCurrent() {return PIDir::setCurrent(path_);}
|
bool setCurrent() {return PIDir::setCurrent(path());}
|
||||||
|
|
||||||
|
|
||||||
/** \brief Returns this directory content
|
/** \brief Returns this directory content
|
||||||
* \details Scan this directory and returns all directories
|
* \details Scan this directory and returns all directories
|
||||||
* and files in one list, sorted alphabetically. This list
|
* and files in one list, sorted alphabetically. This list
|
||||||
* contains also "." and ".." members.
|
* contains also "." and ".." members. There are absolute
|
||||||
|
* pathes in returned list.
|
||||||
* \attention This function doesn`t scan content of inner
|
* \attention This function doesn`t scan content of inner
|
||||||
* directories! */
|
* directories! */
|
||||||
PIVector<PIFile::FileInfo> entries();
|
PIVector<PIFile::FileInfo> entries();
|
||||||
@@ -83,13 +84,14 @@ public:
|
|||||||
/** \brief Returns all this directory content
|
/** \brief Returns all this directory content
|
||||||
* \details Scan this directory recursively and returns all
|
* \details Scan this directory recursively and returns all
|
||||||
* directories and files in one list, sorted alphabetically.
|
* directories and files in one list, sorted alphabetically.
|
||||||
* This list doesn`t contains "." and ".." members.
|
* This list doesn`t contains "." and ".." members. There
|
||||||
* Files placed after directories in this list */
|
* are absolute pathes in returned list, and
|
||||||
|
* files placed after directories in this list */
|
||||||
PIVector<PIFile::FileInfo> allEntries();
|
PIVector<PIFile::FileInfo> allEntries();
|
||||||
|
|
||||||
bool make(bool withParents = true);
|
bool make(bool withParents = true);
|
||||||
bool remove() {return PIDir::remove(path_);}
|
bool remove() {return PIDir::remove(path());}
|
||||||
bool rename(const PIString & new_name) {if (!PIDir::rename(path_, new_name)) return false; path_ = new_name; return true;}
|
bool rename(const PIString & new_name) {if (!PIDir::rename(path(), new_name)) return false; setDir(new_name); return true;}
|
||||||
PIDir & cd(const PIString & path);
|
PIDir & cd(const PIString & path);
|
||||||
PIDir & up() {return cd("..");}
|
PIDir & up() {return cd("..");}
|
||||||
|
|
||||||
@@ -107,7 +109,7 @@ public:
|
|||||||
static bool remove(const PIString & path) {return removeDir(path);}
|
static bool remove(const PIString & path) {return removeDir(path);}
|
||||||
static bool rename(const PIString & path, const PIString & new_name) {return PIDir::renameDir(path, new_name);}
|
static bool rename(const PIString & path, const PIString & new_name) {return PIDir::renameDir(path, new_name);}
|
||||||
static bool setCurrent(const PIString & path);
|
static bool setCurrent(const PIString & path);
|
||||||
static bool setCurrent(const PIDir & dir) {return setCurrent(dir.path_);}
|
static bool setCurrent(const PIDir & dir) {return setCurrent(dir.path());}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool makeDir(const PIString & path);
|
static bool makeDir(const PIString & path);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
typedef PIFlags<FileInfo::Flag> Flags;
|
typedef PIFlags<FileInfo::Flag> Flags;
|
||||||
struct Permissions {
|
struct Permissions {
|
||||||
Permissions(uchar r = 0): raw(r) {}
|
Permissions(uchar r = 0): raw(r) {}
|
||||||
Permissions(bool r, bool w, bool e): raw(0) {read = w; write = w; exec = e;}
|
Permissions(bool r, bool w, bool e): raw(0) {read = r; write = w; exec = e;}
|
||||||
PIString toString() const {return PIString(read ? "r" : "-") + PIString(write ? "w" : "-") + PIString(exec ? "x" : "-");}
|
PIString toString() const {return PIString(read ? "r" : "-") + PIString(write ? "w" : "-") + PIString(exec ? "x" : "-");}
|
||||||
operator int() const {return raw;}
|
operator int() const {return raw;}
|
||||||
Permissions & operator =(int v) {raw = v; return *this;}
|
Permissions & operator =(int v) {raw = v; return *this;}
|
||||||
|
|||||||
@@ -122,7 +122,10 @@ PIString PIPeer::PeerInfo::fastestAddress() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PIPeer::PIPeer(const PIString & name_): PIObject() {
|
PIPeer::PIPeer(const PIString & name_): PIObject() {
|
||||||
|
destroyed = false;
|
||||||
setName(name_);
|
setName(name_);
|
||||||
self_info.name = name_;
|
self_info.name = name_;
|
||||||
self_info.dist = 0;
|
self_info.dist = 0;
|
||||||
@@ -131,15 +134,16 @@ PIPeer::PIPeer(const PIString & name_): PIObject() {
|
|||||||
srand(uint(PISystemTime::current(true).toMicroseconds()));
|
srand(uint(PISystemTime::current(true).toMicroseconds()));
|
||||||
//id_ = self_info.name + "_" + PIString::fromNumber(rand());
|
//id_ = self_info.name + "_" + PIString::fromNumber(rand());
|
||||||
CONNECTU(&timer, tickEvent, this, timerEvent);
|
CONNECTU(&timer, tickEvent, this, timerEvent);
|
||||||
|
prev_ifaces = PIEthernet::interfaces();
|
||||||
initNetwork();
|
initNetwork();
|
||||||
sendSelfInfo();
|
sendSelfInfo();
|
||||||
prev_ifaces = PIEthernet::interfaces();
|
|
||||||
timer.addDelimiter(5);
|
timer.addDelimiter(5);
|
||||||
timer.start(1000);
|
timer.start(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIPeer::~PIPeer() {
|
PIPeer::~PIPeer() {
|
||||||
|
destroyed = true;
|
||||||
timer.stop();
|
timer.stop();
|
||||||
diag_s.stop();
|
diag_s.stop();
|
||||||
diag_d.stop();
|
diag_d.stop();
|
||||||
@@ -148,10 +152,10 @@ PIPeer::~PIPeer() {
|
|||||||
i->stopThreadedRead();
|
i->stopThreadedRead();
|
||||||
piForeach (PIEthernet * i, eths_bcast)
|
piForeach (PIEthernet * i, eths_bcast)
|
||||||
i->stopThreadedRead();
|
i->stopThreadedRead();
|
||||||
eth_send.close();
|
|
||||||
eth_lo.stopThreadedRead();
|
eth_lo.stopThreadedRead();
|
||||||
sendSelfRemove();
|
sendSelfRemove();
|
||||||
destroyMBcasts();
|
destroyMBcasts();
|
||||||
|
eth_send.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -170,7 +174,6 @@ void PIPeer::timerEvent(void * data, int delim) {
|
|||||||
|
|
||||||
void PIPeer::initEths(PIStringList al) {
|
void PIPeer::initEths(PIStringList al) {
|
||||||
PIEthernet * ce;
|
PIEthernet * ce;
|
||||||
PIEthernet::InterfaceList il = PIEthernet::interfaces();
|
|
||||||
const PIEthernet::Interface * cint = 0;
|
const PIEthernet::Interface * cint = 0;
|
||||||
piForeachC (PIString & a, al) {
|
piForeachC (PIString & a, al) {
|
||||||
ce = new PIEthernet();
|
ce = new PIEthernet();
|
||||||
@@ -183,7 +186,7 @@ void PIPeer::initEths(PIStringList al) {
|
|||||||
ce->setReadAddress(a, p);
|
ce->setReadAddress(a, p);
|
||||||
if (ce->open()) {
|
if (ce->open()) {
|
||||||
eths_traffic << ce;
|
eths_traffic << ce;
|
||||||
cint = il.getByAddress(a);
|
cint = prev_ifaces.getByAddress(a);
|
||||||
self_info.addresses << PeerInfo::Address(ce->path(), cint == 0 ? "255.255.255.0" : cint->netmask);
|
self_info.addresses << PeerInfo::Address(ce->path(), cint == 0 ? "255.255.255.0" : cint->netmask);
|
||||||
CONNECTU(ce, threadedReadEvent, this, dataRead);
|
CONNECTU(ce, threadedReadEvent, this, dataRead);
|
||||||
ce->startThreadedRead();
|
ce->startThreadedRead();
|
||||||
@@ -204,7 +207,6 @@ void PIPeer::initEths(PIStringList al) {
|
|||||||
void PIPeer::initMBcasts(PIStringList al) {
|
void PIPeer::initMBcasts(PIStringList al) {
|
||||||
destroyMBcasts();
|
destroyMBcasts();
|
||||||
PIEthernet * ce;
|
PIEthernet * ce;
|
||||||
PIEthernet::InterfaceList il = PIEthernet::interfaces();
|
|
||||||
const PIEthernet::Interface * cint;
|
const PIEthernet::Interface * cint;
|
||||||
PIString nm;
|
PIString nm;
|
||||||
al << _PIPEER_MULTICAST_IP;
|
al << _PIPEER_MULTICAST_IP;
|
||||||
@@ -227,7 +229,7 @@ void PIPeer::initMBcasts(PIStringList al) {
|
|||||||
ce->setDebug(false);
|
ce->setDebug(false);
|
||||||
ce->setName("__S__PIPeer_bcast_eth_" + a);
|
ce->setName("__S__PIPeer_bcast_eth_" + a);
|
||||||
ce->setParameters(PIEthernet::Broadcast);
|
ce->setParameters(PIEthernet::Broadcast);
|
||||||
cint = il.getByAddress(a);
|
cint = prev_ifaces.getByAddress(a);
|
||||||
nm = (cint == 0) ? "255.255.255.0" : cint->netmask;
|
nm = (cint == 0) ? "255.255.255.0" : cint->netmask;
|
||||||
ce->setSendAddress(PIEthernet::getBroadcast(a, nm), _PIPEER_BROADCAST_PORT);
|
ce->setSendAddress(PIEthernet::getBroadcast(a, nm), _PIPEER_BROADCAST_PORT);
|
||||||
ce->setReadAddress(a, _PIPEER_BROADCAST_PORT);
|
ce->setReadAddress(a, _PIPEER_BROADCAST_PORT);
|
||||||
@@ -240,7 +242,7 @@ void PIPeer::initMBcasts(PIStringList al) {
|
|||||||
eth_lo.setDebug(false);
|
eth_lo.setDebug(false);
|
||||||
eth_lo.setName("__S__PIPeer_eth_loopback");
|
eth_lo.setName("__S__PIPeer_eth_loopback");
|
||||||
eth_lo.setParameters(0);
|
eth_lo.setParameters(0);
|
||||||
cint = il.getByAddress("127.0.0.1");
|
cint = prev_ifaces.getByAddress("127.0.0.1");
|
||||||
for (int p = _PIPEER_LOOPBACK_PORT_S; p <= _PIPEER_LOOPBACK_PORT_E; ++p) {
|
for (int p = _PIPEER_LOOPBACK_PORT_S; p <= _PIPEER_LOOPBACK_PORT_E; ++p) {
|
||||||
eth_lo.setReadAddress("127.0.0.1", p);
|
eth_lo.setReadAddress("127.0.0.1", p);
|
||||||
if (eth_lo.open()) {
|
if (eth_lo.open()) {
|
||||||
@@ -345,6 +347,7 @@ void PIPeer::dtReceived(const PIString & from, const PIByteArray & data) {
|
|||||||
|
|
||||||
|
|
||||||
bool PIPeer::dataRead(uchar * readed, int size) {
|
bool PIPeer::dataRead(uchar * readed, int size) {
|
||||||
|
if (destroyed) return true;
|
||||||
if (size < 16) return true;
|
if (size < 16) return true;
|
||||||
PIByteArray ba(readed, size), sba, pba;
|
PIByteArray ba(readed, size), sba, pba;
|
||||||
int type, cnt;
|
int type, cnt;
|
||||||
@@ -444,6 +447,7 @@ bool PIPeer::dataRead(uchar * readed, int size) {
|
|||||||
|
|
||||||
|
|
||||||
bool PIPeer::mbcastRead(uchar * data, int size) {
|
bool PIPeer::mbcastRead(uchar * data, int size) {
|
||||||
|
if (destroyed) return true;
|
||||||
if (size < 8) return true;
|
if (size < 8) return true;
|
||||||
int type, dist;
|
int type, dist;
|
||||||
PIByteArray ba(data, size);
|
PIByteArray ba(data, size);
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ private:
|
|||||||
PIMap<PIString, PIVector<PeerInfo * > > addresses_map; // map {"to" = list of nearest peers}
|
PIMap<PIString, PIVector<PeerInfo * > > addresses_map; // map {"to" = list of nearest peers}
|
||||||
PIMap<PIString, PIPair<int, PISystemTime> > removed;
|
PIMap<PIString, PIPair<int, PISystemTime> > removed;
|
||||||
PIDiagnostics diag_s, diag_d;
|
PIDiagnostics diag_s, diag_d;
|
||||||
|
bool destroyed;
|
||||||
//PIString id_;
|
//PIString id_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user