Class: OverSIP::SIP::TcpClient
- Inherits:
-
TcpReactor
- Object
- EM::Connection
- Reactor
- TcpReactor
- OverSIP::SIP::TcpClient
- Defined in:
- lib/oversip/sip/listeners/tcp_client.rb
Direct Known Subclasses
Constant Summary
Constants inherited from TcpReactor
OverSIP::SIP::TcpReactor::HEADERS_MAX_SIZE
Constants included from MessageProcessor
Constants included from Logger
Logger::SYSLOG_POSIXMQ_MAPPING
Instance Attribute Summary collapse
-
#connected ⇒ Object
readonly
Returns the value of attribute connected.
-
#pending_client_transactions ⇒ Object
readonly
Returns the value of attribute pending_client_transactions.
-
#server_class ⇒ Object
TODO: sirve??.
Instance Method Summary collapse
- #connection_completed ⇒ Object
-
#initialize(ip, port) ⇒ TcpClient
constructor
A new instance of TcpClient.
- #remote_desc ⇒ Object
- #unbind(cause = nil) ⇒ Object
Methods inherited from TcpReactor
#get_body, #parse_headers, #receive_data, #send_sip_msg
Methods inherited from Reactor
#receive_senderror, reliable_transport_listener?
Methods included from Logger
close, #fatal, fg_system_msg2str, init_logger_mq, load_methods, #log_id, syslog_system_msg2str, syslog_user_msg2str
Constructor Details
#initialize(ip, port) ⇒ TcpClient
Returns a new instance of TcpClient.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 9 def initialize ip, port # NOTE: The parent class implementing "initialize" method is Reactor, and allows no arguments. # If we call just "super" from here it will fail since "ip" and "port" will be passed as # arguments. So we must use "super()" and we are done (no arguments are passed to parent). super() @remote_ip = ip @remote_port = port @connection_id = ::OverSIP::SIP::TransportManager.add_connection self, self.class, self.class.ip_type, @remote_ip, @remote_port @connected = false @pending_client_transactions = [] ### TODO: make it configurable. set_pending_connect_timeout 2.0 end |
Instance Attribute Details
#connected ⇒ Object (readonly)
Returns the value of attribute connected.
6 7 8 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 6 def connected @connected end |
#pending_client_transactions ⇒ Object (readonly)
Returns the value of attribute pending_client_transactions.
7 8 9 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 7 def pending_client_transactions @pending_client_transactions end |
#server_class ⇒ Object
TODO: sirve??
5 6 7 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 5 def server_class @server_class end |
Instance Method Details
#connection_completed ⇒ Object
27 28 29 30 31 32 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 27 def connection_completed log_system_info "TCP connection opened to " << remote_desc @connected = true @pending_client_transactions.clear end |
#remote_desc ⇒ Object
35 36 37 38 39 40 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 35 def remote_desc @remote_desc ||= case self.class.ip_type when :ipv4 ; "#{@remote_ip}:#{@remote_port.to_s}" when :ipv6 ; "[#{@remote_ip}]:#{@remote_port.to_s}" end end |
#unbind(cause = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 43 def unbind cause=nil @state = :ignore # Remove the connection. self.class.connections.delete @connection_id @local_closed = true if cause == ::Errno::ETIMEDOUT if @connected log_msg = "connection to #{remote_desc} " log_msg << ( @local_closed ? "locally closed" : "remotely closed" ) log_msg << " (cause: #{cause.inspect})" if cause log_system_debug log_msg if $oversip_debug # If the TCP client connection has failed (remote server rejected the connection) then # inform to all the pending client transactions. else log_system_notice "connection to #{remote_desc} failed" if $oversip_debug @pending_client_transactions.each do |client_transaction| client_transaction.connection_failed end @pending_client_transactions.clear end @connected = false end |