libassa  3.5.1
Address.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // Address.h
4 //------------------------------------------------------------------------------
5 // Copyright (C) 1997 Vladislav Grinchenko
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //------------------------------------------------------------------------------
12 #ifndef ADDRESS_H
13 #define ADDRESS_H
14 
15 #if !defined (WIN32)
16 # include <netinet/in.h>
17 # include <netdb.h>
18 # include <sys/types.h>
19 # include <sys/socket.h>
20 # include <netinet/in.h>
21 # include <arpa/inet.h> // addresses handling
22 # include <sys/un.h>
23 #endif
24 
25 #include <string.h>
26 #include <errno.h>
27 
28 #include "assa/Logger.h"
29 #include "assa/Assure.h"
30 
31 namespace ASSA {
32 
33 typedef struct sockaddr SA; // stolen from R.Stevens
34 typedef struct sockaddr_in SA_IN;
35 
36 #if defined (WIN32)
37 struct sockaddr_un
38 {
39  short sun_family; /* AF_UNIX */
40  char sun_path [108]; /* Path name */
41 };
42 #endif
43 
44 typedef struct sockaddr_un SA_UN;
45 
51 class Address {
52 public:
54  enum addr_state_t {
55  goodbit=0,
56  badbit=1
57  };
58  typedef int addrstate;
59 
60 private:
61  unsigned char m_state;
62 
63 public:
65  Address () : m_state (Address::goodbit) { trace("Address::Address"); }
66 
68  virtual ~Address() {}
69 
73  bool good() const { return m_state == 0; }
74 
80  bool bad() const { return m_state & Address::badbit; }
81 
86  operator void* () const { return (void*) good (); }
87 
91  bool operator! () const { return bad (); }
92 
94 
95  virtual const int getLength() const = 0;
96 
98  virtual SA* getAddress() const = 0;
99 
101  virtual void dump ()
102  {
103  trace("Address");
104  DL((TRACE,"state - %s\n", good () ? "good" : "bad"));
105  }
106 
107 protected:
111  void setstate (addrstate flag_) { m_state |= flag_; }
112 };
113 
114 } // end namespace ASSA
115 
116 #endif /* ADDRESS_H */
A collection of assert function wrappers.
An abstraction to message logging facility.
#define trace(s)
trace() is used to trace function call chain in C++ program.
Definition: Logger.h:429
#define DL(X)
A macro for writing debug message to the Logger.
Definition: Logger.h:273
bool bad() const
Indicates whether there was error during address construction process i.e.
Definition: Address.h:80
unsigned char m_state
Definition: Address.h:61
virtual ~Address()
Destructor.
Definition: Address.h:68
virtual void dump()
Dump object state to the log file.
Definition: Address.h:101
int addrstate
Definition: Address.h:58
virtual SA * getAddress() const =0
Retrieve pointer to the address structure.
bool good() const
Valid address is constructed.
Definition: Address.h:73
virtual const int getLength() const =0
Return length of the underlying address structure.
bool operator!() const
Alias to bad ().
Definition: Address.h:91
void setstate(addrstate flag_)
Set state of the Address object.
Definition: Address.h:111
Address()
Constructor.
Definition: Address.h:65
addr_state_t
State bits.
Definition: Address.h:54
@ goodbit
good state
Definition: Address.h:55
@ badbit
bad state
Definition: Address.h:56
Definition: Acceptor.h:40
struct sockaddr_in SA_IN
Definition: Address.h:34
struct sockaddr_un SA_UN
Definition: Address.h:44
@ TRACE
Function call trace
Definition: LogMask.h:26
struct sockaddr SA
Definition: Address.h:33