summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 599623b..01babf5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -166,8 +166,11 @@ static int tip_client_state_recv_hdr(struct tip_client *cli)
tip_client_stats.direct_from_server++;
cli->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600);
- if (cli->fd < 0)
- return ret;
+ if (cli->fd < 0) {
+ syslog(LOG_ERR, "failed to open file %s: %s",
+ filename, strerror(errno));
+ return -1;
+ }
header_len = trailer - cli->buf;
payload = cli->buf + header_len;
@@ -177,8 +180,11 @@ static int tip_client_state_recv_hdr(struct tip_client *cli)
if (payload_len > 0) {
ret = write(cli->fd, payload, payload_len);
- if (ret < 0)
+ if (ret < 0) {
+ syslog(LOG_ERR, "failed to write to file %s: %s",
+ filename, strerror(errno));
return ret;
+ }
}
if (payload_len >= cli->content_len)
@@ -194,8 +200,11 @@ static int tip_client_state_recv_payload(struct tip_client *cli)
cli->data_len += cli->buf_len;
ret = write(cli->fd, cli->buf, cli->buf_len);
- if (ret < 0)
+ if (ret < 0) {
+ syslog(LOG_ERR, "failed to write to file %s: %s",
+ filename, strerror(errno));
return ret;
+ }
cli->buf_len = 0;
@@ -249,6 +258,11 @@ static void tip_client_read_cb(struct ev_loop *loop, struct ev_io *io, int event
cli = container_of(io, struct tip_client, io);
+ if (events & EV_ERROR) {
+ tip_client_error(cli);
+ return;
+ }
+
ret = tip_client_recv(cli, events);
if (ret < 0)
goto error;
@@ -297,8 +311,10 @@ static void tip_client_connect_cb(struct ev_loop *loop, struct ev_io *io, int ev
cli = container_of(io, struct tip_client, io);
- if (events & EV_ERROR)
+ if (events & EV_ERROR) {
+ tip_client_error(cli);
return;
+ }
len = sizeof(cli->addr);
ret = connect(cli->io.fd, (struct sockaddr *)&cli->addr, len);
@@ -317,6 +333,7 @@ static void tip_client_connect_cb(struct ev_loop *loop, struct ev_io *io, int ev
ret = send(cli->io.fd, buf, strlen(buf), 0);
if (ret < 0) {
+ syslog(LOG_ERR, "failed to send request for %s", filename);
tip_client_error(cli);
return;
}
@@ -341,8 +358,10 @@ static int tip_client_connect(const char *addr)
int ret;
remote_fd = socket(AF_INET, SOCK_STREAM, 0);
- if (remote_fd < 0)
+ if (remote_fd < 0) {
+ tip_client_error(cli);
return -1;
+ }
setsockopt(remote_fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(int));
setsockopt(remote_fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(int));
@@ -352,8 +371,10 @@ static int tip_client_connect(const char *addr)
flags = fcntl(remote_fd, F_GETFL);
flags |= O_NONBLOCK;
ret = fcntl(remote_fd, F_SETFL, flags);
- if (ret < 0)
+ if (ret < 0) {
+ tip_client_error(cli);
return ret;
+ }
cli->addr.sin_family = AF_INET;
cli->addr.sin_addr.s_addr = inet_addr(addr);
@@ -433,6 +454,11 @@ int main(int argc, char *argv[])
while (_cli.state != TIP_CLIENT_DONE && !_cli.error)
ev_loop(tip_main_loop, 0);
+ if (_cli.error) {
+ syslog(LOG_ERR, "Failed to fetch file %s\n", filename);
+ break;
+ }
+
file_chunk[k] = true;
data_len += _cli.data_len;
}