Update of /cvsroot/playerstage/code/player/server
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21813/server
Modified Files:
server.cc
Log Message:
tweaks to allow auto-assignment of ports
Index: server.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/server.cc,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** server.cc 21 Aug 2007 21:25:55 -0000 1.38
--- server.cc 24 Sep 2007 20:43:41 -0000 1.39
***************
*** 125,128 ****
--- 125,129 ----
int gz_serverid = -1;
int* ports;
+ int* new_ports;
int num_ports;
char* cfgfilename;
***************
*** 195,198 ****
--- 196,201 ----
ports = (int*)calloc(deviceTable->Size(),sizeof(int));
assert(ports);
+ new_ports = (int*)calloc(deviceTable->Size(),sizeof(int));
+ assert(new_ports);
num_ports = 0;
for(Device* device = deviceTable->GetFirstDevice();
***************
*** 213,217 ****
}
! if(ptcp->Listen(ports, num_ports) < 0)
{
PLAYER_ERROR("failed to listen on requested TCP ports");
--- 216,220 ----
}
! if(ptcp->Listen(ports, num_ports, new_ports) < 0)
{
PLAYER_ERROR("failed to listen on requested TCP ports");
***************
*** 227,236 ****
}
printf("Listening on ports: ");
for(int i=0;i<num_ports;i++)
! printf("%d ", ports[i]);
puts("");
free(ports);
while(!player_quit)
--- 230,264 ----
}
+ // Go back through and relabel the devices for which ports got
+ // auto-assigned during Listen().
+ // TODO: currently this only works for port=0. Should add support to
+ // specify multiple auto-assigned ports (e.g., with unique negative
numbers).
+ for(int i=0;i<num_ports;i++)
+ {
+ // Get the old port and the new port
+ int oport = ports[i];
+ int nport = new_ports[i];
+
+ // If the old and new ports are the same, nothing to do
+ if(oport == nport)
+ continue;
+
+ // Iterate the device table, looking for devices with the old port
+ for(Device* device = deviceTable->GetFirstDevice();
+ device;
+ device = deviceTable->GetNextDevice(device))
+ {
+ if(device->addr.robot == oport)
+ device->addr.robot = nport;
+ }
+ }
+
printf("Listening on ports: ");
for(int i=0;i<num_ports;i++)
! printf("%d ", new_ports[i]);
puts("");
free(ports);
+ free(new_ports);
while(!player_quit)
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit