3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
22 from dss.server import dss_connection
23 from dss.server import dss_config
24 from dss.server import dss_rpc_processor
27 def __init__(self, conf, rpc_processor):
28 self.uds = conf.get_listening_uds()
29 self.rpc_processor = rpc_processor
30 self.transport_type = conf.get_transport_type()
32 if (self.transport_type == 'stream'):
33 self.server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
35 self.server = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
36 self.server.setblocking(0)
40 logging.info("Server listening at %s" % self.uds)
41 self.server.bind(self.uds)
42 if self.transport_type == 'stream':
44 inputs = [self.server]
45 while not self.stopped:
47 readable, writable, errored = select.select(inputs, [], [])
50 if self.transport_type == 'stream':
51 client, address = self.server.accept()
52 client.setblocking(0) #pylint: disable=no-member
53 conn = dss_connection.Connection(client, address, self.rpc_processor)
55 logging.info("Accepted connection from %r" % address)
57 data, address = self.server.recvfrom(4096)
58 dss_connection.Connection.recv_dgram(self.server, data, address, self.rpc_processor)
63 except (SystemExit, KeyboardInterrupt):
65 except select.error as e:
66 if e.args[0] == errno.EINTR:
68 logging.info("Server stopping")
78 logging.info("Shutting down tcp server")