You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/03/26 22:08:03 UTC
svn commit: r928061 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main:
Makefile.am decaf/net/SocketImpl.cpp decaf/net/SocketImpl.h
decaf/net/SocketOptions.cpp decaf/net/SocketOptions.h
Author: tabish
Date: Fri Mar 26 21:08:03 2010
New Revision: 928061
URL: http://svn.apache.org/viewvc?rev=928061&view=rev
Log:
Add some more Socket implementation interfaces.
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.h (with props)
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=928061&r1=928060&r2=928061&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Fri Mar 26 21:08:03 2010
@@ -548,6 +548,8 @@ cc_sources = \
decaf/net/ServerSocket.cpp \
decaf/net/SocketError.cpp \
decaf/net/SocketFactory.cpp \
+ decaf/net/SocketImpl.cpp \
+ decaf/net/SocketOptions.cpp \
decaf/net/URI.cpp \
decaf/net/URL.cpp \
decaf/net/URLDecoder.cpp \
@@ -1247,6 +1249,8 @@ h_sources = \
decaf/net/SocketError.h \
decaf/net/SocketException.h \
decaf/net/SocketFactory.h \
+ decaf/net/SocketImpl.h \
+ decaf/net/SocketOptions.h \
decaf/net/SocketTimeoutException.h \
decaf/net/URI.h \
decaf/net/URISyntaxException.h \
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp?rev=928061&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp Fri Mar 26 21:08:03 2010
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SocketImpl.h"
+
+#include <decaf/lang/Integer.h>
+
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+SocketImpl::SocketImpl() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SocketImpl::~SocketImpl() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string SocketImpl::toString() const {
+
+ std::string result = std::string( "Socket[addr=" ) + this->hostname +
+ ",port=" + Integer::toString( this->port ) + "]";
+
+ return result;
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h?rev=928061&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h Fri Mar 26 21:08:03 2010
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_NET_SOCKETIMPL_H_
+#define _DECAF_NET_SOCKETIMPL_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/io/IOException.h>
+#include <decaf/io/InputStream.h>
+#include <decaf/io/OutputStream.h>
+
+#include <decaf/net/SocketException.h>
+#include <decaf/net/SocketOptions.h>
+
+#include <string>
+
+namespace decaf {
+namespace net {
+
+ /**
+ * Acts as a base class for all physical Socket implementations.
+ *
+ * @since 1.0
+ */
+ class DECAF_API SocketImpl : public SocketOptions {
+ private:
+
+ int port;
+ std::string hostname;
+
+ public:
+
+ SocketImpl();
+
+ virtual ~SocketImpl();
+
+ protected:
+
+ /**
+ * Accepts a new connection on the given Socket.
+ *
+ * @param socket
+ * The accepted connection.
+ *
+ * @throws IOException if an I/O error occurs while attempting this operation.
+ */
+ virtual void accept( SocketImpl* socket ) throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Connects this socket to the given host and port.
+ *
+ * @param hostname
+ * The name of the host to connect to, or IP address.
+ * @param port
+ * The port number on the host to connect to.
+ *
+ * @throws IOException if an I/O error occurs while attempting this operation.
+ */
+ virtual void connect( const std::string& hostname, int port )
+ throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Binds this Socket instance to the local ip address and port number given.
+ *
+ * @param ipaddress
+ * The address of local ip to bind to.
+ * @param port
+ * The port number on the host to bind to.
+ *
+ * @throws IOException if an I/O error occurs while attempting this operation.
+ */
+ virtual void bind( const std::string& ipaddress, int port )
+ throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Sets the maximum queue length for incoming connection indications (a request to
+ * connect) to the count argument. If a connection indication arrives when the queue is
+ * full, the connection is refused.
+ *
+ * @param backlog
+ * The maximum length of the connection queue.
+ *
+ * @throws IOException if an I/O error occurs while attempting this operation.
+ */
+ virtual void listen( int backlog )
+ throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Gets the InputStream linked to this Socket.
+ *
+ * @returns an InputStream pointer owned by the Socket object.
+ *
+ * @throws IOException if an I/O error occurs while attempting this operation.
+ */
+ virtual decaf::io::InputStream* getInputStream()
+ throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Gets the OutputStream linked to this Socket.
+ *
+ * @returns an OutputStream pointer owned by the Socket object.
+ *
+ * @throws IOException if an I/O error occurs while attempting this operation.
+ */
+ virtual decaf::io::OutputStream* getOutputStream()
+ throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Gets the number of bytes that can be read from the Socket without blocking.
+ *
+ * @returns the number of bytes that can be read from the Socket without blocking.
+ *
+ * @throws IOException if an I/O error occurs while attempting this operation.
+ */
+ virtual int available()
+ throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Closes the socket, terminating any blocked reads or writes.
+ *
+ * @throws IOException if an I/O error occurs while attempting this operation.
+ */
+ virtual void close() throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Places the input stream for this socket at "end of stream". Any data sent to this
+ * socket is acknowledged and then silently discarded. If you read from a socket input
+ * stream after invoking shutdownInput() on the socket, the stream will return EOF.
+ *
+ * @throws IOException if an I/O error occurs while attempting this operation.
+ */
+ virtual void shutdownInput() throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Disables the output stream for this socket. For a TCP socket, any previously written
+ * data will be sent followed by TCP's normal connection termination sequence. If you
+ * write to a socket output stream after invoking shutdownOutput() on the socket, the
+ * stream will throw an IOException.
+ *
+ * @throws IOException if an I/O error occurs while attempting this operation.
+ */
+ virtual void shutdownOutput() throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Gets the port that this socket has been assigned.
+ *
+ * @return the Socket's port number.
+ */
+ int getPort() {
+ return this->port;
+ }
+
+ /**
+ * Returns a string containing the address and port of this Socket instance.
+ *
+ * @returns a string containing the address and port of this socket.
+ */
+ std::string toString() const;
+
+ };
+
+}}
+
+#endif /* _DECAF_NET_SOCKETIMPL_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketImpl.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.cpp?rev=928061&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.cpp Fri Mar 26 21:08:03 2010
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SocketOptions.h"
+
+using namespace decaf;
+using namespace net;
+
+////////////////////////////////////////////////////////////////////////////////
+const int SocketOptions::IP_MULTICAST_IF = 16;
+const int SocketOptions::IP_MULTICAST_IF2 = 31;
+const int SocketOptions::IP_MULTICAST_LOOP = 18;
+const int SocketOptions::IP_TOS = 3;
+const int SocketOptions::SO_BINDADDR = 15;
+const int SocketOptions::SO_BROADCAST = 32;
+const int SocketOptions::SO_KEEPALIVE = 8;
+const int SocketOptions::SO_LINGER = 128;
+const int SocketOptions::SO_OOBINLINE = 4099;
+const int SocketOptions::SO_RCVBUF = 4098;
+const int SocketOptions::SO_REUSEADDR = 4;
+const int SocketOptions::SO_SNDBUF = 4097;
+const int SocketOptions::SO_TIMEOUT = 4102;
+const int SocketOptions::TCP_NODELAY = 1;
+
+////////////////////////////////////////////////////////////////////////////////
+SocketOptions::~SocketOptions() {
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.h?rev=928061&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.h Fri Mar 26 21:08:03 2010
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_NET_SOCKETOPTIONS_H_
+#define _DECAF_NET_SOCKETOPTIONS_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf {
+namespace net {
+
+ /**
+ *
+ * @since 1.0
+ */
+ class DECAF_API SocketOptions {
+ public:
+
+ /**
+ * Disable Nagle's algorithm for this connection. Written data to the network is not
+ * buffered pending acknowledgment of previously written data. Valid for TCP sockets.
+ */
+ static const int TCP_NODELAY;
+
+ /**
+ * Fetch the local address binding of a socket (this option cannot be "set" only "gotten",
+ * since sockets are bound at creation time, and so the locally bound address cannot be
+ * changed). The default local address of a socket is INADDR_ANY, meaning any local address
+ * on a multi-homed host. A multi-homed host can use this option to accept connections to
+ * only one of its addresses (in the case of a ServerSocket or DatagramSocket), or to
+ * specify its return address to the peer (for a Socket or DatagramSocket). The parameter
+ * of this option is an InetAddress.
+ */
+ static const int SO_BINDADDR;
+
+ /**
+ * Sets SO_REUSEADDR for a socket. This is used only for MulticastSockets in decaf, and it is
+ * set by default for MulticastSockets.
+ */
+ static const int SO_REUSEADDR;
+
+ /**
+ * Sets SO_BROADCAST for a socket. This option enables and disables the ability of the process
+ * to send broadcast messages. It is supported for only datagram sockets and only on networks
+ * that support the concept of a broadcast message (e.g. Ethernet, token ring, etc.), and it
+ * is set by default for DatagramSockets.
+ */
+ static const int SO_BROADCAST;
+
+ /**
+ * Set which outgoing interface on which to send multicast packets. Useful on hosts with
+ * multiple network interfaces, where applications want to use other than the system default.
+ * Takes/returns an InetAddress.
+ *
+ * Valid for Multicast: DatagramSocketImpl.
+ */
+ static const int IP_MULTICAST_IF;
+
+ /**
+ * Same as above. This option is introduced so that the behaviour with IP_MULTICAST_IF will
+ * be kept the same as before, while this new option can support setting outgoing interfaces
+ * with either IPv4 and IPv6 addresses.
+ */
+ static const int IP_MULTICAST_IF2;
+
+ /**
+ * This option enables or disables local loopback of multicast datagrams. This option is enabled
+ * by default for Multicast Sockets.
+ */
+ static const int IP_MULTICAST_LOOP;
+
+ /**
+ * This option sets the type-of-service or traffic class field in the IP header for a TCP or
+ * UDP socket.
+ */
+ static const int IP_TOS;
+
+ /**
+ * Specify a linger-on-close timeout. This option disables/enables immediate return from a
+ * close() of a TCP Socket. Enabling this option with a non-zero Integer timeout means that
+ * a close() will block pending the transmission and acknowledgment of all data written to the
+ * peer, at which point the socket is closed gracefully. Upon reaching the linger timeout, the
+ * socket is closed forcefully, with a TCP RST. Enabling the option with a timeout of zero
+ * does a forceful close immediately. If the specified timeout value exceeds 65,535 it will
+ * be reduced to 65,535.
+ *
+ * Valid only for TCP: SocketImpl
+ */
+ static const int SO_LINGER;
+
+ /**
+ * Set a timeout on blocking Socket operations. The option must be set prior to entering a
+ * blocking operation to take effect.
+ */
+ static const int SO_TIMEOUT;
+
+ /**
+ * Set a hint the size of the underlying buffers used by the platform for outgoing network
+ * I/O. When used in set, this is a suggestion to the kernel from the application about the
+ * size of buffers to use for the data to be sent over the socket. When used in get, this
+ * must return the size of the buffer actually used by the platform when sending out data
+ * on this socket. Valid for all sockets: SocketImpl, DatagramSocketImpl
+ */
+ static const int SO_SNDBUF;
+
+ /**
+ * Set a hint the size of the underlying buffers used by the platform for incoming network
+ * I/O. When used in set, this is a suggestion to the kernel from the application about the
+ * size of buffers to use for the data to be received over the socket. When used in get,
+ * this must return the size of the buffer actually used by the platform when receiving in
+ * data on this socket. Valid for all sockets: SocketImpl, DatagramSocketImpl.
+ */
+ static const int SO_RCVBUF;
+
+ /**
+ * When the keepalive option is set for a TCP socket and no data has been exchanged across
+ * the socket in either direction for 2 hours (NOTE: the actual value is implementation
+ * dependent), TCP automatically sends a keepalive probe to the peer. This probe is a TCP
+ * segment to which the peer must respond. One of three responses is expected: 1. The peer
+ * responds with the expected ACK. The application is not notified (since everything is OK).
+ * TCP will send another probe following another 2 hours of inactivity. 2. The peer responds
+ * with an RST, which tells the local TCP that the peer host has crashed and rebooted. The
+ * socket is closed. 3. There is no response from the peer. The socket is closed. The
+ * purpose of this option is to detect if the peer host crashes.
+ *
+ * Valid only for TCP socket: SocketImpl
+ */
+ static const int SO_KEEPALIVE;
+
+ /**
+ * When the OOBINLINE option is set, any TCP urgent data received on the socket will be
+ * received through the socket input stream. When the option is disabled (which is the default)
+ * urgent data is silently discarded.
+ */
+ static const int SO_OOBINLINE;
+
+ public:
+
+ virtual ~SocketOptions();
+
+ };
+
+}}
+
+#endif /* _DECAF_NET_SOCKETOPTIONS_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketOptions.h
------------------------------------------------------------------------------
svn:eol-style = native