summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2013-02-13 13:23:40 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2013-02-14 08:08:39 +0900
commit83e3709a0d70f889e794d1c5f70c1c1eb73075f7 (patch)
tree46b295dfd926b4630fc49e2f8501f36469c25970
parentd4822f6da8dfc6c162f8aa30628d3dc5807a2df6 (diff)
controller: fix send_q draining
when stopping the sender thread, ensure that no one is going to block on send_q. otherwise a ryu app who wants to do send_msg on the datapath can block on the queue forever if the queue is full. Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/controller/controller.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py
index 4680f9a5..32d89dd5 100644
--- a/ryu/controller/controller.py
+++ b/ryu/controller/controller.py
@@ -189,12 +189,19 @@ class Datapath(object):
@_deactivate
def _send_loop(self):
- while self.is_active:
- buf = self.send_q.get()
- self.socket.sendall(buf)
+ try:
+ while self.is_active:
+ buf = self.send_q.get()
+ self.socket.sendall(buf)
+ finally:
+ q = self.send_q
+ self.send_q = None
+ while q.get():
+ pass
def send(self, buf):
- self.send_q.put(buf)
+ if self.send_q:
+ self.send_q.put(buf)
def set_xid(self, msg):
self.xid += 1