git-svn-id: svn://db.shs.com.ru/pip@680 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -543,9 +543,30 @@ bool PIEthernet::leaveMulticastGroup(const PIString & group) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIEthernet::connect() {
|
bool PIEthernet::connect(bool threaded) {
|
||||||
connecting_ = true;
|
if (threaded) {
|
||||||
return true;
|
connecting_ = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (sock == -1) init();
|
||||||
|
if (sock == -1) return false;
|
||||||
|
memset(&PRIVATE->addr_, 0, sizeof(PRIVATE->addr_));
|
||||||
|
addr_r.set(path());
|
||||||
|
PRIVATE->addr_.sin_port = htons(addr_r.port());
|
||||||
|
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
|
||||||
|
PRIVATE->addr_.sin_family = AF_INET;
|
||||||
|
#ifdef QNX
|
||||||
|
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
|
||||||
|
#endif
|
||||||
|
connected_ = (::connect(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == 0);
|
||||||
|
if (!connected_)
|
||||||
|
piCoutObj << "Can`t connect to" << addr_r << "," << ethErrorString();
|
||||||
|
opened_ = connected_;
|
||||||
|
if (connected_) {
|
||||||
|
connecting_ = false;
|
||||||
|
connected();
|
||||||
|
}
|
||||||
|
return connected_;
|
||||||
/*if (sock == -1) return false;
|
/*if (sock == -1) return false;
|
||||||
memset(addr_, 0, sizeof(*addr_));
|
memset(addr_, 0, sizeof(*addr_));
|
||||||
parseAddress(path_, &ip_, &port_);
|
parseAddress(path_, &ip_, &port_);
|
||||||
@@ -674,11 +695,13 @@ int PIEthernet::readDevice(void * read_to, int max_size) {
|
|||||||
//piCoutObj << "readed error" << lerr << errorString().data() << parameters()[DisonnectOnTimeout];
|
//piCoutObj << "readed error" << lerr << errorString().data() << parameters()[DisonnectOnTimeout];
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if ((lerr == WSAEWOULDBLOCK || lerr == WSAETIMEDOUT) && !parameters()[DisonnectOnTimeout]) {
|
if ((lerr == WSAEWOULDBLOCK || lerr == WSAETIMEDOUT) && !parameters()[DisonnectOnTimeout]) {
|
||||||
|
#elif ANDROID
|
||||||
|
if ((lerr == EWOULDBLOCK || lerr == EAGAIN || lerr == EINTR) && !parameters()[DisonnectOnTimeout]) {
|
||||||
#else
|
#else
|
||||||
if ((lerr == EWOULDBLOCK || lerr == EAGAIN) && !parameters()[DisonnectOnTimeout]) {
|
if ((lerr == EWOULDBLOCK || lerr == EAGAIN) && !parameters()[DisonnectOnTimeout]) {
|
||||||
#endif
|
#endif
|
||||||
//piCoutObj << errorString();
|
//piCoutObj << errorString();
|
||||||
piMSleep(10);
|
//piMSleep(10);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (connected_) {
|
if (connected_) {
|
||||||
@@ -828,6 +851,8 @@ void PIEthernet::server_func(void * eth) {
|
|||||||
int lerr = ethErrorCore();
|
int lerr = ethErrorCore();
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (lerr == WSAETIMEDOUT) {
|
if (lerr == WSAETIMEDOUT) {
|
||||||
|
#elif ANDROID
|
||||||
|
if ((lerr == EAGAIN || lerr == EINTR)) {
|
||||||
#else
|
#else
|
||||||
if (lerr == EAGAIN) {
|
if (lerr == EAGAIN) {
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -252,17 +252,19 @@ public:
|
|||||||
const PIStringList & multicastGroups() const {return mcast_groups;}
|
const PIStringList & multicastGroups() const {return mcast_groups;}
|
||||||
|
|
||||||
|
|
||||||
//! Connect to TCP server with address \a readAddress(). Use only for TCP_Client
|
//! If \"threaded\" queue connect to TCP server with address \a readAddress() in
|
||||||
bool connect();
|
//! any \a read() or \a write() call. Otherwise connect immediate.
|
||||||
|
//! Use only for TCP_Client
|
||||||
|
bool connect(bool threaded = true);
|
||||||
|
|
||||||
//! Connect to TCP server with address "ip":"port". Use only for TCP_Client
|
//! Connect to TCP server with address "ip":"port". Use only for TCP_Client
|
||||||
bool connect(const PIString & ip, int port) {setPath(ip + PIStringAscii(":") + PIString::fromNumber(port)); return connect();}
|
bool connect(const PIString & ip, int port, bool threaded = true) {setPath(ip + PIStringAscii(":") + PIString::fromNumber(port)); return connect(threaded);}
|
||||||
|
|
||||||
//! Connect to TCP server with address "ip_port". Use only for TCP_Client
|
//! Connect to TCP server with address "ip_port". Use only for TCP_Client
|
||||||
bool connect(const PIString & ip_port) {setPath(ip_port); return connect();}
|
bool connect(const PIString & ip_port, bool threaded = true) {setPath(ip_port); return connect(threaded);}
|
||||||
|
|
||||||
//! Connect to TCP server with address "addr". Use only for TCP_Client
|
//! Connect to TCP server with address "addr". Use only for TCP_Client
|
||||||
bool connect(const Address & addr) {setPath(addr.toString()); return connect();}
|
bool connect(const Address & addr, bool threaded = true) {setPath(addr.toString()); return connect(threaded);}
|
||||||
|
|
||||||
//! Returns if %PIEthernet connected to TCP server. Use only for TCP_Client
|
//! Returns if %PIEthernet connected to TCP server. Use only for TCP_Client
|
||||||
bool isConnected() const {return connected_;}
|
bool isConnected() const {return connected_;}
|
||||||
|
|||||||
Reference in New Issue
Block a user