piethernet
git-svn-id: svn://db.shs.com.ru/pip@38 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -613,6 +613,14 @@ int PIEthernet::write(const void * data, int max_size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::clientDeleted() {
|
||||
clients_mutex.lock();
|
||||
clients_.removeOne((PIEthernet*)emitter());
|
||||
clients_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIEthernet::server_func(void * eth) {
|
||||
PIEthernet * ce = (PIEthernet * )eth;
|
||||
if (ce->listen_threaded) {
|
||||
@@ -628,14 +636,27 @@ void PIEthernet::server_func(void * eth) {
|
||||
socklen_t slen = sizeof(client_addr);
|
||||
int s = accept(ce->sock, (sockaddr * )&client_addr, &slen);
|
||||
if (s == -1) {
|
||||
int lerr = ethErrorCore();
|
||||
#ifdef WINDOWS
|
||||
if (lerr == WSAETIMEDOUT) {
|
||||
#else
|
||||
if (lerr == EAGAIN) {
|
||||
#endif
|
||||
piMSleep(10);
|
||||
return;
|
||||
}
|
||||
if (ce->debug()) piCout << "[PIEthernet] Can`t accept new connection, " << ethErrorString();
|
||||
piMSleep(10);
|
||||
return;
|
||||
}
|
||||
PIString ip(inet_ntoa(client_addr.sin_addr));
|
||||
ip += ":" + PIString::fromNumber(htons(client_addr.sin_port));
|
||||
ce->clients_ << new PIEthernet(s, ip);
|
||||
ce->newConnection(ce->clients_.back());
|
||||
PIEthernet * e = new PIEthernet(s, ip);
|
||||
ce->clients_mutex.lock();
|
||||
CONNECTU(e, deleted, ce, clientDeleted)
|
||||
ce->clients_ << e;
|
||||
ce->clients_mutex.unlock();
|
||||
ce->newConnection(e);
|
||||
//cout << "connected " << ip << endl;
|
||||
//char d[256];
|
||||
//cout << " recv " << recv(s, d, 256, 0) << endl;
|
||||
|
||||
Reference in New Issue
Block a user