Class: EaseEngine::TCPSocket

Inherits:
Socket
  • Object
show all
Defined in:
lib/ease_engine/socket.rb

Direct Known Subclasses

TCPServer

Instance Attribute Summary collapse

Attributes inherited from Socket

#dst_addr, #err, #is_disable, #read_buf, #read_max_size, #socket, #write_buf

Instance Method Summary collapse

Methods inherited from Socket

#bind, #close, #errno, #recvfrom, #send, #to_i

Constructor Details

#initialize(*args) ⇒ TCPSocket

Returns a new instance of TCPSocket.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ease_engine/socket.rb', line 102

def initialize( *args )
  super
  
  @is_heartbeat = false
  @is_timeout = false
  
  case args.length
  when 1
    @socket = args[ 0 ]
  when 2
    @dst_addr = ::TCPSocket.gethostbyname( args[ 0 ] )
    @dst_addr.push args[ 1 ]
    @socket = ::Socket.new( @dst_addr[ 2 ], ::Socket::SOCK_STREAM, 0 )
    connect
  end
end

Instance Attribute Details

#is_heartbeatObject

Returns the value of attribute is_heartbeat.



99
100
101
# File 'lib/ease_engine/socket.rb', line 99

def is_heartbeat
  @is_heartbeat
end

#is_timeoutObject

Returns the value of attribute is_timeout.



100
101
102
# File 'lib/ease_engine/socket.rb', line 100

def is_timeout
  @is_timeout
end

Instance Method Details

#connectObject



119
120
121
122
123
124
125
126
# File 'lib/ease_engine/socket.rb', line 119

def connect
  @err = nil
  begin
    @socket.connect_nonblock( ::Socket.sockaddr_in( @dst_addr.last, @dst_addr[ 3 ] ) )
  rescue => err
    @err = err
  end
end

#recv(max, flags = 0) ⇒ Object



128
129
130
131
# File 'lib/ease_engine/socket.rb', line 128

def recv( max, flags = 0 )
  @is_timeout = false
  super( max, flags )
end