schedulator: don't do MAGIC every time they list a bug explicitly; only
[wvapps.git] / wvtftp / wvtftpbase.h
blob46ee4ee3e8fb6591d39cca144f9d631b0795bf81
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2003 Net Integration Technologies, Inc.
5 * WvTFTPBase, the WvTFTP base class. This class holds functions that are
6 * common to both server and client.
7 */
8 #ifndef __WVTFTPBASE_H
9 #define __WVTFTPBASE_H
11 #include "wvstring.h"
12 #include "wvhashtable.h"
13 #include "wvudp.h"
14 #include "wvlog.h"
15 #include "wvtimestream.h"
16 #include "wvstringlist.h"
17 #include <stdio.h>
18 #include <time.h>
19 #include <sys/time.h>
21 const int MAX_PACKET_SIZE = 65535;
22 const bool WVTFTP_DEBUG = false;
24 class PktTime
26 public:
27 PktTime(int _pktclump);
28 ~PktTime();
30 void set(int pktnum, struct timeval &tv);
31 struct timeval *get(int pktnum);
33 private:
34 int idx;
35 int pktclump;
36 struct timeval *times;
39 class WvTFTPBase : public WvUDPStream
41 public:
42 enum TFTPDir {tftpread = 0, tftpwrite = 1};
43 enum TFTPOpcode {RRQ = 1, WRQ = 2, DATA = 3, ACK = 4, ERROR = 5};
44 enum TFTPMode {netascii = 0, octet, mail};
46 // _tftp_tick is in ms.
47 WvTFTPBase(int _tftp_tick, int port = 0);
48 virtual ~WvTFTPBase();
50 struct TFTPConn
52 WvIPPortAddr remote; // remote's address and port
53 WvString filename; // filename of this connection
54 TFTPDir direction; // reading or writing?
55 TFTPMode mode; // mode (netascii or octet)
56 FILE *tftpfile; // the file being transferred
57 size_t blksize; // blocksize (RFC 2348)
58 int tsize; // transfer size (RFC 2349)
59 int pktclump; // number of packets to send at once
60 int unack; // first unacked packet for writing data
61 int lastsent; // block number of last packet sent
62 bool donefile; // done reading from the file?
63 bool send_oack; // do we need to or did we send an OACK?
64 char oack[512]; // Holds the OACK packet in case we need
65 size_t oacklen; // to resend it.
66 int numtimeouts;
67 int rtt; // "Total" round-trip time accumulator.
68 int mult; // base of the multiplier for timeout
69 // backoffs. The actual multiplier
70 // is mult squared.
71 PktTime *pkttimes;
72 int total_packets; // Number of correct packets used to
73 // calculate average rtt.
75 int timed_out_ignore; // block number of largest packet that
76 // has been retransmitted due to
77 // timeout, and should thus be ignored
78 // in rtt calculations.
80 TFTPConn()
81 { tftpfile = NULL; }
82 ~TFTPConn()
83 { if (tftpfile) fclose(tftpfile); if (pkttimes) delete pkttimes; }
86 DeclareWvDict(TFTPConn, WvIPPortAddr, remote);
88 protected:
89 TFTPConnDict conns;
90 WvLog log;
91 int tftp_tick;
92 char packet[MAX_PACKET_SIZE];
93 size_t packetsize;
94 int def_timeout;
96 virtual void new_connection() = 0;
97 virtual void handle_packet();
98 void send_data(TFTPConn *c, bool resend = false);
99 void send_ack(TFTPConn *c, bool resend = false);
100 void send_err(char errcode, WvString errmsg = "");
102 void dump_pkt();
105 #endif // __WVTFTP_H