Commit d7a2b1a7 authored by Johannes Kanig's avatar Johannes Kanig

improve handling of "single client" why3server

* make server aware of single client mode with command line flag
* server will quit when last client disconnects
* unix variant also deletes socket
* move why3server binary to libdir
parent 4319934f
......@@ -555,7 +555,6 @@ clean_old_install::
install_no_local::
cp -f bin/why3.@OCAMLBEST@ $(BINDIR)/why3$(EXE)
cp -f bin/why3server$(EXE) $(BINDIR)/why3$(EXE)
cp -f bin/why3config.@OCAMLBEST@ $(TOOLDIR)/why3config$(EXE)
cp -f bin/why3execute.@OCAMLBEST@ $(TOOLDIR)/why3execute$(EXE)
cp -f bin/why3extract.@OCAMLBEST@ $(TOOLDIR)/why3extract$(EXE)
......@@ -620,9 +619,9 @@ SERVER_C:= $(addprefix src/tools/, $(addsuffix .c, $(SERVER_MODULES)))
SERVER_H:= $(addprefix src/tools/, $(addsuffix .h, $(SERVER_MODULES)))
SERVER_O:= $(addprefix src/tools/, $(addsuffix .o, $(SERVER_MODULES)))
opt: bin/why3server$(EXE)
opt: lib/why3server$(EXE)
bin/why3server$(EXE): $(SERVER_O)
lib/why3server$(EXE): $(SERVER_O)
gcc -o $@ $^
%.o: %.c %.h
......@@ -633,7 +632,7 @@ bin/why3server$(EXE): $(SERVER_O)
src/tools/main.o:: src/tools/server-unix.c src/tools/server-win.c
install_no_local::
cp -f bin/why3server$(EXE) $(BINDIR)/why3server$(EXE)
cp -f lib/why3server$(EXE) $(LIBDIR)/why3/why3server$(EXE)
clean::
rm -f $(SERVER_O)
......@@ -649,7 +648,7 @@ install_spark2014:
cp -f modules/*.mlw $(DATADIR)/why3/modules
cp -f drivers/*.drv drivers/*.gen drivers/*.aux $(DATADIR)/why3/drivers
cp -f share/why3session.dtd $(DATADIR)/why3
cp -f bin/why3server$(EXE) $(BINDIR)/why3server$(EXE)
cp -f lib/why3server$(EXE) $(BINDIR)/why3server$(EXE)
cp -f bin/gnatwhy3.@OCAMLBEST@ $(BINDIR)/gnatwhy3$(EXE)
cp -f bin/why3realize.@OCAMLBEST@ $(BINDIR)/why3realize$(EXE)
cp -f bin/why3config.@OCAMLBEST@ $(BINDIR)/why3config$(EXE)
......
......@@ -68,21 +68,17 @@ let disconnect () =
client_disconnect ()
let run_server () =
let id =
Unix.create_process "why3server"
[|"why3server"; "--socket"; !socket_name|]
Unix.stdin Unix.stdout Unix.stderr
in
at_exit (fun () ->
Unix.kill id 9;
if Sys.os_type <> "Win32" then Sys.remove !socket_name
)
let exec = Filename.concat Config.libdir "why3server" in
Unix.create_process exec
[|exec; "--socket"; !socket_name; "--single-client"|]
Unix.stdin Unix.stdout Unix.stderr
let force_connect () =
match !socket with
| None when !standalone ->
run_server ();
(* sleep is needed before connecting, or the server will not be ready yet *)
(* sleep is needed before connecting, or the server will not be ready
yet *)
ignore (Unix.select [] [] [] 0.1);
connect()
| _ -> ()
......
......@@ -7,12 +7,14 @@
int parallel = 1;
char* basename = NULL;
bool logging = false;
bool single_client = false;
void parse_options(int argc, char **argv) {
static struct option long_options[] = {
/* These options set a flag. */
{"socket", required_argument, 0, 's'},
{"logging", no_argument, 0, 'l'},
{"single-client", no_argument, 0, 'i'},
{0, 0, 0, 0}
};
while (1) {
......@@ -30,6 +32,10 @@ void parse_options(int argc, char **argv) {
corresponding flag in long_options. */
exit (1);
case 'i':
single_client = true;
break;
case 'j':
errno = 0;
parallel = strtol(optarg, NULL, 10);
......@@ -46,6 +52,7 @@ void parse_options(int argc, char **argv) {
case 'l':
logging = true;
break;
case 's':
basename = optarg;
break;
......
......@@ -6,6 +6,7 @@
extern int parallel;
extern char* basename;
extern bool logging;
extern bool single_client;
//parse command line options and set the variables <basename> and <parallel>
void parse_options(int argc, char **argv);
......
......@@ -210,7 +210,7 @@ void server_init_listening(char* basename, int parallel) {
memcpy(addr.sun_path, basename, strlen(basename) + 1);
server_sock = socket(AF_UNIX, SOCK_STREAM, 0);
res = unlink(basename);
// we delete the file if present, said otherwise we accept ENOENT as error
// we delete the file if present
if (res == -1 && errno != ENOENT) {
shutdown_with_msg("error deleting socket");
}
......@@ -451,6 +451,11 @@ void handle_msg(pclient client, int key) {
}
}
void shutdown_server() {
unlink(basename);
shutdown_with_msg("last client disconnected");
}
void close_client(pclient client) {
list_remove(clients, client->fd);
poll_list_remove(client->fd);
......@@ -458,6 +463,9 @@ void close_client(pclient client) {
free_writebuf(client->writebuf);
close(client->fd);
free(client);
if (single_client && list_is_empty(clients)) {
shutdown_server();
}
}
......
......@@ -487,12 +487,19 @@ void send_msg_to_client(pclient client,
try_write(client);
}
void shutdown_server() {
shutdown_with_msg("last client disconnected");
}
void close_client(pclient client, int key) {
list_remove(clients, key);
CloseHandle(client->handle);
free_readbuf(client->readbuf);
free_writebuf(client->writebuf);
free(client);
list_remove(clients, key);
CloseHandle(client->handle);
free_readbuf(client->readbuf);
free_writebuf(client->writebuf);
free(client);
if (single_client && list_is_empty(clients)) {
shutdown_server();
}
}
void schedule_new_jobs() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment