about summary refs log tree commit diff stats
path: root/091socket.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-24 08:51:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-24 08:51:55 -0700
commit87eb3acae90e0c7a36562da1bc930e03f1e12cb7 (patch)
tree4d07494f3947987609a8b1a753a5cc1213c826b5 /091socket.cc
parent55800f65587a18576f46d4973fa8177133a5efa4 (diff)
downloadmu-87eb3acae90e0c7a36562da1bc930e03f1e12cb7.tar.gz
3586
Make sure we clear the socket variable after closing it.
Diffstat (limited to '091socket.cc')
-rw-r--r--091socket.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/091socket.cc b/091socket.cc
index 4ea0d2b6..2aebbed8 100644
--- a/091socket.cc
+++ b/091socket.cc
@@ -321,6 +321,14 @@ case _CLOSE_SOCKET: {
     raise << maybe(get(Recipe, r).name) << "first ingredient of '$close-socket' should be a number, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end();
     break;
   }
+  if (SIZE(inst.products) != 1) {
+    raise << maybe(get(Recipe, r).name) << "'$close-socket' requires exactly one product, but got '" << inst.original_string << "'\n" << end();
+    break;
+  }
+  if (inst.products.at(0).name != inst.ingredients.at(0).name) {
+    raise << maybe(get(Recipe, r).name) << "product of '$close-socket' must be first ingredient '" << inst.ingredients.at(0).original_string << "', but got '" << inst.products.at(0).original_string << "'\n" << end();
+    break;
+  }
   break;
 }
 :(before "End Primitive Recipe Implementations")
@@ -329,6 +337,8 @@ case _CLOSE_SOCKET: {
   socket_t* socket = reinterpret_cast<socket_t*>(x);
   close(socket->fd);
   delete socket;
+  products.resize(1);
+  products.at(0).push_back(0);  // make sure we can't reuse the socket
   break;
 }