View | Details | Raw Unified | Return to bug 2434 | Differences between
and this patch

Collapse All | Expand All

(-)a/atomicio.c (-4 / +16 lines)
Lines 54-62 atomicio6(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n, Link Here
54
		res = (f) (fd, s + pos, n - pos);
54
		res = (f) (fd, s + pos, n - pos);
55
		switch (res) {
55
		switch (res) {
56
		case -1:
56
		case -1:
57
			if (errno == EINTR)
57
			switch(errno) {
58
			case EINTR:
59
				/* possible SIGALARM, update callback */
60
				if (cb != NULL && cb(cb_arg, 0) == -1) {
61
					errno = EINTR;
62
					return pos;
63
				}
58
				continue;
64
				continue;
59
			if (errno == EAGAIN) {
65
			case EAGAIN:
60
				(void)poll(&pfd, 1, -1);
66
				(void)poll(&pfd, 1, -1);
61
				continue;
67
				continue;
62
			}
68
			}
Lines 107-115 atomiciov6(ssize_t (*f) (int, const struct iovec *, int), int fd, Link Here
107
		res = (f) (fd, iov, iovcnt);
113
		res = (f) (fd, iov, iovcnt);
108
		switch (res) {
114
		switch (res) {
109
		case -1:
115
		case -1:
110
			if (errno == EINTR)
116
			switch(errno) {
117
			case EINTR:
118
				/* possible SIGALARM, update callback */
119
				if (cb != NULL && cb(cb_arg, 0) == -1) {
120
					errno = EINTR;
121
					return pos;
122
				}
111
				continue;
123
				continue;
112
			if (errno == EAGAIN) {
124
			case EAGAIN:
113
				(void)poll(&pfd, 1, -1);
125
				(void)poll(&pfd, 1, -1);
114
				continue;
126
				continue;
115
			}
127
			}
(-)a/progressmeter.c (-28 / +23 lines)
Lines 29-34 Link Here
29
29
30
#include <errno.h>
30
#include <errno.h>
31
#include <signal.h>
31
#include <signal.h>
32
#include <stdarg.h>
32
#include <stdio.h>
33
#include <stdio.h>
33
#include <string.h>
34
#include <string.h>
34
#include <time.h>
35
#include <time.h>
Lines 37-42 Link Here
37
#include "progressmeter.h"
38
#include "progressmeter.h"
38
#include "atomicio.h"
39
#include "atomicio.h"
39
#include "misc.h"
40
#include "misc.h"
41
#include "utf8.h"
40
42
41
#define DEFAULT_WINSIZE 80
43
#define DEFAULT_WINSIZE 80
42
#define MAX_WINSIZE 512
44
#define MAX_WINSIZE 512
Lines 59-65 static void setscreensize(void); Link Here
59
void refresh_progress_meter(void);
61
void refresh_progress_meter(void);
60
62
61
/* signal handler for updating the progress meter */
63
/* signal handler for updating the progress meter */
62
static void update_progress_meter(int);
64
static void sig_alarm(int);
63
65
64
static double start;		/* start progress */
66
static double start;		/* start progress */
65
static double last_update;	/* last progress update */
67
static double last_update;	/* last progress update */
Lines 72-77 static long stalled; /* how long we have been stalled */ Link Here
72
static int bytes_per_second;	/* current speed in bytes per second */
74
static int bytes_per_second;	/* current speed in bytes per second */
73
static int win_size;		/* terminal window size */
75
static int win_size;		/* terminal window size */
74
static volatile sig_atomic_t win_resized; /* for window resizing */
76
static volatile sig_atomic_t win_resized; /* for window resizing */
77
static volatile sig_atomic_t alarm_fired;
75
78
76
/* units for format_size */
79
/* units for format_size */
77
static const char unit[] = " KMGT";
80
static const char unit[] = " KMGT";
Lines 124-132 refresh_progress_meter(void) Link Here
124
	off_t bytes_left;
127
	off_t bytes_left;
125
	int cur_speed;
128
	int cur_speed;
126
	int hours, minutes, seconds;
129
	int hours, minutes, seconds;
127
	int i, len;
128
	int file_len;
130
	int file_len;
129
131
132
	if ((!alarm_fired && !win_resized) || !can_output())
133
		return;
134
	alarm_fired = 0;
135
136
	if (win_resized) {
137
		setscreensize();
138
		win_resized = 0;
139
	}
140
130
	transferred = *counter - (cur_pos ? cur_pos : start_pos);
141
	transferred = *counter - (cur_pos ? cur_pos : start_pos);
131
	cur_pos = *counter;
142
	cur_pos = *counter;
132
	now = monotime_double();
143
	now = monotime_double();
Lines 156-171 refresh_progress_meter(void) Link Here
156
167
157
	/* filename */
168
	/* filename */
158
	buf[0] = '\0';
169
	buf[0] = '\0';
159
	file_len = win_size - 35;
170
	file_len = win_size - 36;
160
	if (file_len > 0) {
171
	if (file_len > 0) {
161
		len = snprintf(buf, file_len + 1, "\r%s", file);
172
		buf[0] = '\r';
162
		if (len < 0)
173
		snmprintf(buf+1, sizeof(buf)-1 , &file_len, "%*s",
163
			len = 0;
174
		    file_len * -1, file);
164
		if (len >= file_len + 1)
175
		file_len++;
165
			len = file_len;
166
		for (i = len; i < file_len; i++)
167
			buf[i] = ' ';
168
		buf[file_len] = '\0';
169
	}
176
	}
170
177
171
	/* percent of transfer done */
178
	/* percent of transfer done */
Lines 226-247 refresh_progress_meter(void) Link Here
226
233
227
/*ARGSUSED*/
234
/*ARGSUSED*/
228
static void
235
static void
229
update_progress_meter(int ignore)
236
sig_alarm(int ignore)
230
{
237
{
231
	int save_errno;
238
	alarm_fired = 1;
232
239
	signal(SIGALRM, sig_alarm);
233
	save_errno = errno;
234
235
	if (win_resized) {
236
		setscreensize();
237
		win_resized = 0;
238
	}
239
	if (can_output())
240
		refresh_progress_meter();
241
242
	signal(SIGALRM, update_progress_meter);
243
	alarm(UPDATE_INTERVAL);
240
	alarm(UPDATE_INTERVAL);
244
	errno = save_errno;
245
}
241
}
246
242
247
void
243
void
Lines 257-266 start_progress_meter(const char *f, off_t filesize, off_t *ctr) Link Here
257
	bytes_per_second = 0;
253
	bytes_per_second = 0;
258
254
259
	setscreensize();
255
	setscreensize();
260
	if (can_output())
256
	refresh_progress_meter();
261
		refresh_progress_meter();
262
257
263
	signal(SIGALRM, update_progress_meter);
258
	signal(SIGALRM, sig_alarm);
264
	signal(SIGWINCH, sig_winch);
259
	signal(SIGWINCH, sig_winch);
265
	alarm(UPDATE_INTERVAL);
260
	alarm(UPDATE_INTERVAL);
266
}
261
}
(-)a/progressmeter.h (+1 lines)
Lines 24-27 Link Here
24
 */
24
 */
25
25
26
void	start_progress_meter(const char *, off_t, off_t *);
26
void	start_progress_meter(const char *, off_t, off_t *);
27
void	refresh_progress_meter(void);
27
void	stop_progress_meter(void);
28
void	stop_progress_meter(void);
(-)a/scp.c (+1 lines)
Lines 563-568 scpio(void *_cnt, size_t s) Link Here
563
	off_t *cnt = (off_t *)_cnt;
563
	off_t *cnt = (off_t *)_cnt;
564
564
565
	*cnt += s;
565
	*cnt += s;
566
	refresh_progress_meter();
566
	if (limit_kbps > 0)
567
	if (limit_kbps > 0)
567
		bandwidth_limit(&bwlimit, s);
568
		bandwidth_limit(&bwlimit, s);
568
	return 0;
569
	return 0;
(-)a/sftp-client.c (-7 / +9 lines)
Lines 88-94 sftpio(void *_bwlimit, size_t amount) Link Here
88
{
88
{
89
	struct bwlimit *bwlimit = (struct bwlimit *)_bwlimit;
89
	struct bwlimit *bwlimit = (struct bwlimit *)_bwlimit;
90
90
91
	bandwidth_limit(bwlimit, amount);
91
	refresh_progress_meter();
92
	if (bwlimit != NULL)
93
		bandwidth_limit(bwlimit, amount);
92
	return 0;
94
	return 0;
93
}
95
}
94
96
Lines 108-115 send_msg(struct sftp_conn *conn, struct sshbuf *m) Link Here
108
	iov[1].iov_base = (u_char *)sshbuf_ptr(m);
110
	iov[1].iov_base = (u_char *)sshbuf_ptr(m);
109
	iov[1].iov_len = sshbuf_len(m);
111
	iov[1].iov_len = sshbuf_len(m);
110
112
111
	if (atomiciov6(writev, conn->fd_out, iov, 2,
113
	if (atomiciov6(writev, conn->fd_out, iov, 2, sftpio,
112
	    conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_out) !=
114
	    conn->limit_kbps > 0 ? &conn->bwlimit_out : NULL) !=
113
	    sshbuf_len(m) + sizeof(mlen))
115
	    sshbuf_len(m) + sizeof(mlen))
114
		fatal("Couldn't send packet: %s", strerror(errno));
116
		fatal("Couldn't send packet: %s", strerror(errno));
115
117
Lines 125-132 get_msg_extended(struct sftp_conn *conn, struct sshbuf *m, int initial) Link Here
125
127
126
	if ((r = sshbuf_reserve(m, 4, &p)) != 0)
128
	if ((r = sshbuf_reserve(m, 4, &p)) != 0)
127
		fatal("%s: buffer error: %s", __func__, ssh_err(r));
129
		fatal("%s: buffer error: %s", __func__, ssh_err(r));
128
	if (atomicio6(read, conn->fd_in, p, 4,
130
	if (atomicio6(read, conn->fd_in, p, 4, sftpio,
129
	    conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_in) != 4) {
131
	    conn->limit_kbps > 0 ? &conn->bwlimit_in : NULL) != 4) {
130
		if (errno == EPIPE || errno == ECONNRESET)
132
		if (errno == EPIPE || errno == ECONNRESET)
131
			fatal("Connection closed");
133
			fatal("Connection closed");
132
		else
134
		else
Lines 144-151 get_msg_extended(struct sftp_conn *conn, struct sshbuf *m, int initial) Link Here
144
146
145
	if ((r = sshbuf_reserve(m, msg_len, &p)) != 0)
147
	if ((r = sshbuf_reserve(m, msg_len, &p)) != 0)
146
		fatal("%s: buffer error: %s", __func__, ssh_err(r));
148
		fatal("%s: buffer error: %s", __func__, ssh_err(r));
147
	if (atomicio6(read, conn->fd_in, p, msg_len,
149
	if (atomicio6(read, conn->fd_in, p, msg_len, sftpio,
148
	    conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_in)
150
	    conn->limit_kbps > 0 ? &conn->bwlimit_in : NULL)
149
	    != msg_len) {
151
	    != msg_len) {
150
		if (errno == EPIPE)
152
		if (errno == EPIPE)
151
			fatal("Connection closed");
153
			fatal("Connection closed");

Return to bug 2434