Apache log4cxx Version 0.13.0
datagramsocket.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _LOG4CXX_HELPERS_DATAGRAM_SOCKET_H
19#define _LOG4CXX_HELPERS_DATAGRAM_SOCKET_H
20
25
26extern "C" {
27 struct apr_socket_t;
28}
29
30namespace log4cxx
31{
32namespace helpers
33{
36class LOG4CXX_EXPORT DatagramSocket : public helpers::Object
37{
38 public:
43
44
47
50 DatagramSocket(int port);
51
54 DatagramSocket(int port, InetAddressPtr laddr);
55
58
60 void bind(int lport, InetAddressPtr laddress);
61
63 void create();
64
66 void close();
67
69 void connect(InetAddressPtr address, int port);
70
72 inline InetAddressPtr getInetAddress() const
73 {
74 return address;
75 }
76
78 inline InetAddressPtr getLocalAddress() const
79 {
80 return localAddress;
81 }
82
85 inline int getLocalPort() const
86 {
87 return localPort;
88 }
89
91 inline int getPort() const
92 {
93 return port;
94 }
95
97 inline bool isBound() const
98 {
99 return localPort != 0;
100 }
101
103 inline bool isClosed() const
104 {
105 return socket != 0;
106 }
107
109 inline bool isConnected() const
110 {
111 return port != 0;
112 }
113
115 void receive(DatagramPacketPtr& p);
116
118 void send(DatagramPacketPtr& p);
119
120 private:
122 DatagramSocket& operator=(const DatagramSocket&);
124 apr_socket_t* socket;
125
127 Pool socketPool;
128
129 InetAddressPtr address;
130
131 InetAddressPtr localAddress;
132
133 int port;
134
136 int localPort;
137
138};
140} // namespace helpers
141} // namespace log4cxx
142
143#endif //_LOG4CXX_HELPERS_DATAGRAM_SOCKET_H
This class represents a socket for sending and receiving datagram packets.
Definition: datagramsocket.h:37
InetAddressPtr getLocalAddress() const
Gets the local address to which the socket is bound.
Definition: datagramsocket.h:78
int getPort() const
Returns the port for this socket.
Definition: datagramsocket.h:91
int getLocalPort() const
Returns the port number on the local host to which this socket is bound.
Definition: datagramsocket.h:85
bool isClosed() const
Returns wether the socket is closed or not.
Definition: datagramsocket.h:103
void receive(DatagramPacketPtr &p)
Receives a datagram packet from this socket.
bool isConnected() const
Returns the connection state of the socket.
Definition: datagramsocket.h:109
void send(DatagramPacketPtr &p)
Sends a datagram packet from this socket.
bool isBound() const
Returns the binding state of the socket.
Definition: datagramsocket.h:97
base class for java-like objects.
Definition: object.h:102
Definition: pool.h:33
LOG4CXX_PTR_DEF(AppenderAttachableImpl)
Definition: messagehandler.h:23
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:153
#define DECLARE_ABSTRACT_LOG4CXX_OBJECT(object)
Definition: object.h:26
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:147
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:141