]> andersk Git - openssh.git/blame - roaming_common.c
- dtucker@cvs.openbsd.org 2009/06/21 09:04:03
[openssh.git] / roaming_common.c
CommitLineData
ac692f84 1/* $OpenBSD: roaming_common.c,v 1.4 2009/06/21 09:04:03 dtucker Exp $ */
d0137ef8 2/*
3 * Copyright (c) 2004-2009 AppGate Network Security AB
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <sys/types.h>
19#include <sys/socket.h>
20#include <sys/uio.h>
21
22#include <errno.h>
23#include <inttypes.h>
24#include <stdarg.h>
25#include <unistd.h>
26
27#include "atomicio.h"
28#include "log.h"
29#include "packet.h"
30#include "xmalloc.h"
31#include "cipher.h"
32#include "buffer.h"
33#include "roaming.h"
34
35static u_int64_t write_bytes = 0;
36static u_int64_t read_bytes = 0;
37
38int resume_in_progress = 0;
39
40u_int64_t
41get_recv_bytes(void)
42{
43 return read_bytes;
44}
45
46void
47add_recv_bytes(u_int64_t num)
48{
49 read_bytes += num;
50}
51
52u_int64_t
53get_sent_bytes(void)
54{
55 return write_bytes;
56}
57
58void
ac692f84 59roam_set_bytes(u_int64_t sent, u_int64_t recvd)
d0137ef8 60{
ac692f84 61 read_bytes = recvd;
d0137ef8 62 write_bytes = sent;
63}
64
65ssize_t
66roaming_write(int fd, const void *buf, size_t count, int *cont)
67{
68 ssize_t ret;
69
70 ret = write(fd, buf, count);
71 if (ret > 0 && !resume_in_progress) {
72 write_bytes += ret;
73 }
ac692f84 74 debug3("Wrote %ld bytes for a total of %llu", (long)ret,
75 (unsigned long long)write_bytes);
d0137ef8 76 return ret;
77}
78
79ssize_t
80roaming_read(int fd, void *buf, size_t count, int *cont)
81{
82 ssize_t ret = read(fd, buf, count);
83 if (ret > 0) {
84 if (!resume_in_progress) {
85 read_bytes += ret;
86 }
87 }
88 return ret;
89}
90
ac692f84 91size_t
92roaming_atomicio(ssize_t(*f)(int, void*, size_t), int fd, void *buf,
93 size_t count)
d0137ef8 94{
ac692f84 95 size_t ret = atomicio(f, fd, buf, count);
d0137ef8 96
ac692f84 97 if (f == vwrite && ret > 0 && !resume_in_progress) {
d0137ef8 98 write_bytes += ret;
99 } else if (f == read && ret > 0 && !resume_in_progress) {
100 read_bytes += ret;
101 }
102 return ret;
103}
This page took 0.2084 seconds and 5 git commands to generate.