From d4d68ced26f9671bd80232fb5c194b75b85e4d7e Mon Sep 17 00:00:00 2001
From: elocatel <elocatel@localhost>
Date: Wed, 23 Apr 2008 15:51:18 +0000
Subject: [PATCH] Added function getFreePort
---
opends/tests/shared/functions/utils.xml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/opends/tests/shared/functions/utils.xml b/opends/tests/shared/functions/utils.xml
index cab3b82..1482766 100755
--- a/opends/tests/shared/functions/utils.xml
+++ b/opends/tests/shared/functions/utils.xml
@@ -1979,4 +1979,52 @@
</if>
</sequence>
</function>
+
+
+
+ <function name="getFreePort" scope="local">
+ <function-description>
+ Returns the first free TCP port greater or equal to given number
+ </function-description>
+ <function-map-args>
+ <function-arg-def name="host" type="optional" default="STAXServiceMachine">
+ <function-arg-description>
+ Which machine to look for the free port
+ </function-arg-description>
+ </function-arg-def>
+ <function-arg-def name="port" type="required">
+ <function-arg-description>
+ The minimal port number to be returned
+ </function-arg-description>
+ </function-arg-def>
+ </function-map-args>
+ <sequence>
+ <script>
+ # returns first free port in [port; port+5]
+ # if no free port in this interval, return -1
+ import socket
+ import sys
+ s = None
+ i = 0
+ while 1:
+ try:
+ i = i + 1
+ if i > 5:
+ port = -1
+ break
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.bind(host, port)
+ s.listen(1)
+ s.close()
+ break
+ except socket.error:
+ if s:
+ s.close()
+ port = port + 1
+ </script>
+ <return>port</return>
+ </sequence>
+ </function>
+
+
</stax>
--
Gitblit v1.10.0