Skip to content

Commit

Permalink
prevent calls to enable tls unless connected
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen von Takach committed Nov 25, 2013
1 parent 0fd67e3 commit b71ef21
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: ruby
rvm:
- "1.9.3"
- "2.0.0"
- rbx-20mode
- jruby-19mode
- jruby-20mode
- ruby-head
- rbx-2.2.1
- jruby-head
branches:
only:
- master
Expand Down
17 changes: 16 additions & 1 deletion lib/libuv/tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ class TCP < Handle
TLS_ERROR = "TLS write failed".freeze


attr_reader :connected


def initialize(loop, acceptor = nil)
@loop = loop

tcp_ptr = ::Libuv::Ext.create_handle(:uv_tcp)
error = check_result(::Libuv::Ext.tcp_init(loop.handle, tcp_ptr))
error = check_result(::Libuv::Ext.accept(acceptor, tcp_ptr)) if acceptor && error.nil?

if acceptor && error.nil?
error = check_result(::Libuv::Ext.accept(acceptor, tcp_ptr))
@connected = true
else
@connected = false
end

super(tcp_ptr, error)
end
Expand All @@ -27,6 +36,8 @@ def initialize(loop, acceptor = nil)
# --------------------------------------
#
def start_tls(args = {})
return unless @connected && @tls.nil?

@handshake = false
@pending_writes = []
@tls = ::RubyTls::Connection.new(self)
Expand Down Expand Up @@ -79,6 +90,8 @@ def close_cb
# overwrite the default close to ensure
# pending writes are rejected
def close
@connected = false

if not @pending_writes.nil?
@pending_writes.each do |deferred, data|
deferred.reject(TLS_ERROR)
Expand Down Expand Up @@ -229,6 +242,8 @@ def create_socket(ip, port)

def on_connect(req, status)
::Libuv::Ext.free(req)
@connected = true

begin
@callback.call(self)
rescue Exception => e
Expand Down
2 changes: 1 addition & 1 deletion lib/libuv/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Libuv
VERSION = '0.11.2'
VERSION = '0.11.3'
end

0 comments on commit b71ef21

Please sign in to comment.