Annotation of fam/fam/RPC_TCP_Connector.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 RPC_TCP_Connector_included
! 24: #define RPC_TCP_Connector_included
! 25:
! 26: #include <sys/types.h>
! 27: #include <netinet/in.h>
! 28:
! 29: #include "Boolean.h"
! 30:
! 31: // An RPC_TCP_Connector is an object that connects to a server.
! 32: // Specifically, a service registered with portmapper that uses
! 33: // TCP/IP.
! 34: //
! 35: // The destination host, program, and version are specified when the
! 36: // R.T.Connector is created.
! 37: //
! 38: // An R.T.Connector, when activated, tries repeatedly to connect,
! 39: // first to portmapper, then to the server itself. It keeps trying
! 40: // until it succeeds, it is deactivated, or it is destroyed. When it
! 41: // succeeds, it calls its ConnectHandler.
! 42: //
! 43: // An R.T.Connector is inactive when it's created.
! 44: //
! 45: // The R.T.Connector uses an exponentially increasing timeout. I.e.,
! 46: // if its first attempt fails, it waits one second and tries again.
! 47: // If the second attempt fails, it waits two seconds. Then it waits
! 48: // four seconds. Then eight. Et cetera, up to a maximum of 1024
! 49: // seconds (~17 minutes).
! 50:
! 51: class RPC_TCP_Connector {
! 52:
! 53: public:
! 54:
! 55: typedef void (*ConnectHandler)(int fd, void *closure);
! 56:
! 57: RPC_TCP_Connector(unsigned long program,
! 58: unsigned long version,
! 59: unsigned long host,
! 60: ConnectHandler,
! 61: void *closure);
! 62: ~RPC_TCP_Connector();
! 63:
! 64: bool active() { return state != IDLE; }
! 65: void activate();
! 66: void deactivate();
! 67:
! 68: private:
! 69:
! 70: enum { PMAP_TIMEOUT = 60 }; // seconds
! 71: enum { INITIAL_RETRY_INTERVAL = 1, MAX_RETRY_INTERVAL = 1024 }; // seconds
! 72: enum State { IDLE, PMAPPING, CONNECTING, PAUSING };
! 73:
! 74: // Instance Variables
! 75:
! 76: State state;
! 77: int sockfd;
! 78: sockaddr_in address;
! 79: unsigned long program;
! 80: unsigned long version;
! 81: int retry_interval;
! 82: const ConnectHandler connect_handler;
! 83: void *closure;
! 84:
! 85: // Private Instance Methods
! 86:
! 87: void try_to_connect();
! 88: void try_again();
! 89:
! 90: // Class Methods
! 91:
! 92: static void retry_task(void *closure);
! 93: static void write_handler(int fd, void *closure);
! 94:
! 95: };
! 96:
! 97: #endif /* !RPCTCPConnector_included */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>