activemq-cpp-3.9.5
Socket.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#ifndef _DECAF_NET_SOCKET_H_
18#define _DECAF_NET_SOCKET_H_
19
25#include <decaf/io/Closeable.h>
26#include <decaf/util/Config.h>
27
33
34namespace decaf{
35namespace net{
36
37 class SocketImpl;
38 class ServerSocket;
39
44 class DECAF_API Socket : public decaf::io::Closeable {
45 protected:
46
47 // The actual Socket that this Socket represents.
48 mutable SocketImpl* impl;
49
50 private:
51
52 // Factory for creating sockets, if not set a Plan TCP Socket is created
53 static SocketImplFactory* factory;
54
55 mutable volatile bool created;
56
57 bool connected;
58 bool closed;
59 bool bound;
60 bool inputShutdown;
61 bool outputShutdown;
62
63 friend class ServerSocket;
64
65 private:
66
67 Socket( const Socket& );
68 Socket& operator= ( const Socket& );
69
70 public:
71
77
89
107 Socket( const InetAddress* address, int port );
108
129 Socket( const InetAddress* address, int port, const InetAddress* localAddress, int localPort );
130
147 Socket( const std::string& host, int port );
148
169 Socket( const std::string& host, int port, const InetAddress* localAddress, int localPort );
170
171 virtual ~Socket();
172
187 virtual void bind( const std::string& ipaddress, int port );
188
195 virtual void close();
196
208 virtual void connect(const std::string& host, int port);
209
227 virtual void connect(const std::string& host, int port, int timeout);
228
234 bool isConnected() const {
235 return connected;
236 }
237
241 bool isClosed() const {
242 return closed;
243 }
244
248 bool isBound() const {
249 return bound;
250 }
251
255 bool isInputShutdown() const {
256 return inputShutdown;
257 }
258
262 bool isOutputShutdown() const {
263 return outputShutdown;
264 }
265
282
295
301 int getPort() const;
302
308 int getLocalPort() const;
309
315 std::string getInetAddress() const;
316
322 std::string getLocalAddress() const;
323
330 virtual void shutdownInput();
331
338 virtual void shutdownOutput();
339
348 virtual int getSoLinger() const;
349
362 virtual void setSoLinger(bool state, int timeout);
363
371 virtual bool getKeepAlive() const;
372
381 virtual void setKeepAlive(bool keepAlive);
382
391 virtual int getReceiveBufferSize() const;
392
402 virtual void setReceiveBufferSize(int size);
403
411 virtual bool getReuseAddress() const;
412
421 virtual void setReuseAddress(bool reuse);
422
431 virtual int getSendBufferSize() const;
432
443 virtual void setSendBufferSize(int size);
444
452 virtual int getSoTimeout() const;
453
464 virtual void setSoTimeout(int timeout);
465
473 virtual bool getTcpNoDelay() const;
474
484 virtual void setTcpNoDelay(bool value);
485
497 virtual int getTrafficClass() const;
498
512 virtual void setTrafficClass(int value);
513
521 virtual bool getOOBInline() const;
522
531 virtual void setOOBInline(bool value);
532
541 virtual void sendUrgentData(int data);
542
546 virtual std::string toString() const;
547
548 public:
549
562
563 protected:
564
565 // Flags the Socket instance as created, bound and connected when its connected
566 // via a ServerSocket accept call.
567 void accepted();
568
569 // Sets up a connected socket for the constructors that take connection arguments.
570 void initSocketImpl( const std::string& address, int port, const InetAddress* localAddress, int localPort );
571
572 // Check for already closed and throw an error if so.
573 void checkClosed() const;
574
575 // Create but don't connect the underlying OS Socket instance, if not already created.
576 void ensureCreated() const;
577
578 };
579
580}}
581
582#endif /*_DECAF_NET_SOCKET_H_*/
Interface for a class that implements the close method.
Definition Closeable.h:30
A base class that must be implemented by all classes wishing to provide a class that reads in a strea...
Definition InputStream.h:39
Base interface for any class that wants to represent an output stream of bytes.
Definition OutputStream.h:39
Represents an IP address.
Definition InetAddress.h:33
This class implements server sockets.
Definition ServerSocket.h:50
bool isOutputShutdown() const
Definition Socket.h:262
friend class ServerSocket
Definition Socket.h:63
Socket(const std::string &host, int port, const InetAddress *localAddress, int localPort)
Creates a new Socket instance and connects it to the given host and port.
void ensureCreated() const
virtual void setSendBufferSize(int size)
Gets the send buffer size for this socket, SO_SNDBUF, this value is used by the platform socket to bu...
SocketImpl * impl
Definition Socket.h:48
int getLocalPort() const
Gets the local port the socket is bound to.
Socket(SocketImpl *impl)
Creates a Socket wrapping the provided SocketImpl instance, this Socket is considered unconnected.
bool isInputShutdown() const
Definition Socket.h:255
virtual int getSoTimeout() const
Gets the timeout for socket operations, SO_TIMEOUT.
virtual int getReceiveBufferSize() const
Gets the receive buffer size for this socket, SO_RCVBUF.
bool isConnected() const
Indicates whether or not this socket is connected to am end point.
Definition Socket.h:234
virtual void connect(const std::string &host, int port)
Connects to the specified destination.
Socket(const std::string &host, int port)
Creates a new Socket instance and connects it to the given host and port.
virtual void connect(const std::string &host, int port, int timeout)
Connects to the specified destination, with a specified timeout value.
virtual void setReceiveBufferSize(int size)
Sets the receive buffer size for this socket, SO_RCVBUF.
static void setSocketImplFactory(SocketImplFactory *factory)
Sets the instance of a SocketImplFactory that the Socket class should use when new instances of this ...
virtual bool getKeepAlive() const
Gets the keep alive flag for this socket, SO_KEEPALIVE.
virtual decaf::io::OutputStream * getOutputStream()
Gets the OutputStream for this socket if it is connected.
virtual void bind(const std::string &ipaddress, int port)
Binds this Socket to the given local address and port.
void initSocketImpl(const std::string &address, int port, const InetAddress *localAddress, int localPort)
Socket()
Creates an unconnected Socket using the set SocketImplFactory or if non is set than the default SockI...
virtual bool getTcpNoDelay() const
Gets the Status of the TCP_NODELAY setting for this socket.
virtual void setReuseAddress(bool reuse)
Sets the reuse address flag, SO_REUSEADDR.
int getPort() const
Gets the on the remote host this Socket is connected to.
virtual decaf::io::InputStream * getInputStream()
Gets the InputStream for this socket if its connected.
virtual bool getOOBInline() const
Gets the value of the OOBINLINE for this socket.
bool isBound() const
Definition Socket.h:248
virtual int getSoLinger() const
Gets the linger time for the socket, SO_LINGER.
virtual void setTcpNoDelay(bool value)
Sets the Status of the TCP_NODELAY param for this socket., this setting is used to disable or enable ...
virtual int getTrafficClass() const
Gets the Traffic Class setting for this Socket, sometimes referred to as Type of Service setting.
virtual int getSendBufferSize() const
Gets the send buffer size for this socket, SO_SNDBUF, this value is used by the platform socket to bu...
virtual void close()
Closes the Socket.
virtual std::string toString() const
virtual void shutdownOutput()
Shuts down the OutputStream for this socket, any data already written to the socket will be sent,...
virtual void setKeepAlive(bool keepAlive)
Enables/disables the keep alive flag for this socket, SO_KEEPALIVE.
void checkClosed() const
Socket(const InetAddress *address, int port)
Creates a new Socket instance and connects it to the given address and port.
virtual void setSoTimeout(int timeout)
Sets the timeout for socket operations, SO_TIMEOUT.
std::string getInetAddress() const
Returns the address to which the socket is connected.
virtual void sendUrgentData(int data)
Sends on byte of urgent data to the Socket.
Socket(const InetAddress *address, int port, const InetAddress *localAddress, int localPort)
Creates a new Socket instance and connects it to the given address and port.
virtual void setSoLinger(bool state, int timeout)
Sets the linger time (SO_LINGER) using a specified time value, this limits of this value are platform...
virtual void setOOBInline(bool value)
Sets the value of the OOBINLINE for this socket, by default this option is disabled.
std::string getLocalAddress() const
Gets the local address to which the socket is bound.
virtual void setTrafficClass(int value)
Gets the Traffic Class setting for this Socket, sometimes referred to as Type of Service setting.
virtual bool getReuseAddress() const
Gets the reuse address flag, SO_REUSEADDR.
virtual void shutdownInput()
Shuts down the InputStream for this socket essentially marking it as EOF.
bool isClosed() const
Definition Socket.h:241
Factory class interface for a Factory that creates ScoketImpl objects.
Definition SocketImplFactory.h:38
Acts as a base class for all physical Socket implementations.
Definition SocketImpl.h:42
#define DECAF_API
Definition Config.h:29
Definition URLStreamHandlerManager.h:26
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25