| 22 | #define MAXCOMMAND 4096 |
| 23 | |
| 24 | static void command_loop(int input_fd, int output_fd) |
| 25 | { |
| 26 | char buffer[MAXCOMMAND]; |
| 27 | |
| 28 | while (1) { |
| 29 | size_t i; |
| 30 | if (!fgets(buffer, MAXCOMMAND - 1, stdin)) { |
| 31 | if (ferror(stdin)) |
| 32 | die("Input error"); |
| 33 | return; |
| 34 | } |
| 35 | /* Strip end of line characters. */ |
| 36 | i = strlen(buffer); |
| 37 | while (i > 0 && isspace(buffer[i - 1])) |
| 38 | buffer[--i] = 0; |
| 39 | |
| 40 | if (!strcmp(buffer, "capabilities")) { |
| 41 | printf("*connect\n\n"); |
| 42 | fflush(stdout); |
| 43 | } else if (starts_with(buffer, "connect ")) { |
| 44 | printf("\n"); |
| 45 | fflush(stdout); |
| 46 | if (bidirectional_transfer_loop(input_fd, |
| 47 | output_fd)) |
| 48 | die("Copying data between file descriptors failed"); |
| 49 | return; |
| 50 | } else { |
| 51 | die("Bad command: %s", buffer); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | int cmd_remote_fd(int argc, |
| 57 | const char **argv, |
no test coverage detected