![]() |
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * Hostname resolver object * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 *********************************************************************************/ 00022 #ifndef FXRESOLVER_H 00023 #define FXRESOLVER_H 00024 00025 #ifndef FXTHREAD_H 00026 #include "FXThread.h" 00027 using namespace FX; 00028 #endif 00029 namespace FXEX { 00030 class FXFastMutex; 00031 00032 /** 00033 * FXResolver is designed to resolve hostnames synchronously or asychronously, so that the 00034 * application can choose whether it wants to wait for resolution to finish, before returning 00035 * or whether to wait for the SEL_COMMAND to be sent to indicate if the resolution has finished. 00036 * 00037 * The resolver defaults to resolving IPv4 addresses, but can be made to lookup IPv6 addresses. 00038 * The default socket type used in the lookup, is any type (ie stream or datagram). 00039 * 00040 * The class implements a non-threaded lookup of hostnames which correspond to the current 00041 * machine. This is to reduce the overhead with the lookup, since a blocking lookup should be 00042 * quick for most machines that have some form of network stack. 00043 */ 00044 class FXAPI FXResolver : public FXThread { 00045 FXDECLARE (FXResolver) 00046 00047 protected: 00048 FXString hostname; // host to lookup 00049 FXString officialname; // canonomical name of resolved host 00050 FXSocketFamily family; // prefered socket family - defaults to any 00051 FXSocketType type; // prefered socket type - defaults to any 00052 FXint code; // status code of lookup 00053 void *sock_addr; // socket address structure 00054 FXFastMutex *fastmutex; // resource lock 00055 00056 protected: 00057 /// serialisation 00058 FXResolver(); 00059 00060 /// worker thread implementation 00061 void run(); 00062 00063 public: 00064 enum { 00065 ID_RESOLVER=FXThread::ID_LAST, 00066 ID_LAST 00067 }; 00068 00069 public: 00070 long onCmdSetValue(FXObject*,FXSelector,void*); 00071 long onCmdSetStringValue(FXObject*,FXSelector,void*); 00072 long onCmdGetStringValue(FXObject*,FXSelector,void*); 00073 00074 public: 00075 /// Just supply the target and selector (de-serialisation too) 00076 FXResolver(const FXString& host,FXObject *tgt=NULL,FXSelector sel=0); 00077 00078 /// get status last hostname lookup 00079 FXint status(); 00080 00081 /// indicates if we have resolved the hostname 00082 FXbool resolved(); 00083 00084 /// set resolver to new host name 00085 void host(const FXString& h); 00086 00087 /// get currently resolving host name 00088 FXString host() const { return hostname; } 00089 00090 /// get the official/canonomical hostname of the resolved name 00091 FXString officialName(); 00092 00093 /** 00094 * Tell resolver to resolve the host info 00095 * - handle a SEL_COMMAND event, ptr contains a pointer to the 00096 * array of returned addrinfo structures 00097 */ 00098 void resolve(); 00099 00100 /// resolve using a blocking implementation 00101 FXbool blockingResolve(); 00102 00103 /** 00104 * return reference to last looked up resolved hostname 00105 * as a socket address struct (ie you need to cast it) 00106 */ 00107 void* socket_address_struct(); 00108 00109 /** 00110 * Set the family of the conection type 00111 * ie you can set it to one of FXSocketFamilyInet6 or FXSocketFamilyInet 00112 */ 00113 void setFamily(FXSocketFamily family); 00114 00115 /// return the prefered socket family 00116 FXSocketFamily getFamily(); 00117 00118 /// set the prefered socket type 00119 void setType(FXSocketType type); 00120 00121 /// get the currently prefered socket type 00122 FXSocketType getType(); 00123 00124 /// dtor 00125 virtual ~FXResolver(); 00126 }; 00127 00128 } // namespace FXEX 00129 #endif // FXRESOLVER_H 00130