Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

wvunixsocket.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  */ 
00006 #ifndef __WVUNIXSOCKET_H
00007 #define __WVUNIXSOCKET_H
00008 
00009 #include "wvfdstream.h"
00010 #include "wvaddr.h"
00011 
00012 class WvStreamList;
00013 class WvUnixListener;
00014 
00015 /**
00016  * WvStream-based Unix domain socket connection class.
00017  * 
00018  * Unlike WvTCPConn, WvUnixConn makes connections synchronously because either
00019  * the remote server is there, or it isn't.  For convenience, we'll just
00020  * ignore situations where it's a local server but still slow.
00021  * 
00022  * FIXME: support SOCK_DGRAM mode somehow.  This is a bit tricky since the
00023  * listener/connection separation doesn't make as much sense then.  I guess we
00024  * could just ignore the listener or something...
00025  * 
00026  * FIXME: use the weird credential-passing stuff to exchange pid, uid, and gid
00027  * with the remote end of the socket.  See the unix(7) man page.  This would
00028  * be very cool for authentication purposes.
00029  */
00030 class WvUnixConn : public WvFDStream
00031 {
00032     friend class WvUnixListener;
00033 protected:
00034     WvUnixAddr addr;
00035     
00036     /** connect an already-open socket (used by WvUnixListener) */
00037     WvUnixConn(int _fd, const WvUnixAddr &_addr);
00038     
00039 public:
00040     /** connect a new socket */
00041     WvUnixConn(const WvUnixAddr &_addr);
00042 
00043     virtual ~WvUnixConn();
00044     
00045     /**
00046      * the local address of this socket (ie. from getsockname())
00047      * really useful only for transparent proxies, but always available.
00048      * may be 0.0.0.0 if we did not bind explicitly!
00049      */
00050     const WvUnixAddr &localaddr() { return addr; }
00051     
00052     /**
00053      * return the remote address (source of all incoming packets),
00054      * which is a constant for any given connection.
00055      * This doesn't make much sense in Unix domain sockets, so we just
00056      * return localaddr() instead.
00057      */
00058     virtual const WvUnixAddr *src() const;
00059 };
00060 
00061 /** Server end of a Unix Sockets stream */
00062 class WvUnixListener : public WvFDStream
00063 {
00064 public:
00065     WvUnixListener(const WvUnixAddr &_addr, int create_mode);
00066     virtual ~WvUnixListener();
00067     
00068     virtual void close();
00069     
00070     /**
00071      * return a new WvUnixConn socket corresponding to a newly-accepted
00072      * connection.  If no connection is ready immediately, we wait for
00073      * one indefinitely.  You can use select(read=true) to check for a
00074      * waiting connection.
00075      */
00076     WvUnixConn *accept();
00077     
00078     /**
00079      * set a callback() function that automatically accepts new WvUnixConn
00080      * connections, assigning them their own callback function 'callfunc'
00081      * with parameter 'userdata.'  Pass list==NULL or define your own
00082      * own callback function to disable auto-accepting.
00083      *
00084      * Be careful not to accept() connections yourself if you do this,
00085      * or we may end up accept()ing twice, causing a hang the second time.
00086      */
00087     void auto_accept(WvStreamList *list,
00088                      WvStreamCallback callfunc = NULL, void *userdata = NULL);
00089 
00090     /**
00091      * these don't do anything, but they confuse the socket, so we'll
00092      * ignore them on purpose.
00093      */
00094     virtual size_t uread(void *buf, size_t len);
00095     virtual size_t uwrite(const void *buf, size_t len);
00096     
00097     /** src() is a bit of a misnomer, but it returns the socket address. */
00098     virtual const WvUnixAddr *src() const;
00099     
00100 protected:
00101     WvUnixAddr addr;
00102     bool bound_okay;
00103     WvStreamList *auto_list;
00104 
00105     WvStreamCallback auto_callback;
00106     void *auto_userdata;
00107 
00108     static void accept_callback(WvStream &s, void *userdata);
00109 };
00110 
00111 
00112 #endif // __WVUNIXSOCKET_H

Generated on Wed Dec 15 15:08:11 2004 for WvStreams by  doxygen 1.3.9.1