Revision 465b8ee3
b/daemons/ganeti-confd | ||
---|---|---|
64 | 64 |
self.bind_address = bind_address |
65 | 65 |
self.port = port |
66 | 66 |
self.processor = processor |
67 |
self.out_queue = [] |
|
67 | 68 |
self.create_socket(socket.AF_INET, socket.SOCK_DGRAM) |
68 | 69 |
self.bind((bind_address, port)) |
69 | 70 |
logging.debug("listening on ('%s':%d)" % (bind_address, port)) |
... | ... | |
90 | 91 |
ip, port = address |
91 | 92 |
payload_out = self.processor.ExecQuery(payload_in, ip, port) |
92 | 93 |
if payload_out is not None: |
93 |
self.sendto(payload_out, 0, (ip, port))
|
|
94 |
self.out_queue.append((ip, port, payload_out))
|
|
94 | 95 |
except: |
95 | 96 |
# we need to catch any exception here, log it, but proceed, because even |
96 | 97 |
# if we failed handling a single request, we still want the confd to |
... | ... | |
99 | 100 |
|
100 | 101 |
# this method is overriding an asyncore.dispatcher method |
101 | 102 |
def writable(self): |
102 |
# No need to check if we can write to the UDP socket |
|
103 |
return False |
|
103 |
# Only handle writes if we have something enqueued to write |
|
104 |
if self.out_queue: |
|
105 |
return True |
|
106 |
else: |
|
107 |
return False |
|
108 |
|
|
109 |
def handle_write(self): |
|
110 |
try: |
|
111 |
if not self.out_queue: |
|
112 |
logging.error("handle_write called with empty output queue") |
|
113 |
return |
|
114 |
(ip, port, payload) = self.out_queue[0] |
|
115 |
try: |
|
116 |
self.sendto(payload, 0, (ip, port)) |
|
117 |
except socket.error, err: |
|
118 |
if err.errno == errno.EINTR: |
|
119 |
# we got a signal while trying to write. no need to do anything, |
|
120 |
# handle_write will be called again because we haven't emptied the |
|
121 |
# out_queue, and we'll try again |
|
122 |
return |
|
123 |
else: |
|
124 |
raise |
|
125 |
self.out_queue.pop(0) |
|
126 |
except: |
|
127 |
# we need to catch any exception here, log it, but proceed, because even |
|
128 |
# if we failed handling a single request, we still want the confd to |
|
129 |
# continue working. |
|
130 |
logging.error("Unexpected exception", exc_info=True) |
|
104 | 131 |
|
105 | 132 |
|
106 | 133 |
class ConfdInotifyEventHandler(pyinotify.ProcessEvent): |
Also available in: Unified diff