activemq-cpp-3.3.0

src/main/decaf/internal/net/tcp/TcpSocket.h

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef _DECAF_INTERNAL_NET_TCP_TCPSOCKET_H_
00018 #define _DECAF_INTERNAL_NET_TCP_TCPSOCKET_H_
00019 
00020 #include <decaf/net/SocketException.h>
00021 #include <decaf/net/SocketImpl.h>
00022 #include <decaf/io/InputStream.h>
00023 #include <decaf/io/OutputStream.h>
00024 #include <decaf/util/Config.h>
00025 #include <decaf/internal/AprPool.h>
00026 
00027 #include <apr_network_io.h>
00028 
00029 #include <decaf/io/IOException.h>
00030 #include <decaf/net/SocketTimeoutException.h>
00031 #include <decaf/lang/exceptions/NullPointerException.h>
00032 #include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
00033 
00034 namespace decaf {
00035 namespace internal {
00036 namespace net {
00037 namespace tcp {
00038 
00039     // Forward declarations
00040     class TcpSocketInputStream;
00041     class TcpSocketOutputStream;
00042 
00046     class DECAF_API TcpSocket : public decaf::net::SocketImpl {
00047     private:
00048 
00052         typedef apr_socket_t* SocketHandle;
00053 
00057         typedef apr_sockaddr_t* SocketAddress;
00058 
00059     private:
00060 
00061         TcpSocket( const TcpSocket& );
00062         TcpSocket& operator= ( const TcpSocket& );
00063 
00064     private:
00065 
00069         decaf::internal::AprPool apr_pool;
00070 
00074         SocketHandle socketHandle;
00075 
00079         SocketAddress localAddress;
00080 
00084         SocketAddress remoteAddress;
00085 
00089         TcpSocketInputStream* inputStream;
00090 
00094         TcpSocketOutputStream* outputStream;
00095 
00099         bool inputShutdown;
00100 
00104         bool outputShutdown;
00105 
00109         volatile bool closed;
00110 
00114         int trafficClass;
00115 
00119         int soTimeout;
00120 
00125         mutable int soLinger;
00126 
00127     public:
00128 
00134         TcpSocket();
00135 
00139         virtual ~TcpSocket();
00140 
00145         SocketHandle getSocketHandle () {
00146             return socketHandle;
00147         }
00148 
00152         bool isConnected() const {
00153             return socketHandle != NULL;
00154         }
00155 
00159         bool isClosed() const {
00160             return this->closed;
00161         }
00162 
00166         virtual std::string getLocalAddress() const;
00167 
00171         virtual void create();
00172 
00176         virtual void accept( SocketImpl* socket );
00177 
00181         virtual void bind( const std::string& ipaddress, int port );
00182 
00186         virtual void connect( const std::string& hostname, int port, int timeout );
00187 
00191         virtual void listen( int backlog );
00192 
00196         virtual decaf::io::InputStream* getInputStream();
00197 
00201         virtual decaf::io::OutputStream* getOutputStream();
00202 
00206         virtual int available();
00207 
00211         virtual void close();
00212 
00216         virtual void shutdownInput();
00217 
00221         virtual void shutdownOutput();
00222 
00226         virtual int getOption( int option ) const;
00227 
00231         virtual void setOption( int option, int value );
00232 
00233     public:
00234 
00253         int read( unsigned char* buffer, int size, int offset, int length );
00254 
00271         void write( const unsigned char* buffer, int size, int offset, int length );
00272 
00273     protected:
00274 
00275         void checkResult( apr_status_t value ) const;
00276 
00277     };
00278 
00279 }}}}
00280 
00281 #endif /*_DECAF_INTERNAL_NET_TCP_TCPSOCKET_H_*/