Module: Roma::Event::EMConnection

Defined in:
lib/roma/event/con_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#apObject

Returns the value of attribute ap.



14
15
16
# File 'lib/roma/event/con_pool.rb', line 14

def ap
  @ap
end

#connectedObject (readonly)

Returns the value of attribute connected.



13
14
15
# File 'lib/roma/event/con_pool.rb', line 13

def connected
  @connected
end

#fiber=(value) ⇒ Object (writeonly)

Sets the attribute fiber

Parameters:

  • value

    the value to set the attribute fiber to.



12
13
14
# File 'lib/roma/event/con_pool.rb', line 12

def fiber=(value)
  @fiber = value
end

#last_accessObject

Returns the value of attribute last_access.



15
16
17
# File 'lib/roma/event/con_pool.rb', line 15

def last_access
  @last_access
end

Instance Method Details

#getsObject



65
66
67
68
69
70
71
72
73
74
# File 'lib/roma/event/con_pool.rb', line 65

def gets
  while(@connected) do
    if idx = @rbuf.index("\n")
      return pop(idx+1)
    else
      Fiber.yield(@rbuf.size)
    end
  end
  nil
end

#pop(size) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/roma/event/con_pool.rb', line 42

def pop(size)
  if @rbuf.size >= size
    r = @rbuf[0..size-1]
    @rbuf = @rbuf[size..-1]
    r
  else
    nil
  end
end

#post_initObject



17
18
19
20
21
# File 'lib/roma/event/con_pool.rb', line 17

def post_init
  @rbuf = ''
  @connected = true
  @last_access = Time.now
end

#read_bytes(size) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/roma/event/con_pool.rb', line 52

def read_bytes(size)
  while(@connected) do
    d = pop(size)
    if d
      return d
    else
      remain = size - @rbuf.size
      Fiber.yield(remain)
    end
  end
  nil
end

#receive_data(data) ⇒ Object



23
24
25
26
27
28
# File 'lib/roma/event/con_pool.rb', line 23

def receive_data(data)
  @rbuf << data
  @fiber.resume
rescue =>e
  Roma::Logging::RLogger.instance.error("#{__FILE__}:#{__LINE__}:#{e.inspect} #{$@}")
end

#send(data) ⇒ Object



38
39
40
# File 'lib/roma/event/con_pool.rb', line 38

def send(data)
  send_data(data)
end

#unbindObject



30
31
32
33
34
35
36
# File 'lib/roma/event/con_pool.rb', line 30

def unbind
  @connected = nil
  @fiber.resume
rescue FiberError
rescue =>e
  Roma::Logging::RLogger.instance.warn("#{__FILE__}:#{__LINE__}:#{e.inspect} #{$@}")
end