Siena C++ API Documentation
Author: Antonio Carzaniga

Siena C++ API documentation (v. 0.4.3)

- Main Page
- Classes
- Files
- 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.1 2003/07/09 20:17:31 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 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 /* default */);
    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 }; // namespace Siena
    00301 #endif
    00302
    00303 #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