]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/rb/lib/thrift/transport/server_socket.rb
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / rb / lib / thrift / transport / server_socket.rb
CommitLineData
f67539c2
TL
1# encoding: ascii-8bit
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance
9# with the License. You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing,
14# software distributed under the License is distributed on an
15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16# KIND, either express or implied. See the License for the
17# specific language governing permissions and limitations
18# under the License.
19#
20
21require 'socket'
22
23module Thrift
24 class ServerSocket < BaseServerTransport
25 # call-seq: initialize(host = nil, port)
26 def initialize(host_or_port, port = nil)
27 if port
28 @host = host_or_port
29 @port = port
30 else
31 @host = nil
32 @port = host_or_port
33 end
34 @handle = nil
35 end
36
37 attr_reader :handle
38
39 def listen
40 @handle = TCPServer.new(@host, @port)
41 end
42
43 def accept
44 unless @handle.nil?
45 sock = @handle.accept
46 trans = Socket.new
47 trans.handle = sock
48 trans
49 end
50 end
51
52 def close
53 @handle.close unless @handle.nil? or @handle.closed?
54 @handle = nil
55 end
56
57 def closed?
58 @handle.nil? or @handle.closed?
59 end
60
61 alias to_io handle
62
63 def to_s
64 "socket(#{@host}:#{@port})"
65 end
66
67 end
68end