diff --git a/lib/modules/Remote.pmod/Client.pike b/lib/modules/Remote.pmod/Client.pike index d8e095ddddee84ab4037f42e22186e44361c0987..704dea0550081678c692cf650cb5ee310c5c4bbe 100644 --- a/lib/modules/Remote.pmod/Client.pike +++ b/lib/modules/Remote.pmod/Client.pike @@ -13,10 +13,10 @@ object get(string name) } -void create(string host, int port) +void create(string host, int port, void|int nice, int ...timeout) { - con = Connection(); - if(!con->connect(host, port)) + con = Connection(nice); + if(!con->connect(host, port, @timeout)) error("Could not connect to server"); connected = 1; con->closed = 0; diff --git a/lib/modules/Remote.pmod/Server.pike b/lib/modules/Remote.pmod/Server.pike index 4f100a7b6fce067b12b4b97d56aa38a4ed252810..478c4fd6afe4e84c32a3456eed40abf5c9118a46 100644 --- a/lib/modules/Remote.pmod/Server.pike +++ b/lib/modules/Remote.pmod/Server.pike @@ -49,6 +49,7 @@ void create(string host, int p) { portno = p; port = Stdio.Port(); + port->set_id(port); if(host) { if(!port->bind(p, got_connection, host)) diff --git a/lib/modules/Remote.pmod/connection.pike b/lib/modules/Remote.pmod/connection.pike index 4f4cc988bf2f331b9e2d6fbe067c99852cbe8c52..77fb91f2eab71f6304cb3df0884c315400c41b0a 100644 --- a/lib/modules/Remote.pmod/connection.pike +++ b/lib/modules/Remote.pmod/connection.pike @@ -6,18 +6,28 @@ object con; object ctx; array(function) close_callbacks = ({ }); +int nice; // don't throw from call_sync + void handshake(int ignore, string s); void read_some(int ignore, string s); void write_some(int|void ignore); void closed_connection(int|void ignore); +// - create + +void create(void|int _nice) +{ + nice=_nice; +} + // - connect // // This function is called by clients to connect to a server. // -int connect(string host, int port) +int connect(string host, int port, int ... timeout) { string s, sv; + int end_time=time()+(sizeof(timeout)?(timeout[0]||1):60); DEBUGMSG("connecting to "+host+":"+port+"...\n"); @@ -29,7 +39,19 @@ int connect(string host, int port) return 0; DEBUGMSG("connected\n"); con->write("Pike remote client "+PROTO_VERSION+"\n"); - s = con->read(24); + s=""; + con->set_nonblocking(); + for (;;) + { + s += (con->read(24-strlen(s),1)||""); + if (strlen(s)==24) break; + sleep(0.02); + if (time()>end_time) + { + con->close(); + return 0; + } + } if((sscanf(s,"Pike remote server %4s\n", sv) == 1) && (sv == PROTO_VERSION)) { ctx = Context(replace(con->query_address(1), " ", "-"), this_object()); @@ -261,7 +283,10 @@ mixed call_sync(array data) if(!s || !strlen(s)) { closed_connection(); - error("Could not read"); + if (!nice) + error("Could not read"); + else + return ([])[0]; // failed, like } read_some(0,s); }