1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-07 22:16:33 +00:00

move the check, wheter a socket is open, before connecting it again to l_nsock_queued() - otherwise there are problems with the returned values..

This commit is contained in:
stoiko
2007-12-12 18:23:19 +00:00
parent 24cca96f14
commit 1b143f2c36

View File

@@ -221,6 +221,23 @@ static int l_nsock_connect_queued(lua_State* l) {
script might open a few sockets at once and we don't want it to
deadlock when it tries to open the 2nd one. */
const int max_descriptors_allowed = MAX(o.max_parallelism, 10);
l_nsock_udata* udata = (l_nsock_udata*) auxiliar_checkclass(l, "nsock", 1);
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);
}
if(nsock_descriptors_used >= max_descriptors_allowed){
/* wait for free descriptor */
nsock_connect_queue.push_back(l);
@@ -270,17 +287,6 @@ static int l_nsock_connect(lua_State* l) {
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);