[BACK]Return to ServerHost.h CVS log [TXT][DIR] Up to [Development] / fam / fam

Annotation of fam/fam/ServerHost.h, Revision 1.1

1.1     ! trev        1: //  Copyright (C) 1999 Silicon Graphics, Inc.  All Rights Reserved.
        !             2: //
        !             3: //  This program is free software; you can redistribute it and/or modify it
        !             4: //  under the terms of version 2 of the GNU General Public License as
        !             5: //  published by the Free Software Foundation.
        !             6: //
        !             7: //  This program is distributed in the hope that it would be useful, but
        !             8: //  WITHOUT ANY WARRANTY; without even the implied warranty of
        !             9: //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  Further, any
        !            10: //  license provided herein, whether implied or otherwise, is limited to
        !            11: //  this program in accordance with the express provisions of the GNU
        !            12: //  General Public License.  Patent licenses, if any, provided herein do not
        !            13: //  apply to combinations of this program with other product or programs, or
        !            14: //  any other product whatsoever.  This program is distributed without any
        !            15: //  warranty that the program is delivered free of the rightful claim of any
        !            16: //  third person by way of infringement or the like.  See the GNU General
        !            17: //  Public License for more details.
        !            18: //
        !            19: //  You should have received a copy of the GNU General Public License along
        !            20: //  with this program; if not, write the Free Software Foundation, Inc., 59
        !            21: //  Temple Place - Suite 330, Boston MA 02111-1307, USA.
        !            22:
        !            23: #ifndef ServerHost_included
        !            24: #define ServerHost_included
        !            25:
        !            26: #include <limits.h>
        !            27: #include "Boolean.h"
        !            28: #include "ClientInterest.h"
        !            29: #include "RequestMap.h"
        !            30: #include "RPC_TCP_Connector.h"
        !            31: struct hostent;
        !            32: class ServerConnection;
        !            33:
        !            34: //  ServerHost represents an NFS-server host.  A ServerHost tries to
        !            35: //  talk to remote fam.  If it succeeds, it relies on remote fam to
        !            36: //  monitor files that reside on that host.  If it can't talk to fam,
        !            37: //  it polls the files of interest.
        !            38: //
        !            39: //  send_monitor() et al are used to tell the ServerHost what files
        !            40: //  are being monitored.  If we have a connection to a remote fam,
        !            41: //  we send the appropriate message.
        !            42: //
        !            43: //  When a file is monitored, a request number is allocated for it,
        !            44: //  and it is added to a RequestMap.  When it's cancelled, it's
        !            45: //  removed from the RequestMap.
        !            46: //
        !            47: //  A ServerHost is "active" if we're monitoring at least one file on
        !            48: //  that host.  The ServerHost starts trying to connect to remote fam
        !            49: //  when it becomes active.  When it becomes inactive, it starts a
        !            50: //  timer; if it stays inactive for three seconds, it disconnects from
        !            51: //  remote fam.
        !            52: //
        !            53: //  So a ServerHost can be "active" but not "connected": there is no
        !            54: //  remote fam or its connection hasn't come up yet.  A ServerHost can
        !            55: //  also be "connected" but not "active": its connection is timing
        !            56: //  out.
        !            57: //
        !            58: //  Unfortunately, the kernel's NFS attribute cache gets in fam's way.
        !            59: //  If we scan a file within n seconds of someone else scanning the
        !            60: //  same file (n defaults to 3), then we get stale information from
        !            61: //  the cache.  So we scan the file immediately, just in case the
        !            62: //  cache won't bite us, then we put the file into a queue of files to
        !            63: //  rescan n seconds later, the deferred scan queue.
        !            64:
        !            65: class ServerHost {
        !            66:
        !            67: public:
        !            68:
        !            69:     bool is_connected() const	{ return connection != 0; }
        !            70:     const char *name() const		{ return myname; }
        !            71:
        !            72:     Request send_monitor(ClientInterest *, ClientInterest::Type,
        !            73: 			 const char *remote_path);
        !            74:     void send_cancel(Request);
        !            75:     void send_suspend(Request);
        !            76:     void send_resume(Request);
        !            77:
        !            78:     void poll();
        !            79:
        !            80: private:
        !            81:
        !            82:     //  A DeferredScan is the info needed to rescan an Interest after
        !            83:     //  several seconds' delay.  The delay is needed to let the NFS
        !            84:     //  attribute cache go stale.
        !            85:
        !            86:     class DeferredScan {
        !            87:
        !            88:     public:
        !            89:
        !            90: 	inline DeferredScan(int then, int retries, Request = 0, const char * = 0);
        !            91:
        !            92: 	operator int ()			{ return myrequest != 0; }
        !            93:
        !            94: 	Request request() const		{ return myrequest; }
        !            95: 	const char *path() const	{ return mypath[0] ? mypath : NULL; }
        !            96:
        !            97: 	int when;  //  absolute time, in seconds
        !            98:         int retries;  // how many times to try
        !            99: 	class DeferredScan *next;
        !           100:
        !           101:     private:
        !           102:
        !           103: 	Request myrequest;
        !           104: 	char mypath[NAME_MAX];
        !           105:
        !           106:     };
        !           107:
        !           108:     //  Instance Variables
        !           109:
        !           110:     enum {RETRY_INTERVAL = 10};
        !           111:
        !           112:     unsigned refcount;
        !           113:     char *myname;
        !           114:     RPC_TCP_Connector connector;
        !           115:     ServerConnection *connection;
        !           116:     Request unique_request;
        !           117:     RequestMap requests;
        !           118:     DeferredScan *deferred_scans;
        !           119:     DeferredScan *last;
        !           120:     int min_time;
        !           121:
        !           122:     //  Private Instance Methods
        !           123:
        !           124:     ServerHost(const hostent&);
        !           125:     ~ServerHost();
        !           126:     bool active()			{ return requests.size() != 0; }
        !           127:     void activate();
        !           128:     void deactivate();
        !           129:     void defer_scan(int when, int retries, Request r , const char * path);
        !           130:
        !           131:     //  Class Methods
        !           132:
        !           133:     static void connect_handler(int fd, void *);
        !           134:     static void disconnect_handler(void *);
        !           135:
        !           136:     static void event_handler(const Event*, Request, const char *, void *);
        !           137:     static void deferred_scan_task(void *);
        !           138:     static void timeout_task(void *);
        !           139:
        !           140:     ServerHost(const ServerHost&);	// Do not copy
        !           141:     ServerHost & operator = (const ServerHost&);	//  or assign.
        !           142:
        !           143: friend class ServerHostRef;
        !           144:
        !           145: };
        !           146:
        !           147: #endif /* !ServerHost_included */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>