File: http_unix_server.rb

package info (click to toggle)
gitlab-shell 14.35.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,652 kB
  • sloc: ruby: 1,129; makefile: 583; sql: 391; sh: 384
file content (35 lines) | stat: -rw-r--r-- 931 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'webrick'

# like WEBrick::HTTPServer, but listens on UNIX socket
class HTTPUNIXServer < WEBrick::HTTPServer
  def initialize(config = {})
    null_log = WEBrick::Log.new(IO::NULL, 7)

    super(config.merge(Logger: null_log, AccessLog: null_log))
  end

  def listen(address, port)
    socket = Socket.unix_server_socket(address)
    socket.autoclose = false
    server = UNIXServer.for_fd(socket.fileno)
    socket.close
    @listeners << server
  end

  # Workaround:
  # https://bugs.ruby-lang.org/issues/10956
  # Affecting Ruby 2.2
  # Fix for 2.2 is at https://github.com/ruby/ruby/commit/ab0a64e1
  # However, this doesn't work with 2.1. The following should work for both:
  def start(&block)
    @shutdown_pipe = IO.pipe
    shutdown_pipe = @shutdown_pipe
    super(&block)
  end

  def cleanup_shutdown_pipe(shutdown_pipe)
    @shutdown_pipe = nil
    return if !shutdown_pipe
    super(shutdown_pipe)
  end
end