skstream
sksocket.h
1 /**************************************************************************
2  FreeSockets - Portable C++ classes for IP(sockets) applications. (v0.3)
3  Copyright (C) 2000-2001 Rafael Guterres Jeffman
4  (C) 2003-2006 Alistair Riddoch
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20 **************************************************************************/
21 
29 #ifndef RGJ_FREE_SOCKET_H_
30 #define RGJ_FREE_SOCKET_H_
31 
32 #include <skstream/skstreamconfig.h>
33 
34 // This constant is defined in windows, but not in most other systems
35 #ifndef SOCKET_ERROR
36 static const int SOCKET_ERROR = -1;
37 #endif
38 
39 // This constant is defined in windows, but not in most other systems
40 #ifndef INVALID_SOCKET
41  #define INVALID_SOCKET (SOCKET_TYPE)~0
42 #endif // INVALID_SOCKET
43 
44 // All systems should define this, but it is here just in case
45 #ifndef INADDR_NONE
46  #warning System headers do not define INADDR_NONE
47  #define INADDR_NONE 0xFFFFFFFF
48 #endif // INADDR_NONE
49 
51 // Enumerations
53 // Supported Protocols
54 namespace FreeSockets {
55  enum IP_Protocol {
56  proto_IP = IPPROTO_IP,
57  proto_ICMP = IPPROTO_ICMP,
58 #ifndef _WIN32
59  proto_IGMP = IPPROTO_IGMP,
60 #else
61  proto_IGMP = IPPROTO_GGP,
62 #endif
63  proto_TCP = IPPROTO_TCP,
64  proto_PUP = IPPROTO_PUP,
65  proto_UDP = IPPROTO_UDP,
66  proto_IDP = IPPROTO_IDP,
67 #ifdef IPPROTO_SCTP
68  proto_SCTP = IPPROTO_SCTP,
69 #endif
70  proto_RAW = IPPROTO_RAW
71  };
72 };
73 
75 // class basic_socket, a virtual base class for use in polling
77 
79 class basic_socket {
80 private:
81  static int startup_count;
82 protected:
83  mutable int LastError;
84 
85  void setLastError() const;
86 
87  basic_socket();
88 public:
89  virtual ~basic_socket();
90 
91  virtual SOCKET_TYPE getSocket() const = 0;
92 
93  int getLastError() const {
94  return LastError;
95  }
96 
97  void copyLastError(const basic_socket & other) {
98  LastError = other.getLastError();
99  }
100 
101  bool is_open() const {
102  return (getSocket() != INVALID_SOCKET);
103  }
104 
105  static bool startup();
106 
107 };
108 
109 #endif // RGJ_FREE_SOCKET_H_
Base class for anything that encapsulates a socket.
Definition: sksocket.h:79
Definition: sksocket.h:54