00001 #ifndef CONNECTION_CLASS 00002 #define CONNECTION_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : connection * 00007 * Author : Chris Koeritz * 00008 * * 00009 * Purpose: * 00010 * * 00011 * A structure that represents the state of a communication pathway between * 00012 * two transports. This header should never appear in another header; it is * 00013 * heavyweight and intended for code files (*.cpp) only. * 00014 * * 00015 ******************************************************************************* 00016 * Copyright (c) 1992-$now By Author. This program is free software; you can * 00017 * redistribute it and/or modify it under the terms of the GNU General Public * 00018 * License as published by the Free Software Foundation; either version 2 of * 00019 * the License or (at your option) any later version. This is online at: * 00020 * http://www.fsf.org/copyleft/gpl.html * 00021 * Please send any updates to: fred@gruntose.com * 00022 \*****************************************************************************/ 00023 00024 #include "connections_dll.h" 00025 00026 #include <mechanisms/heartbeat.h> 00027 #include <mechanisms/time_stamp.h> 00028 #include <nodes/catalogable.h> 00029 #include <sockets/address.h> 00030 #include <sockets/definitions_sockets.h> 00031 00032 class CONNECTIONS_CLASS_STYLE connection : public nodes::catalogable 00033 { 00034 public: 00035 connection(); 00036 ~connection() {} 00037 00038 // these are the various connection states. 00039 enum states { 00040 DISCONNECTED, // not connected or totally finished disconnecting. 00041 AWAITING_A_CLIENT, // a server awaiting a connection from a client. 00042 REACHING_SERVER, // client is awaiting a connection to the server. 00043 WHO_IS_CLIENT, // server doesn't know who connection is from yet. 00044 HELLO_TO_SERVER, // client not connected yet, but working on it. 00045 CONNECTED, // finished with connection process. 00046 SENDING_CLOSE, // working on disconnecting the connection. 00047 SENDING_CLOSE_ACK, // tells other side that their disconnect was okay. 00048 DONE_CLOSING // finished disconnecting. 00049 }; 00050 00051 static const char *connection_state_name(states state); 00052 // provides a textual form for the "state". 00053 00055 00056 // ugly public data. perhaps encapsulate as a class. 00057 00058 // used for the low-level ids. 00059 #define PRIMARY_ID 0 00060 #define SECONDARY_ID 1 00061 00062 // these are known after first bits are added to the table: 00063 transport_id local_transport_id; // the linked transport on our side. 00064 transport_id real_transport_id; // the real transport on our side. 00065 00066 // these are known at the time of connection for everyone, we hope: 00067 network_address remote_host; // the name of the machine we're talking to. 00068 int low_level[2]; 00069 // connection id at the communication medium level. either it's identical 00070 // to the remote_transport_id or based on low-level medium details. 00071 00072 // these are known after connection intros exchanged: 00073 transport_id remote_transport_id; // the transport id on the other side. 00074 connection_id remote_connection_id; // the other side's name for us. 00075 00076 // these are just connection table bookkeeping info: 00077 bool alive; // reports if this connection entry is still alive or not. 00078 heartbeat liveness; // state of other side's healthiness. 00079 00081 00082 connection_id conn_id() const { return connection_id(id().raw_id()); } 00083 // returns the unique identifier for this connection. 00084 00085 // allows the connection id to be modified. 00086 void conn_id(const connection_id &new_id); 00087 00088 istring catalogable_name() const; 00089 // returns our name as a catalogable object. 00090 00091 istring text_form() const; 00092 // returns a textual form for this connection. 00093 00094 bool connected() const; 00095 // reports if this connection is actually considered alive. 00096 00097 time_stamp connected_since() const; 00098 // returns the time that this connection has been in a connected state. 00099 // this is only valid if the current state is CONNECTED. 00100 00101 states state() const; 00102 // returns the current connection state. 00103 void state(states to_set); 00104 // makes "to_set" the current state for this connection. this also updates 00105 // the time stamp of last_state_change() regardless of the new state. 00106 // in addition, if the previous state was not CONNECTED and "to_set" is 00107 // CONNECTED, then the connected_since() time_stamp is reset. 00108 00109 time_stamp last_state_change() const; 00110 // returns the last time that the state changed. 00111 00112 private: 00113 states _the_state; 00114 // describes the current state of the connection. 00115 time_stamp _state_change_time; 00116 // the last time the state of the connection was modified. 00117 time_stamp _connected_since; 00118 // tracks how long the current connection has lasted. this is only valid 00119 // if the current state is CONNECTED. 00120 }; 00121 00122 #endif 00123
1.5.1