--- /dev/null
+| kill | status | start | stop | meaning |
+|------+--------+-------+------+----------------------------------------------------|
+| 0 | 0 | 0 | 0 | no request |
+| 0 | 0 | 0 | 1 | stop only |
+| 0 | 0 | 1 | 0 | start only |
+| 0 | 0 | 1 | 1 | start + stop (error) |
+| 0 | 1 | 0 | 0 | status only |
+| 0 | 1 | 0 | 1 | status + stop |
+| 0 | 1 | 1 | 0 | status + start |
+| 0 | 1 | 1 | 1 | status + start + stop (error, show status |
+| 1 | 0 | 0 | 0 | kill only |
+| 1 | 0 | 0 | 1 | kill + stop (error, kill) |
+| 1 | 0 | 1 | 0 | kill + start (error, kill) |
+| 1 | 0 | 1 | 1 | kill + start + stop (error, kill) |
+| 1 | 1 | 0 | 0 | kill + status |
+| 1 | 1 | 0 | 1 | kill + status + stop (error, kill, status) |
+| 1 | 1 | 1 | 0 | kill + status + start (error, kill) |
+| 1 | 1 | 1 | 1 | kill + status + start + stop (error, kill, status) |
+
+
+
+
}
}
-#define HALLO "hallo there from dumb-client"
-
-void write_hallo(void)
-{
- printf("writing hallo\n");
- ssize_t wrote =
- write(sfd, HALLO, sizeof HALLO);
- printf("wrote %d bytes.\n", wrote);
-}
-
static char *default_name = "no_name";
static struct{
char status, stop, kill, start;
}
}
-static void print_options()
+static void print_options(void)
{
tomc_p("---------");
tomc_p(" name: %s", options.name);
tomc_p("---------");
}
+#define HALLO "hallo there from dumb-client"
+
+void write_hallo(void)
+{
+ printf("writing hallo\n");
+ ssize_t wrote =
+ write(sfd, HALLO, sizeof HALLO);
+ printf("wrote %d bytes.\n", wrote);
+}
+
+static char write_buf[100];
+static char socket_buf[100];
+
+#define SOCK_WRITE(X) { \
+ strcpy(write_buf, X); \
+ int write_len = strlen(write_buf); \
+ ssize_t wrote = \
+ write(sfd, write_buf, write_len); \
+ if(wrote != write_len){ \
+ perror("[tomc] write size mismatch"); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+#define SOCK_READ { read(sfd, socket_buf, 100); }
+#define SOCK_READ_X(X){ \
+ SOCK_READ; \
+ if(strcmp(socket_buf, X) != 0){ \
+ tomc_p("protocol error. instead of ACK we got '%s'", socket_buf); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+#define SOCK_ACK {SOCK_READ_X("ACK")};
+#define SOCK_REQUEST(X) { \
+ SOCK_WRITE(X); \
+ SOCK_ACK; \
+ SOCK_WRITE(options.name); \
+ SOCK_ACK; \
+ SOCK_READ; \
+ tomc_p("tomd reports '%s'", socket_buf); \
+ }
+
+static void write_client(void)
+{
+ SOCK_WRITE("client:tomc");
+ SOCK_ACK;
+}
+
+static void write_start(void)
+{
+
+}
+
+static void write_stop(void)
+{
+ SOCK_REQUEST("stop");
+}
+
+static void write_kill(void)
+{
+ SOCK_REQUEST("kill");
+}
+
+static void write_status(void)
+{
+ SOCK_REQUEST("status");
+}
+
+static void write_requests(void)
+{
+ write_client();
+
+ /* go through options to figure out what we want to do */
+ if(options.kill){
+ SOCK_REQUEST("kill");
+
+ if(options.start == 1 ||
+ options.stop == 1){
+ tomc_p("can only kill and status at once.");
+ }
+ } else {
+ if(options.start){
+ if(options.stop){
+ tomc_p("can't start and stop at once.");
+ }
+ SOCK_REQUEST("start");
+ }
+ if(options.stop){
+ SOCK_REQUEST("stop");
+ }
+ }
+
+ if(options.status){
+ SOCK_REQUEST("status");
+ }
+}
+
int main(int argc, char **argv)
{
header();
extract_options(argc, argv);
print_options();
init();
-
+ write_requests();
return EXIT_SUCCESS;
}