Siena C++ API documentation (v. 0.4.1)

Main Page   Class Hierarchy   Compound List   File List   Compound Members   Examples  

Comm.h

00001 // -*- C++ -*-
00002 //
00003 //  This file is part of Siena, a wide-area event notification system.
00004 //  See http://www.cs.colorado.edu/serl/siena/
00005 //
00006 //  Author: Antonio Carzaniga <carzanig@cs.colorado.edu>
00007 //  See the file AUTHORS for full details. 
00008 //
00009 //  Copyright (C) 1998-2001 University of Colorado
00010 //
00011 //  This program is free software; you can redistribute it and/or
00012 //  modify it under the terms of the GNU General Public License
00013 //  as published by the Free Software Foundation; either version 2
00014 //  of the License, or (at your option) any later version.
00015 //
00016 //  This program is distributed in the hope that it will be useful,
00017 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License
00022 //  along with this program; if not, write to the Free Software
00023 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
00024 //  USA, or send email to serl@cs.colorado.edu.
00025 //
00026 //
00027 // $Id: Comm.h,v 1.4 2001/06/26 22:03:27 carzanig Exp $
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 #ifdef USING_WIN32
00045 using namespace std;
00046 #endif
00047 
00048 #include <stdio.h>
00049 
00050 #ifdef HAVE_CXX_NAMESPACE
00051 namespace Siena {
00052 #endif
00053 
00056 class CommException: public exception {
00057 public:
00058     virtual const char *what() const;
00059 };
00060 
00063 class CommError: public CommException {
00064 public:
00065     virtual const char *what() const;
00066 };
00067 
00070 class CommInterrupted: public CommException {
00071 public:
00072     virtual const char *what() const;
00073 };
00074 
00077 class BadSender: public exception {
00078 public:
00079     virtual const char *what() const;
00080 };
00081 
00084 class BadSenderSchema: public BadSender {
00085 public:
00086     virtual const char *what() const;
00087 };
00088 
00091 class UnknownHost: public BadSender {
00092 public:
00093     virtual const char *what() const;
00094 };
00095 
00104 class Sender { 
00105  public:
00110     static Sender *     create_sender(const string &);
00111 
00112     virtual             ~Sender();
00113 
00118     virtual void        send(const char *, size_t) throw (CommException) = 0;
00119 
00122     virtual void        shutdown();
00123 };
00124 
00133 class Receiver { 
00134  public:
00137     virtual             ~Receiver();
00138 
00145     virtual string      uri() = 0;
00146 
00153     virtual string &    uri(string &) = 0;
00154 
00159     virtual size_t      receive(char *, size_t) throw (CommException) = 0;
00160 
00163     virtual void        shutdown();
00164 };
00165 
00171 class TCPSender: public Sender {
00172 public:
00173                         TCPSender(const string &host, in_port_t port);
00174                         TCPSender(in_addr_t ip, in_port_t port);
00175 
00176     virtual void        send(const char *, size_t) throw (CommException);
00177 
00178 private:
00179     in_port_t port;
00180     in_addr_t ip;
00181 };
00182 
00189 class UDPSender: public Sender {
00190 public:
00191                         UDPSender(const string &host, in_port_t port);
00192                         UDPSender(in_addr_t ip, in_port_t port);
00193 
00194     virtual void        shutdown();
00195 
00196     virtual void        send(const char *, size_t) throw (CommException);
00197 private:
00198     in_port_t port;
00199     in_addr_t ip;
00200 #ifdef USING_WIN32
00201     SOCKET sock_fd;
00202 #else
00203     int sock_fd;
00204 #endif
00205 };
00206 
00214 class TCPReceiver: public Receiver {
00215 public:
00234                         TCPReceiver(in_port_t port, 
00235                                     const char * hostname = NULL, 
00236                                     bool reuse = true, 
00237                                     int maxconn = -1 /* default */);
00238 
00239     virtual size_t      receive(char *, size_t) throw (CommException);
00240     virtual void        shutdown();
00241 
00242     virtual string      uri();
00243     virtual string &    uri(string &);
00244 
00245 private:
00246     in_port_t port;
00247     string _uri;
00248 #ifdef USING_WIN32
00249     SOCKET sock_fd;
00250 #else
00251     int sock_fd;
00252 #endif
00253 };
00254 
00262 class UDPReceiver: public Receiver {
00263 public:
00279                         UDPReceiver(in_port_t p, 
00280                                     const char * hostname = NULL, 
00281                                     bool reuse = true);
00282 
00283     virtual size_t      receive(char *, size_t) throw (CommException);
00284     virtual void        shutdown();
00285 
00286     virtual string      uri();
00287     virtual string &    uri(string &);
00288 
00289 private:
00290     in_port_t port;
00291     string _uri;
00292 #ifdef USING_WIN32
00293     SOCKET sock_fd;
00294 #else
00295     int sock_fd;
00296 #endif
00297 };
00298 
00299 #ifndef NO_INLINE
00300 #include <siena/Comm.icc>
00301 #endif
00302 
00303 #ifdef HAVE_CXX_NAMESPACE
00304 }; // namespace Siena
00305 #endif
00306 
00307 #endif

Copyright © 2001 University of Colorado.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". This documentation is authored and maintained by Antonio Carzaniga