Permalink
Browse files

Firing close event on error in send(). Hopefully fixes issue #92 .

  • Loading branch information...
1 parent b16e4ce commit 47c316c59312f137079aa67adae1d8ea6b126cc9 @gimite committed Dec 17, 2011
View
Binary file not shown.
Binary file not shown.
@@ -156,7 +156,6 @@ public class WebSocket extends EventDispatcher {
var dataBytes:ByteArray = new ByteArray();
dataBytes.writeUTFBytes(data);
if (readyState == OPEN) {
- // TODO: binary API support
var frame:WebSocketFrame = new WebSocketFrame();
frame.opcode = OPCODE_TEXT;
frame.payload = dataBytes;
@@ -467,10 +466,13 @@ public class WebSocket extends EventDispatcher {
socket.writeBytes(header);
socket.writeBytes(maskedPayload);
socket.flush();
- } catch (ex:IOError) {
- logger.error("IOError while sending frame");
- // TODO Fire close event if it hasn't
- readyState = CLOSED;
+ } catch (ex:Error) {
+ logger.error("Error while sending frame: " + ex.message);
+ setTimeout(function():void {
+ if (readyState != CLOSED) {
+ close(STATUS_CONNECTION_ERROR);
+ }
+ }, 0);
return false;
}
return true;
View
@@ -99,10 +99,10 @@
*/
WebSocket.prototype.close = function() {
if (this.__createTask) {
- clearTimeout(this.__createTask);
- this.__createTask = null;
- this.readyState = WebSocket.CLOSED;
- return;
+ clearTimeout(this.__createTask);
+ this.__createTask = null;
+ this.readyState = WebSocket.CLOSED;
+ return;
}
if (this.readyState == WebSocket.CLOSED || this.readyState == WebSocket.CLOSING) {
return;

0 comments on commit 47c316c

Please sign in to comment.