#include <unistd.h>
#include "../../include/macros.h"
+#include "../../include/manifest.h"
static int sfd;
perror("connect");
exit(EXIT_FAILURE);
}
+ setup_socket(sfd);
}
static char *default_name = "no_name";
int write_len = strlen(write_buf); \
ssize_t wrote = \
write(sfd, write_buf, write_len); \
- tomc_p("wrote '%s' (%d)", write_buf, write_len); \
+ /* tomc_p("wrote '%s' (%d)", write_buf, write_len); */ \
if(wrote != write_len){ \
perror("[tomc] write size mismatch"); \
exit(EXIT_FAILURE); \
}}
+int last_read_size = 0;
+
+static void do_read(char *line)
+{
+ printf("got %s as input.\n", line);
+ strcpy(socket_buf, line);
+ /* printf("socket_buf: %s\n", socket_buf); */
+}
#define SOCK_READ { \
- int size = read(sfd, socket_buf, 100); \
- if(read == 0) { \
- tomc_p("didn't actually get anything."); \
- socket_buf[0] = '\0'; \
- } \
- socket_buf[size] = '\0'; \
+ socket_read(do_read); \
}
+ /* int size = read(sfd, socket_buf, 100); \ */
+ /* if(size == 0) { \ */
+ /* tomc_p("didn't actually get anything."); \ */
+ /* socket_buf[0] = '\0'; \ */
+ /* }else{ \ */
+ /* tomc_p("__debug__:size=%d", size); \ */
+ /* } \ */
+ /* socket_buf[size] = '\0'; \ */
+ /* tomc_p("__debug__: '%s'", socket_buf);\ */
+ /* last_read_size = size;\ */
+ /* } */
#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); \
} \
- tomc_p("got an ACK"); \
}
#define SOCK_ACK {SOCK_READ_X("ACK")};
#define SOCK_REQUEST(X) { \
SOCK_ACK; \
SOCK_WRITE(options.name); \
SOCK_ACK; \
- SOCK_READ; \
- tomc_p("tomd reports '%s'", socket_buf); \
}
static void write_client(void)
if(options.status){
SOCK_REQUEST("status");
}
+
+ while(1){
+ printf("looking for that last ack.\n");
+ SOCK_READ;
+ if(strcmp(socket_buf, "ACK") == 0){
+ tomc_p("got the ending ack.");
+ break;
+ }else{
+ printf("in else.\n");
+ /* int len = strlen(socket_buf); */
+ /* int total = len; */
+ /* if(last_read_size == 0){ */
+ /* continue; */
+ /* } */
+ tomc_p(socket_buf);
+ /* while(total != last_read_size -1){ */
+ /* tomc_p("__debug__:total=%d, size=%d", total, last_read_size); */
+ /* char *ptr = socket_buf + total; */
+ /* tomc_p("'%s'", ptr); */
+ /* total += strlen(ptr); */
+ /* } */
+ }
+ }
}
int main(int argc, char **argv)
print_options();
init();
write_requests();
+
+ tomc_p("dying of our own accord.");
return EXIT_SUCCESS;
}