Class: Plum::Rack::UNIXListener

Inherits:
BaseListener show all
Defined in:
lib/plum/rack/listener.rb

Instance Method Summary collapse

Methods inherited from BaseListener

#method_missing

Constructor Details

#initialize(lc) ⇒ UNIXListener

Returns a new instance of UNIXListener.



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/plum/rack/listener.rb', line 140

def initialize(lc)
  if File.exist?(lc[:path])
    begin
      old = UNIXSocket.new(lc[:path])
    rescue SystemCallError, IOError
      File.unlink(lc[:path])
    else
      old.close
      raise "Already a server bound to: #{lc[:path]}"
    end
  end

  @server = ::UNIXServer.new(lc[:path])

  File.chmod(lc[:mode], lc[:path]) if lc[:mode]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Plum::Rack::BaseListener

Instance Method Details

#accept(svc) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/plum/rack/listener.rb', line 166

def accept(svc)
  sock = @server.accept
  Thread.start {
    begin
      plum = ::Plum::ServerConnection.new(sock.method(:write))
      sess = Session.new(svc, sock, plum)
      sess.run
    rescue Errno::ECONNRESET, EOFError # closed
    rescue => e
      svc.log_exception(e)
    ensure
      sock.close if sock
    end
  }
end

#stopObject



157
158
159
160
# File 'lib/plum/rack/listener.rb', line 157

def stop
  super
  File.unlink(lc[:path])
end

#to_ioObject



162
163
164
# File 'lib/plum/rack/listener.rb', line 162

def to_io
  @server.to_io
end