From 34bb61b8ad5f569e034a8414aa2a064703fd2c19 Mon Sep 17 00:00:00 2001 From: Martin Stjernholm <mast@lysator.liu.se> Date: Tue, 29 Jun 1999 15:49:02 +0200 Subject: [PATCH] Try hard to return the socket to nonblocking in call_sync() even when there are errors. Rev: lib/modules/Remote.pmod/connection.pike:1.11 --- lib/modules/Remote.pmod/connection.pike | 57 ++++++++++++++----------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/lib/modules/Remote.pmod/connection.pike b/lib/modules/Remote.pmod/connection.pike index 0f9843b1f2..cb23579406 100644 --- a/lib/modules/Remote.pmod/connection.pike +++ b/lib/modules/Remote.pmod/connection.pike @@ -308,38 +308,43 @@ mixed call_sync(array data) int refno = data[4]; string s = encode_value(data); con->set_blocking(); - DEBUGMSG("call_sync "+ctx->describe(data)+"\n"); - pending_calls[refno] = 17; // a mutex lock key maybe? - send(sprintf("%4c%s", sizeof(s), s)); - while(zero_type(finished_calls[refno])) - { + mixed err = catch { + DEBUGMSG("call_sync "+ctx->describe(data)+"\n"); + pending_calls[refno] = 17; // a mutex lock key maybe? + send(sprintf("%4c%s", sizeof(s), s)); + while(zero_type(finished_calls[refno])) + { #if constant(Thread.Mutex) - // Only one thread does read(), the rest just waits. When the - // read() finishes, all threads loop once. - object lock = block_read_mutex->trylock(); - if (lock) { + // Only one thread does read(), the rest just waits. When the + // read() finishes, all threads loop once. + object lock = block_read_mutex->trylock(); + if (lock) { #endif - string s = con->read(8192,1); - if(s && strlen(s)) read_some(0,s); - else - { + string s = con->read(8192,1); + if(s && strlen(s)) read_some(0,s); + else + { #if constant(Thread.Mutex) - lock = 0; + lock = 0; #endif - if (!catch (con->close())) - closed_connection(); - if (!nice) - error("Could not read"); - else - return ([])[0]; // failed, like - } + if (!catch (con->close())) + closed_connection(); + if (!nice) + error("Could not read"); + else + return ([])[0]; // failed, like + } #if constant(Thread.Mutex) - lock = 0; - } - else block_read_mutex->lock(); + lock = 0; + } + else block_read_mutex->lock(); #endif - } - con->set_nonblocking(read_some, write_some, closed_connection); + } + }; + mixed err2 = catch { + con->set_nonblocking(read_some, write_some, closed_connection); + }; + if (err || err2) throw (err || err2); return get_result(refno); } -- GitLab