Apache log4cxx  Version 0.12.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 
21 #include <log4cxx/helpers/object.h>
23 #include <log4cxx/helpers/pool.h>
25 
26 extern "C" {
27  struct apr_socket_t;
28 }
29 
30 namespace log4cxx
31 {
32 namespace helpers
33 {
36 class LOG4CXX_EXPORT DatagramSocket : public helpers::Object
37 {
38  public:
43 
44 
47 
50  DatagramSocket(int port);
51 
54  DatagramSocket(int port, InetAddressPtr laddr);
55 
57  ~DatagramSocket();
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
InetAddressPtr getLocalAddress() const
Gets the local address to which the socket is bound.
Definition: datagramsocket.h:78
#define DECLARE_ABSTRACT_LOG4CXX_OBJECT(object)
Definition: object.h:26
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:148
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:142
LOG4CXX_PTR_DEF(AppenderAttachableImpl)
InetAddressPtr getInetAddress() const
Returns the address to which this socket is connected.
Definition: datagramsocket.h:72
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:136
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 isConnected() const
Returns the connection state of the socket.
Definition: datagramsocket.h:109
bool isBound() const
Returns the binding state of the socket.
Definition: datagramsocket.h:97
bool isClosed() const
Returns wether the socket is closed or not.
Definition: datagramsocket.h:103
base class for java-like objects.
Definition: object.h:101
Definition: pool.h:32
This class represents a socket for sending and receiving datagram packets.
Definition: datagramsocket.h:36
Definition: appender.h:32