ENUt

socket.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_SOCKET_H
00031 
00032 #define NUT_SOCKET_H
00033 
00034 #include "nutconfig.h"
00035 #include "nuttypes.h"
00036 #include <errut/errorbase.h>
00037 #include <stdio.h>
00038 #if !(defined(WIN32) || defined(_WIN32_WCE))
00039         #include <sys/socket.h>
00040         #include <netinet/in.h>
00041         #include <arpa/inet.h>
00042         #include <sys/ioctl.h>
00043         #include <net/if.h>
00044         #include <string.h>
00045         #include <netdb.h>
00046         #include <unistd.h>
00047         #include <errno.h>
00048 #endif // ! (WIN32 || _WIN32_WCE)
00049 
00050 namespace nut
00051 {
00052 
00054 class ENUT_IMPORTEXPORT Socket : public errut::ErrorBase
00055 {
00056 protected:
00058         Socket()                                                                                        { m_dataAvailable = false; }
00059 
00061         Socket(const std::string &objName) : errut::ErrorBase(objName)                                  { }
00062 public:
00063         ~Socket()                                                                                       { }
00064 
00068         bool setSocketOption(int level, int optname, const void *optval, socklen_t optlen);
00069 
00073         bool getSocketOption(int level, int optname, void *optval, socklen_t *optlen);
00074         
00083         bool waitForData(int seconds = -1, int microSeconds = -1);
00084 
00089         bool isDataAvailable() const                                                                    { return m_dataAvailable; }
00090 protected:
00091 #if (defined(WIN32) || defined(_WIN32_WCE))
00092         virtual SOCKET getSocketDescriptor() = 0;
00093 #else
00094         virtual int getSocketDescriptor() = 0;
00095 #endif // WIN32 || _WIN32_WCE
00096 private:
00097         void setDataAvailable(bool f)                                                                   { m_dataAvailable = f; }
00098 
00099         bool m_dataAvailable;
00100         
00101         friend class SocketWaiter;
00102 };
00103         
00104 } // end namespace
00105         
00106 #endif // NUT_SOCKET_H
00107