00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _Comm_h
00030 #define _Comm_h
00031
00032 #include <sienaconf.h>
00033
00034 #ifdef USING_WIN32
00035 #include <winsock.h>
00036 #else
00037 #include<sys/socket.h>
00038 #include<netinet/in.h>
00039 #endif
00040
00041 #include <exception>
00042 #include <string>
00043
00044 using namespace std;
00045
00046 #ifdef HAVE_CXX_NAMESPACE
00047 namespace Siena {
00048 #endif
00049
00052 class CommException: public exception {
00053 public:
00054 virtual const char *what() const throw ();
00055 };
00056
00059 class CommError: public CommException {
00060 public:
00061 virtual const char *what() const throw ();
00062 };
00063
00066 class CommInterrupted: public CommException {
00067 public:
00068 virtual const char *what() const throw ();
00069 };
00070
00073 class BadSender: public exception {
00074 public:
00075 virtual const char *what() const throw ();
00076 };
00077
00080 class BadSenderSchema: public BadSender {
00081 public:
00082 virtual const char *what() const throw ();
00083 };
00084
00087 class UnknownHost: public BadSender {
00088 public:
00089 virtual const char *what() const throw ();
00090 };
00091
00100 class Sender {
00101 public:
00106 static Sender * create_sender(const string &);
00107
00108 virtual ~Sender();
00109
00114 virtual void send(const char *, size_t) throw (CommException) = 0;
00115
00118 virtual void shutdown();
00119 };
00120
00129 class Receiver {
00130 public:
00133 virtual ~Receiver();
00134
00141 virtual string uri() = 0;
00142
00149 virtual string & uri(string &) = 0;
00150
00155 virtual size_t receive(char *, size_t) throw (CommException) = 0;
00156
00159 virtual void shutdown();
00160 };
00161
00167 class TCPSender: public Sender {
00168 public:
00169 TCPSender(const string &host, in_port_t port);
00170 TCPSender(in_addr_t ip, in_port_t port);
00171
00172 virtual void send(const char *, size_t) throw (CommException);
00173
00174 private:
00175 in_port_t port;
00176 in_addr_t ip;
00177 };
00178
00185 class UDPSender: public Sender {
00186 public:
00187 UDPSender(const string &host, in_port_t port);
00188 UDPSender(in_addr_t ip, in_port_t port);
00189
00190 virtual void shutdown();
00191
00192 virtual void send(const char *, size_t) throw (CommException);
00193 private:
00194 in_port_t port;
00195 in_addr_t ip;
00196 #ifdef USING_WIN32
00197 SOCKET sock_fd;
00198 #else
00199 int sock_fd;
00200 #endif
00201 };
00202
00211 class TCPReceiver: public Receiver {
00212 public:
00231 TCPReceiver(in_port_t port,
00232 const char * hostname = NULL,
00233 bool reuse = true,
00234 int maxconn = -1 );
00235
00236 virtual size_t receive(char *, size_t) throw (CommException);
00237 virtual void shutdown();
00238
00239 virtual string uri();
00240 virtual string & uri(string &);
00241
00242 private:
00243 in_port_t port;
00244 string _uri;
00245 #ifdef USING_WIN32
00246 SOCKET sock_fd;
00247 #else
00248 int sock_fd;
00249 #endif
00250 };
00251
00252
00258 class UDPReceiver: public Receiver {
00259 public:
00275 UDPReceiver(in_port_t port,
00276 const char * hostname = NULL,
00277 bool reuse = true);
00278
00279 virtual size_t receive(char *, size_t) throw (CommException);
00280 virtual void shutdown();
00281
00282 virtual string uri();
00283 virtual string & uri(string &);
00284
00285 private:
00286 in_port_t port;
00287 string _uri;
00288 #ifdef USING_WIN32
00289 SOCKET sock_fd;
00290 #else
00291 int sock_fd;
00292 #endif
00293 };
00294
00295 #ifndef NO_INLINE
00296 #include <siena/Comm.icc>
00297 #endif
00298
00299 #ifdef HAVE_CXX_NAMESPACE
00300 };
00301 #endif
00302
00303 #endif