Class: OverSIP::SIP::TcpClient
- Inherits:
-
TcpConnection
- Object
- EM::Connection
- Connection
- TcpConnection
- OverSIP::SIP::TcpClient
- Defined in:
- lib/oversip/sip/listeners/tcp_client.rb
Direct Known Subclasses
Constant Summary
Constants inherited from TcpConnection
OverSIP::SIP::TcpConnection::HEADERS_MAX_SIZE
Constants included from MessageProcessor
Class Attribute Summary collapse
-
.server_class ⇒ Object
readonly
Returns the value of attribute server_class.
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.
Attributes inherited from Connection
Instance Method Summary collapse
- #connection_completed ⇒ Object
-
#initialize(ip, port) ⇒ TcpClient
constructor
A new instance of TcpClient.
-
#record_route ⇒ Object
For the case in which OverSIP receives a SIP request from a connection open by OverSIP.
- #remote_desc ⇒ Object
- #unbind(cause = nil) ⇒ Object
Methods inherited from TcpConnection
#get_body, #parse_headers, #process_received_data, #receive_data, #remote_ip, #remote_ip_type, #remote_port, #send_sip_msg
Methods inherited from Connection
#open?, outbound_listener?, #receive_senderror, reliable_transport_listener?, #transport
Methods included from Logger
close, 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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 12 def initialize ip, port # NOTE: The parent class implementing "initialize" method is Connection, 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 |
Class Attribute Details
.server_class ⇒ Object (readonly)
Returns the value of attribute server_class.
6 7 8 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 6 def server_class @server_class end |
Instance Attribute Details
#connected ⇒ Object (readonly)
Returns the value of attribute connected.
9 10 11 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 9 def connected @connected end |
#pending_client_transactions ⇒ Object (readonly)
Returns the value of attribute pending_client_transactions.
10 11 12 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 10 def pending_client_transactions @pending_client_transactions end |
Instance Method Details
#connection_completed ⇒ Object
29 30 31 32 33 34 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 29 def connection_completed log_system_info "TCP connection opened to " << remote_desc @connected = true @pending_client_transactions.clear end |
#record_route ⇒ Object
For the case in which OverSIP receives a SIP request from a connection open by OverSIP.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 75 def record_route @record_route and return @record_route server_class = self.class.server_class local_port, local_ip = ::Socket.unpack_sockaddr_in(get_sockname) case when server_class == ::OverSIP::SIP::IPv4TcpServer uri_ip = local_ip when server_class == ::OverSIP::SIP::IPv6TcpServer uri_ip = "[#{local_ip}]" when server_class == ::OverSIP::SIP::IPv4TlsServer uri_ip = local_ip when server_class == ::OverSIP::SIP::IPv6TlsServer uri_ip = "[#{local_ip}]" end @record_route = "<sip:#{uri_ip}:#{local_port};transport=#{server_class.transport.to_s};lr;ovid=#{OverSIP::SIP::Tags.value_for_route_ovid}>" end |
#remote_desc ⇒ Object
37 38 39 40 41 42 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 37 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
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 70 71 |
# File 'lib/oversip/sip/listeners/tcp_client.rb', line 45 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 unless $! @connected = false end |