Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

SocketModule.h

00001 #ifndef _STR_SocketModule_H_  // -*-c++-*-
00002 
00003 /*
00004  * Copyright 1991-2002 Eric M. Hopper <hopper@omnifarious.org>
00005  * 
00006  *     This program is free software; you can redistribute it and/or modify it
00007  *     under the terms of the GNU Lesser General Public License as published
00008  *     by 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, but
00012  *     WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *     Lesser General Public License for more details.
00015  * 
00016  *     You should have received a copy of the GNU Lesser General Public
00017  *     License along with this program; if not, write to the Free Software
00018  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifdef __GNUG__
00022 #  pragma interface
00023 #endif
00024 
00025 /* $Header: /home/hopper/src/cvs/C++/StrMod/StrMod/SocketModule.h,v 1.12 2002/08/29 00:58:04 hopper Exp $ */
00026 
00027 // See ../ChangeLog for a change log.
00028 
00029 #include <EHnet++/SocketAddress.h>
00030 
00031 #ifndef _STR_StreamFDModule_H_
00032 #  include <StrMod/StreamFDModule.h>
00033 #endif
00034 
00035 #define _STR_SocketModule_H_
00036 
00037 namespace strmod {
00038 namespace strmod {
00039 
00040 class SockListenModule;
00041 
00042 class SocketModule : public StreamFDModule
00043 {
00044    friend class SockListenModule;  // This is so SockListenModule's can access
00045                                    // that one protected constructor down there
00046  public:
00047    static const STR_ClassIdent identifier;
00048 
00049    //! Create a SocketModule connected to the given address.
00050    SocketModule(const ehnet::SocketAddress &addr,
00051                 unievent::Dispatcher &disp,
00052                 unievent::UnixEventRegistry &ureg,
00053                 bool blockconnect = true) throw(unievent::UNIXError);
00054    virtual ~SocketModule();
00055 
00056    inline virtual int AreYouA(const lcore::ClassIdent &cid) const;
00057 
00058    //: Who are we connected to?
00059    const ehnet::SocketAddress &GetPeerAddr()           { return(peer_); }
00060 
00061  protected:
00062    virtual void writeEOF();
00063 
00064    /** Create a SocketModule using the given fd.
00065     * Note that ownership of peer is being passed.
00066     */
00067    SocketModule(int fd, ehnet::SocketAddress *peer,
00068                 unievent::Dispatcher &disp,
00069                 unievent::UnixEventRegistry &ureg);
00070 
00071    virtual const lcore::ClassIdent *i_GetIdent() const  { return &identifier; }
00072 
00073    static int MakeSocket(SocketModule &obj, const ehnet::SocketAddress &addr,
00074                          bool blockconnect) throw(unievent::UNIXError);
00075 
00076  private:
00077    ehnet::SocketAddress &peer_;
00078 };
00079 
00080 //-------------------------------inline functions------------------------------
00081 
00082 inline int SocketModule::AreYouA(const lcore::ClassIdent &cid) const
00083 {
00084    return((identifier == cid) || StreamFDModule::AreYouA(cid));
00085 }
00086 
00087 };  // namespace strmod
00088 };  // namespace strmod
00089 
00090 #endif

Generated on Wed Jan 29 00:32:44 2003 for libNet by doxygen1.3-rc1