monotone

monotone Mtn Source Tree

Root/netxx/timeout.h

1/*
2 * Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
3 * All Rights Reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * 3. Neither the name of the Author nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
23 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33/** @file
34 * This file contains the definition of the Netxx::Timeout class.
35**/
36
37#ifndef _netxx_timeout_h_
38#define _netxx_timeout_h_
39
40namespace Netxx {
41
42/**
43 * The Netxx::Timeout class is used by the other Netxx classes to specifiy a
44 * timeout value. A timeout is broken down into seconds and microseconds.
45 * This class also has a default constructor for a null timeout, that is, no
46 * timeout.
47 *
48 * As a side note, just in case you did not know, there are one million
49 * microseconds in one second.
50**/
51class Timeout {
52public:
53 //####################################################################
54 /**
55 * Construct a null timeout. This means that a timeout value should not
56 * be used at all. This is the default for most Netxx classes.
57 *
58 * @author Peter Jones
59 **/
60 //####################################################################
61 Timeout (void) : sec_(0), usec_(0) { }
62
63 //####################################################################
64 /**
65 * Construct a Netxx::Timeout with the given length in seconds and
66 * optionally the addition of the given microseconds.
67 *
68 * @param sec The number of seconds for the timeout.
69 * @param usec An optional number of microseconds.
70 * @author Peter Jones
71 **/
72 //####################################################################
73 explicit Timeout (long sec, long usec=0) : sec_(sec), usec_(usec) {}
74
75 //####################################################################
76 /**
77 * Set the seconds part of the timeout.
78 *
79 * @param sec The new value for the seconds field.
80 * @author Peter Jones
81 **/
82 //####################################################################
83 void set_sec (long sec)
84 { sec_ = sec; }
85
86 //####################################################################
87 /**
88 * Get the seconds field of the timeout.
89 *
90 * @return The timeout's seconds field.
91 * @author Peter Jones
92 **/
93 //####################################################################
94 long get_sec (void) const
95 { return sec_; }
96
97 //####################################################################
98 /**
99 * Set the microseconds field for the timeout.
100 *
101 * @param usec The microseconds to use for this timeout.
102 * @author Peter Jones
103 **/
104 //####################################################################
105 void set_usec (long usec)
106 { usec_ = usec; }
107
108 //####################################################################
109 /**
110 * Get the microseconds field for this timeout.
111 *
112 * @return The timeout's microseconds field.
113 * @author Peter Jones
114 **/
115 //####################################################################
116 long get_usec (void) const
117 { return usec_; }
118
119 //####################################################################
120 /**
121 * Test to see if this timeout is valid or null.
122 *
123 * @return True if this timeout has been set with a value.
124 * @return False if this timeout is NULL (set to zero).
125 * @author Peter Jones
126 **/
127 //####################################################################
128 operator bool (void) const
129 { return sec_ || usec_; }
130
131private:
132 long sec_;
133 long usec_;
134
135}; // end Netxx::Timeout class
136} // end Netxx namespace
137#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status