Listen for security errors on our socket.

Have the FrameReader stop listening on the socket when we're done with it.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5707 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2009-04-03 17:40:54 +00:00
parent cc1690654a
commit c192056f3a
2 changed files with 14 additions and 2 deletions
+9 -1
View File
@@ -44,6 +44,14 @@ public class FrameReader extends EventDispatcher
_socket.addEventListener(ProgressEvent.SOCKET_DATA, socketHasData); _socket.addEventListener(ProgressEvent.SOCKET_DATA, socketHasData);
} }
/**
* Stop listening on the socket.
*/
public function shutdown () :void
{
_socket.removeEventListener(ProgressEvent.SOCKET_DATA, socketHasData);
}
/** /**
* Called when our socket has data that we can read. * Called when our socket has data that we can read.
*/ */
@@ -52,7 +60,7 @@ public class FrameReader extends EventDispatcher
try { try {
readAvailable(); readAvailable();
} catch (e :Error) { } catch (e :Error) {
Log.getLog(this).warning("Error reading socket data [e=" + e + "]."); Log.getLog(this).warning("Error reading socket data", e);
} }
} }
@@ -24,6 +24,7 @@ package com.threerings.presents.client {
import flash.errors.IOError; import flash.errors.IOError;
import flash.events.Event; import flash.events.Event;
import flash.events.IOErrorEvent; import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.events.TimerEvent; import flash.events.TimerEvent;
import flash.net.Socket; import flash.net.Socket;
@@ -104,6 +105,7 @@ public class Communicator
_socket.endian = Endian.BIG_ENDIAN; _socket.endian = Endian.BIG_ENDIAN;
_socket.addEventListener(Event.CONNECT, socketOpened); _socket.addEventListener(Event.CONNECT, socketOpened);
_socket.addEventListener(IOErrorEvent.IO_ERROR, socketError); _socket.addEventListener(IOErrorEvent.IO_ERROR, socketError);
_socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, socketError);
_socket.addEventListener(Event.CLOSE, socketClosed); _socket.addEventListener(Event.CLOSE, socketClosed);
_frameReader = new FrameReader(_socket); _frameReader = new FrameReader(_socket);
@@ -124,9 +126,11 @@ public class Communicator
{ {
_socket.removeEventListener(Event.CONNECT, socketOpened); _socket.removeEventListener(Event.CONNECT, socketOpened);
_socket.removeEventListener(IOErrorEvent.IO_ERROR, socketError); _socket.removeEventListener(IOErrorEvent.IO_ERROR, socketError);
_socket.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, socketError);
_socket.removeEventListener(Event.CLOSE, socketClosed); _socket.removeEventListener(Event.CLOSE, socketClosed);
_frameReader.removeEventListener(FrameAvailableEvent.FRAME_AVAILABLE, inputFrameReceived); _frameReader.removeEventListener(FrameAvailableEvent.FRAME_AVAILABLE, inputFrameReceived);
_frameReader.shutdown();
} }
protected function shutdown (logonError :Error) :void protected function shutdown (logonError :Error) :void
@@ -299,7 +303,7 @@ public class Communicator
/** /**
* Called when there is an io error with the socket. * Called when there is an io error with the socket.
*/ */
protected function socketError (event :IOErrorEvent) :void protected function socketError (event :Event) :void
{ {
// if we're still trying ports, try the next one. // if we're still trying ports, try the next one.
if (_portIdx != -1) { if (_portIdx != -1) {