skstream
|
00001 /************************************************************************** 00002 FreeSockets - Portable C++ classes for IP(sockets) applications. (v0.3) 00003 Copyright (C) 2000-2001 Rafael Guterres Jeffman 00004 (C) 2003-2006 Alistair Riddoch 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 **************************************************************************/ 00021 00029 #ifndef RGJ_FREE_SOCKET_H_ 00030 #define RGJ_FREE_SOCKET_H_ 00031 00032 #include <skstream/skstreamconfig.h> 00033 00034 // This constant is defined in windows, but not in most other systems 00035 #ifndef SOCKET_ERROR 00036 static const int SOCKET_ERROR = -1; 00037 #endif 00038 00039 // This constant is defined in windows, but not in most other systems 00040 #ifndef INVALID_SOCKET 00041 #define INVALID_SOCKET (SOCKET_TYPE)~0 00042 #endif // INVALID_SOCKET 00043 00044 // All systems should define this, but it is here just in case 00045 #ifndef INADDR_NONE 00046 #warning System headers do not define INADDR_NONE 00047 #define INADDR_NONE 0xFFFFFFFF 00048 #endif // INADDR_NONE 00049 00051 // Enumerations 00053 // Supported Protocols 00054 namespace FreeSockets { 00055 enum IP_Protocol { 00056 proto_IP = IPPROTO_IP, 00057 proto_ICMP = IPPROTO_ICMP, 00058 #ifndef _WIN32 00059 proto_IGMP = IPPROTO_IGMP, 00060 #else 00061 proto_IGMP = IPPROTO_GGP, 00062 #endif 00063 proto_TCP = IPPROTO_TCP, 00064 proto_PUP = IPPROTO_PUP, 00065 proto_UDP = IPPROTO_UDP, 00066 proto_IDP = IPPROTO_IDP, 00067 #ifdef IPPROTO_SCTP 00068 proto_SCTP = IPPROTO_SCTP, 00069 #endif 00070 proto_RAW = IPPROTO_RAW 00071 }; 00072 }; 00073 00075 // class basic_socket, a virtual base class for use in polling 00077 00079 class basic_socket { 00080 private: 00081 static int startup_count; 00082 protected: 00083 mutable int LastError; 00084 00085 void setLastError() const; 00086 00087 basic_socket(); 00088 public: 00089 virtual ~basic_socket(); 00090 00091 virtual SOCKET_TYPE getSocket() const = 0; 00092 00093 int getLastError() const { 00094 return LastError; 00095 } 00096 00097 void copyLastError(const basic_socket & other) { 00098 LastError = other.getLastError(); 00099 } 00100 00101 bool is_open() const { 00102 return (getSocket() != INVALID_SOCKET); 00103 } 00104 00105 static bool startup(); 00106 00107 }; 00108 00109 #endif // RGJ_FREE_SOCKET_H_