From 24cca96f146566269f30b6a59df6be7bfd6dfb69 Mon Sep 17 00:00:00 2001 From: stoiko Date: Wed, 12 Dec 2007 14:00:40 +0000 Subject: [PATCH] if nse's connect is issued on an open socket, close the old connection before connecting - this should prevent starvation, in case a single script opens many connections --- nse_nsock.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nse_nsock.cc b/nse_nsock.cc index c9d1112fe..e4291cce5 100644 --- a/nse_nsock.cc +++ b/nse_nsock.cc @@ -269,7 +269,18 @@ static int l_nsock_connect(lua_State* l) { int error_id; l_nsock_clear_buf(l, udata); - + + if(udata->nsiod!=NULL){ + /*should a script try to connect a socket, which is already connected + * we close the old connection, since it would have no access to it + * anyways + */ + if(o.scriptTrace()){ + log_write(LOG_STDOUT,"%s: Trying to connect already connected socket - closing!\n",SCRIPT_ENGINE); + } + l_nsock_close(l); + lua_pop(l,1); + } error_id = getaddrinfo(addr, NULL, NULL, &dest); if (error_id) { error = gai_strerror(error_id);