ENUt

tcpv6socket.h

Go to the documentation of this file.
00001 /*
00002     
00003   This file is a part of ENUt, a library containing network
00004   programming utilities.
00005   
00006   Copyright (C) 2006-2008  Hasselt University - Expertise Centre for
00007                       Digital Media (EDM) (http://www.edm.uhasselt.be)
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00022   USA
00023 
00024 */
00025 
00030 #ifndef NUT_TCPV6SOCKET_H
00031 
00032 #define NUT_TCPV6SOCKET_H
00033 
00034 #include "nutconfig.h"
00035 
00036 #ifdef NUTCONFIG_SUPPORT_IPV6
00037 
00038 #include "tcpsocket.h"
00039 #include "ipv6address.h"
00040 
00041 namespace nut
00042 {
00043 
00045 class ENUT_IMPORTEXPORT TCPv6Socket : public TCPSocket
00046 {
00047 public:
00049         TCPv6Socket();
00050 
00052         TCPv6Socket(const std::string &objName);
00053 
00054         ~TCPv6Socket();
00055 
00056         bool create(uint16_t portNumber = 0);
00057         bool create(const NetworkLayerAddress &bindAddress, uint16_t portNumber = 0);
00058         bool destroy();
00059 
00060         bool setNonBlocking(bool f = true);
00061         
00062         uint16_t getLocalPortNumber()                                                           { return m_localPort; }
00063 
00064         bool connect(const NetworkLayerAddress &hostAddress, uint16_t portNumber);
00065         bool listen(int backlog);
00066         bool accept(TCPSocket **newsock);
00067         bool isConnected()                                                                      { return m_connected; }
00068         
00069         const NetworkLayerAddress *getDestinationAddress() const                                { return m_destIP; }
00070         uint16_t getDestinationPort() const                                                     { return m_destPort; }
00071         
00072         bool write(const void *data, size_t &length);
00073         bool getAvailableDataLength(size_t &length);
00074         bool read(void *buffer, size_t &bufferSize);
00075 protected:
00076         int getSocketDescriptor()                                                               { return m_sock; }
00077 private:
00078         // make sure we can't copy the socket
00079         TCPv6Socket(const TCPv6Socket &s) : TCPSocket(s)                                        { }
00080         TCPv6Socket &operator=(const TCPv6Socket &s)                                            { }
00081         
00082         TCPv6Socket(int sock, uint16_t localPort, in6_addr destIP, uint16_t destPort);
00083         bool internalCreate(in6_addr ip, uint16_t port);
00084         void zeroAll();
00085 
00086         int m_sock;
00087         bool m_connected, m_listening;
00088         uint16_t m_localPort;
00089         uint16_t m_destPort;
00090         IPv6Address *m_destIP;
00091 };
00092 
00093 }
00094 
00095 #endif // NUTCONFIG_SUPPORT_IPV6
00096 
00097 #endif // NUT_TCPV6SOCKET_H
00098