fix socket close and add options to test program