libassa
3.5.1
assa
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 */
ASSA::SA_UN
struct sockaddr_un SA_UN
Definition:
Address.h:44
ASSA::Address::badbit
@ badbit
bad state
Definition:
Address.h:56
ASSA::Address::getLength
virtual const int getLength() const =0
Return length of the underlying address structure.
ASSA::Address::setstate
void setstate(addrstate flag_)
Set state of the Address object.
Definition:
Address.h:111
ASSA::SA
struct sockaddr SA
Definition:
Address.h:33
ASSA::Address::addr_state_t
addr_state_t
State bits.
Definition:
Address.h:54
ASSA::Address::good
bool good() const
Valid address is constructed.
Definition:
Address.h:73
ASSA::Address::operator!
bool operator!() const
Alias to bad ().
Definition:
Address.h:91
ASSA::TRACE
@ TRACE
Function call trace
Definition:
LogMask.h:26
ASSA::Address::getAddress
virtual SA * getAddress() const =0
Retrieve pointer to the address structure.
ASSA::SA_IN
struct sockaddr_in SA_IN
Definition:
Address.h:34
ASSA::Address::~Address
virtual ~Address()
Destructor.
Definition:
Address.h:68
ASSA::Address::bad
bool bad() const
Indicates whether there was error during address construction process i.e.
Definition:
Address.h:80
Logger.h
trace
#define trace(s)
Definition:
Logger.h:429
Assure.h
ASSA::Address::Address
Address()
Constructor.
Definition:
Address.h:65
ASSA
Definition:
Acceptor.h:40
ASSA::Address::dump
virtual void dump()
Dump object state to the log file.
Definition:
Address.h:101
DL
#define DL(X)
Definition:
Logger.h:273
ASSA::Address::goodbit
@ goodbit
good state
Definition:
Address.h:55
ASSA::Address
Definition:
Address.h:51
ASSA::Address::addrstate
int addrstate
Definition:
Address.h:58
ASSA::Address::m_state
unsigned char m_state
Definition:
Address.h:61
Generated by
1.8.17