Apache log4cxx  Version 0.11.0
datagramsocket.h
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/objectimpl.h>
22 #include <log4cxx/helpers/objectptr.h>
23 #include <log4cxx/helpers/inetaddress.h>
24 #include <log4cxx/helpers/pool.h>
25 #include <log4cxx/helpers/datagrampacket.h>
26 
27 extern "C" {
28  struct apr_socket_t;
29 }
30 
31 namespace log4cxx
32 {
33 namespace helpers
34 {
37 class LOG4CXX_EXPORT DatagramSocket : public helpers::ObjectImpl
38 {
39  public:
40  DECLARE_ABSTRACT_LOG4CXX_OBJECT(DatagramSocket)
41  BEGIN_LOG4CXX_CAST_MAP()
42  LOG4CXX_CAST_ENTRY(DatagramSocket)
43  END_LOG4CXX_CAST_MAP()
44 
45 
48 
51  DatagramSocket(int port);
52 
55  DatagramSocket(int port, InetAddressPtr laddr);
56 
58  ~DatagramSocket();
59 
61  void bind(int lport, InetAddressPtr laddress);
62 
64  void create();
65 
67  void close();
68 
70  void connect(InetAddressPtr address, int port);
71 
73  inline InetAddressPtr getInetAddress() const
74  {
75  return address;
76  }
77 
79  inline InetAddressPtr getLocalAddress() const
80  {
81  return localAddress;
82  }
83 
86  inline int getLocalPort() const
87  {
88  return localPort;
89  }
90 
92  inline int getPort() const
93  {
94  return port;
95  }
96 
98  inline bool isBound() const
99  {
100  return localPort != 0;
101  }
102 
104  inline bool isClosed() const
105  {
106  return socket != 0;
107  }
108 
110  inline bool isConnected() const
111  {
112  return port != 0;
113  }
114 
116  void receive(DatagramPacketPtr& p);
117 
119  void send(DatagramPacketPtr& p);
120 
121  private:
123  DatagramSocket& operator=(const DatagramSocket&);
125  apr_socket_t* socket;
126 
128  Pool socketPool;
129 
130  InetAddressPtr address;
131 
132  InetAddressPtr localAddress;
133 
134  int port;
135 
137  int localPort;
138 
139 };
140 LOG4CXX_PTR_DEF(DatagramSocket);
141 } // namespace helpers
142 } // namespace log4cxx
143 
144 #endif //_LOG4CXX_HELPERS_DATAGRAM_SOCKET_H
InetAddressPtr getLocalAddress() const
Gets the local address to which the socket is bound.
Definition: datagramsocket.h:79
InetAddressPtr getInetAddress() const
Returns the address to which this socket is connected.
Definition: datagramsocket.h:73
int getPort() const
Returns the port for this socket.
Definition: datagramsocket.h:92
int getLocalPort() const
Returns the port number on the local host to which this socket is bound.
Definition: datagramsocket.h:86
bool isConnected() const
Returns the connection state of the socket.
Definition: datagramsocket.h:110
bool isBound() const
Returns the binding state of the socket.
Definition: datagramsocket.h:98
bool isClosed() const
Returns wether the socket is closed or not.
Definition: datagramsocket.h:104
Implementation class for Object.
Definition: objectimpl.h:28
Definition: pool.h:32
This class represents a socket for sending and receiving datagram packets.
Definition: datagramsocket.h:37
Definition: appender.h:33