Update of /cvsroot/playerstage/code/player/libplayertcp
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26038/libplayertcp
Modified Files:
playertcp.cc playertcp.h remote_driver.cc
Log Message:
fixed server-server comms (again)
Index: remote_driver.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayertcp/remote_driver.cc,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** remote_driver.cc 23 Aug 2007 19:58:42 -0000 1.19
--- remote_driver.cc 11 Dec 2007 01:58:01 -0000 1.20
***************
*** 177,181 ****
this->sock,
false,
! &this->kill_flag);
PLAYER_MSG0(5,"Adding new TCPRemoteDriver to the PlayerTCP Client
List...Success");
--- 177,182 ----
this->sock,
false,
! &this->kill_flag,
! (this->ptcp->thread == pthread_self()));
PLAYER_MSG0(5,"Adding new TCPRemoteDriver to the PlayerTCP Client
List...Success");
***************
*** 363,367 ****
// Set the delete flag, letting PlayerTCP close the connection and
// clean up.
! this->ptcp->DeleteClient(this->queue);
}
return(0);
--- 364,369 ----
// Set the delete flag, letting PlayerTCP close the connection and
// clean up.
! this->ptcp->DeleteClient(this->queue,
! (this->ptcp->thread == pthread_self()));
}
return(0);
***************
*** 372,379 ****
{
if(this->ptcp->thread == pthread_self())
! this->ptcp->Read(0);
this->ProcessMessages();
if(this->ptcp->thread == pthread_self())
! this->ptcp->Write();
}
--- 374,384 ----
{
if(this->ptcp->thread == pthread_self())
! {
! //this->ptcp->Read(0,true);
! this->ptcp->ReadClient(this->queue);
! }
this->ProcessMessages();
if(this->ptcp->thread == pthread_self())
! this->ptcp->Write(true);
}
Index: playertcp.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayertcp/playertcp.cc,v
retrieving revision 1.71
retrieving revision 1.72
diff -C2 -d -r1.71 -r1.72
*** playertcp.cc 7 Dec 2007 01:50:15 -0000 1.71
--- playertcp.cc 11 Dec 2007 01:58:01 -0000 1.72
***************
*** 206,210 ****
}
- // should be called with client_mutex locked
QueuePointer
PlayerTCP::AddClient(struct sockaddr_in* cliaddr,
--- 206,209 ----
***************
*** 213,218 ****
int newsock,
bool send_banner,
! int* kill_flag)
{
unsigned char data[PLAYER_IDENT_STRLEN];
--- 212,221 ----
int newsock,
bool send_banner,
! int* kill_flag,
! bool have_lock)
{
+ if(!have_lock)
+ Lock();
+
unsigned char data[PLAYER_IDENT_STRLEN];
***************
*** 284,287 ****
--- 287,293 ----
j, this->clients[j].port, this->clients[j].fd);
+ if(!have_lock)
+ Unlock();
+
return(this->clients[j].queue);
}
***************
*** 291,298 ****
{
int ret;
! this->Write();
if((ret = this->Accept(0)))
return(ret);
! return(this->Read(timeout));
}
--- 297,304 ----
{
int ret;
! this->Write(false);
if((ret = this->Accept(0)))
return(ret);
! return(this->Read(timeout,false));
}
***************
*** 358,362 ****
this->host,
this->listeners[i].port,
! newsock, true, NULL);
num_accepts--;
--- 364,368 ----
this->host,
this->listeners[i].port,
! newsock, true, NULL, false);
num_accepts--;
***************
*** 396,400 ****
int
! PlayerTCP::Read(int timeout)
{
int num_available;
--- 402,406 ----
int
! PlayerTCP::Read(int timeout, bool have_lock)
{
int num_available;
***************
*** 406,415 ****
}
! pthread_mutex_lock(&this->clients_mutex);
// Poll for incoming messages
if((num_available = poll(this->client_ufds, this->num_clients, timeout)) <
0)
{
! pthread_mutex_unlock(&this->clients_mutex);
// Got interrupted by a signal; no problem
--- 412,423 ----
}
! if(!have_lock)
! Lock();
// Poll for incoming messages
if((num_available = poll(this->client_ufds, this->num_clients, timeout)) <
0)
{
! if(!have_lock)
! Unlock();
// Got interrupted by a signal; no problem
***************
*** 424,428 ****
if(!num_available)
{
! pthread_mutex_unlock(&this->clients_mutex);
return(0);
}
--- 432,437 ----
if(!num_available)
{
! if(!have_lock)
! Unlock();
return(0);
}
***************
*** 451,455 ****
this->DeleteClients();
! pthread_mutex_unlock(&this->clients_mutex);
return(0);
--- 460,465 ----
this->DeleteClients();
! if(!have_lock)
! Unlock();
return(0);
***************
*** 505,512 ****
}
- // Should be called with clients_mutex lock held
void
! PlayerTCP::DeleteClient(QueuePointer &q)
{
// Find the client and mark it for deletion.
int i;
--- 515,523 ----
}
void
! PlayerTCP::DeleteClient(QueuePointer &q, bool have_lock)
{
+ if(!have_lock)
+ Lock();
// Find the client and mark it for deletion.
int i;
***************
*** 519,522 ****
--- 530,535 ----
}
}
+ if(!have_lock)
+ Unlock();
}
***************
*** 724,730 ****
int
! PlayerTCP::Write()
{
! pthread_mutex_lock(&this->clients_mutex);
for(int i=0;i<this->num_clients;i++)
--- 737,744 ----
int
! PlayerTCP::Write(bool have_lock)
{
! if(!have_lock)
! Lock();
for(int i=0;i<this->num_clients;i++)
***************
*** 739,743 ****
this->DeleteClients();
! pthread_mutex_unlock(&this->clients_mutex);
return(0);
--- 753,758 ----
this->DeleteClients();
! if(!have_lock)
! Unlock();
return(0);
***************
*** 745,748 ****
--- 760,774 ----
int
+ PlayerTCP::ReadClient(QueuePointer q)
+ {
+ for(int cli=0; cli < this->num_clients; cli++)
+ {
+ if(this->clients[cli].queue == q)
+ return(ReadClient(cli));
+ }
+ return(-1);
+ }
+
+ int
PlayerTCP::ReadClient(int cli)
{
***************
*** 954,961 ****
(uLongf)zipped_data->data_count);
if((ret != Z_OK) && (ret != Z_STREAM_END))
- {
PLAYER_ERROR("failed to uncompress map data");
- printf("ret: %d\n", ret);
- }
else
{
--- 980,984 ----
***************
*** 1295,1296 ****
--- 1318,1331 ----
}
+
+ void
+ PlayerTCP::Lock()
+ {
+ pthread_mutex_lock(&clients_mutex);
+ }
+
+ void
+ PlayerTCP::Unlock()
+ {
+ pthread_mutex_unlock(&clients_mutex);
+ }
Index: playertcp.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayertcp/playertcp.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** playertcp.h 24 Sep 2007 20:43:41 -0000 1.26
--- playertcp.h 11 Dec 2007 01:58:01 -0000 1.27
***************
*** 137,140 ****
--- 137,143 ----
int decode_readbuffersize;
+ void Lock();
+ void Unlock();
+
public:
PlayerTCP();
***************
*** 152,167 ****
int newsock,
bool send_banner,
! int* kill_flag);
int Update(int timeout);
int Accept(int timeout);
void Close(int cli);
int ReadClient(int cli);
! int Read(int timeout);
! int Write();
int WriteClient(int cli);
void DeleteClients();
void ParseBuffer(int cli);
int HandlePlayerMessage(int cli, Message* msg);
! void DeleteClient(QueuePointer &q);
bool Listening(int port);
uint32_t GetHost() {return host;};
--- 155,172 ----
int newsock,
bool send_banner,
! int* kill_flag,
! bool have_lock);
int Update(int timeout);
int Accept(int timeout);
void Close(int cli);
int ReadClient(int cli);
! int ReadClient(QueuePointer q);
! int Read(int timeout, bool have_lock);
! int Write(bool have_lock);
int WriteClient(int cli);
void DeleteClients();
void ParseBuffer(int cli);
int HandlePlayerMessage(int cli, Message* msg);
! void DeleteClient(QueuePointer &q, bool have_lock);
bool Listening(int port);
uint32_t GetHost() {return host;};
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit