|
From: Radu B. R. <ru...@cs...> - 2006-06-19 11:57:50
|
Thanks a lot Kurt, I just applied it to the repository.
Everything looks fine at first glance, but I wonder if closing the
sockets directly without unsubscribing will cause any nasty effects on
the Player side for some devices.
Best,
Radu.
Kurt Konolige wrote:
> This function hangs when talking to Stage (haven't tried it with a
> real robot). It's waiting for a response to a device close request,
> which Stage never sends. Took out the close request, just shut down
> the I/O, which closes the Stage connection. Also added setNotThreaded
> code to wait for thread to exit.
>
> Patch is against the latest SVN.
>
> Cheers --Kurt
> ------------------------------------------------------------------------
>
> Index: PlayerClient.java
> ===================================================================
> --- PlayerClient.java (revision 67)
> +++ PlayerClient.java (working copy)
> @@ -97,6 +97,7 @@
> // Timeout for packets
> // private long timeout = 100;
> private boolean isThreaded;
> + private boolean isRunning;
>
> // current data mode
> private int datamode = PLAYER_DATAMODE_PUSH;
> @@ -109,6 +110,10 @@
> */
> public PlayerClient (String serverName, int portNumber) {
> try {
> + // init
> + isThreaded = false;
> + isRunning = false;
> +
> // initialize network connection
> socket = new Socket (serverName, portNumber);
> // open the proper streams (I/O)
> @@ -167,21 +172,25 @@
> * with the Player server.
> */
> public void close () {
> - try {
> - for (int i = 0; i < deviceList.size (); i++) {
> - PlayerDevice pd = (PlayerDevice)deviceList.get (i);
> - requestDeviceAccess (pd.getDeviceAddress ().getInterf (),
> - pd.getDeviceAddress ().getIndex (),
> - PLAYER_CLOSE_MODE);
> - readAll ();
> - }
> + try
> + {
> + /*
> + for (int i = 0; i < deviceList.size (); i++)
> + {
> + PlayerDevice pd = (PlayerDevice)deviceList.get (i);
> + requestDeviceAccess (pd.getDeviceAddress ().getInterf (),
> + pd.getDeviceAddress ().getIndex (),
> + PLAYER_CLOSE_MODE);
> + readAll ();
> + }
> + */
>
> // close all sockets
> - os.close ();
> + this.setNotThreaded ();
> + os.close ();
> buffer.close ();
> is.close ();
> socket.close ();
> - this.setNotThreaded ();
> } catch (IOException e) {
> throw new PlayerException
> ("[PlayerClient]: Error in PlayerClient stop: " +
> @@ -191,9 +200,14 @@
>
> /**
> * Change the mode Javaclient runs to non-threaded.
> + * NOTE: waits for thread to stop
> */
> public void setNotThreaded() {
> + if (!isThreaded)
> + return;
> isThreaded = false;
> + while (isRunning == true) // wait to exit run thread
> + try { Thread.sleep (10); } catch (Exception e) { }
> }
>
> /**
> @@ -216,6 +230,7 @@
> * Start the Javaclient thread. Ran automatically from runThreaded ().
> */
> public void run () {
> + isRunning = true;
> try {
> while (isThreaded) {
> if (this.datamode == PLAYER_DATAMODE_PULL) {
> @@ -236,6 +251,8 @@
> }
> } catch (InterruptedException e) { throw new PlayerException (e); }
> // } catch (IOException e) { throw new PlayerException (e); }
> +
> + isRunning = false; // sync with setNotThreaded
> }
>
> /**
>
--
| Radu Bogdan Rusu | http://rbrusu.com/
| http://www9.cs.tum.edu/people/rusu/
| Intelligent Autonomous Systems
| Technische Universitaet Muenchen
|