Skip to content

Commit

Permalink
handle socket errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Apr 27, 2012
1 parent cb7d1cb commit 527d1f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions irc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class IRC extends EventEmitter
@socket = new net.Socket
@socket.on 'connect', => @onConnect()
@socket.on 'data', (data) => @onData data
@socket.on 'error', (err) => @onError err
@socket.on 'end', (err) => @onError err
@data = []

connect: ->
Expand Down Expand Up @@ -138,6 +140,11 @@ class IRC extends EventEmitter
else
break

onError: (err) ->
console.log "error", err
@socket.end()
@emit 'disconnect'

send: (args...) ->
msg = makeCommand args...
console.log('=>', msg[0...msg.length-2])
Expand Down
2 changes: 2 additions & 0 deletions net.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Socket
chrome.experimental.socket.disconnect @socketId
@emit 'close' # TODO: figure out whether i should emit 'end' as well?

end: -> @destroy() # TODO: only half-close the socket

_onEvent: (ev) =>
switch ev.type
when 'connectComplete'
Expand Down

0 comments on commit 527d1f5

Please sign in to comment.