diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -525,6 +525,14 @@ static uint32_t select_file_chunk(bool *file_chunk) return k; } +static void tip_client_reset_state(struct tip_client *cli, int fd, + uint64_t chunk_offset) +{ + memset(cli, 0, sizeof(*cli)); + cli->chunk_offset = chunk_offset; + cli->fd = fd; +} + static char _filename[PATH_MAX + 1]; int main(int argc, char *argv[]) @@ -551,6 +559,7 @@ int main(int argc, char *argv[]) do { filename = argv[2]; + memset(&_cli, 0, sizeof(_cli)); _cli.state = TIP_CLIENT_HEAD_HEADER; ret = tip_client_request_file(&_cli, addr, filename); } while (ret > 0); @@ -565,28 +574,22 @@ int main(int argc, char *argv[]) file_size = _cli.content_len; for (i = 0; i < MAX_CHUNKS; i++) { - memset(&_cli, 0, sizeof(_cli)); - k = select_file_chunk(file_chunk); snprintf(_filename, sizeof(_filename), "%s.%u", argv[2], k); filename = _filename; chunk_size = file_size / MAX_CHUNKS; - _cli.chunk_offset = chunk_size * k; - _cli.fd = fd; do { + tip_client_reset_state(&_cli, fd, chunk_size * k); syslog(LOG_INFO, "Requesting file %s to server\n", filename); _cli.state = TIP_CLIENT_GET_HEADER; ret = tip_client_request_file(&_cli, addr, filename); } while (ret > 0); if (ret < 0) { - memset(&_cli, 0, sizeof(_cli)); - _cli.chunk_offset = chunk_size * k; - _cli.fd = fd; - _cli.server_only = true; - do { + tip_client_reset_state(&_cli, fd, chunk_size * k); + _cli.server_only = true; syslog(LOG_INFO, "Requesting file %s to server only\n", filename); _cli.state = TIP_CLIENT_GET_HEADER; ret = tip_client_request_file(&_cli, addr, filename); |