Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/cxxtools/include/cxxtools/net/net.h

00001 /*
00002  * Copyright (C) 2005 Tommi Maekitalo
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00027  */
00028 
00029 #ifndef CXXTOOLS_NET_NET_H
00030 #define CXXTOOLS_NET_NET_H
00031 
00032 #include <cxxtools/ioerror.h>
00033 #include <cxxtools/noncopyable.h>
00034 
00035 namespace cxxtools
00036 {
00037 
00038 namespace net
00039 {
00040   typedef IOTimeout Timeout;
00041 
00042   class AddressInUse : public IOError
00043   {
00044     public:
00045       AddressInUse();
00046   };
00047 
00049 
00052   class Socket : private NonCopyable
00053   {
00054 
00055     public:
00057       Socket(int domain, int type, int protocol);
00058 
00061       explicit Socket(int fd = -1)
00062         : m_sockFd(fd),
00063           m_timeout(-1)
00064         { }
00065 
00068       virtual ~Socket();
00069 
00071       bool good() const     { return m_sockFd >= 0; }
00073       bool bad() const      { return m_sockFd <  0; }
00075       operator bool() const { return m_sockFd >= 0; }
00076 
00079       void create(int domain, int type, int protocol);
00081       void close();
00082 
00084       int getFd() const     { return m_sockFd; }
00085 
00087       std::string getSockAddr() const;
00088 
00090       void setTimeout(int t);
00092       int getTimeout() const  { return m_timeout; }
00093 
00096       short poll(short events) const;
00097 
00098     protected:
00099       void setFd(int sockFd);
00100 
00101     private:
00102       int m_sockFd;
00103       int m_timeout;
00104   };
00105 
00106 } // namespace net
00107 
00108 } // namespace cxxtools
00109 
00110 #endif // CXXTOOLS_NET_NET_H
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6