/home/vlg/develop/libASSA/libassa/assa/FdSet.cpp

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //------------------------------------------------------------------------------
00003 //                               FdSet.cpp
00004 //------------------------------------------------------------------------------
00005 //  Copyright (C) 2006  Vladislav Grinchenko 
00006 //
00007 //  This library is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU Library General Public
00009 //  License as published by the Free Software Foundation; either
00010 //  version 2 of the License, or (at your option) any later version.
00011 //------------------------------------------------------------------------------
00012 
00013 #include "FdSet.h"
00014 #include "Logger.h"
00015 
00016 using namespace ASSA;
00017 
00018 bool
00019 FdSet::
00020 setFd (handler_t fd_) 
00021 { 
00022     FD_SET (fd_, this); 
00023 
00024 #if !defined (WIN32)
00025     ActiveFDs_Iter iter;
00026     iter = std::find (m_actfds.begin (), 
00027                       m_actfds.end (), 
00028                       fd_);
00029     if (iter == m_actfds.end ()) { // not found
00030         m_actfds.push_back (fd_);
00031     }
00032 #endif
00033 
00034     return true;
00035 }
00036 
00037 bool 
00038 FdSet::
00039 clear (handler_t fd_) 
00040 {
00041     DL ((REACT,"Clearing fd=%d\n", fd_));
00042 
00043     if (!isSet (fd_)) {
00044         DL ((REACT,"Not set! - ignoring.\n"));
00045         return false;
00046     }
00047 
00048     FD_CLR (fd_, this); 
00049     if (FD_ISSET (fd_, this)) {
00050         DL ((REACT,"Woop - an error! FD_CLR failed!\n"));
00051     }
00052 
00053 #if !defined (WIN32)
00054     ActiveFDs_Iter iter;
00055     iter = std::find (m_actfds.begin (), 
00056                       m_actfds.end (), 
00057                       fd_);
00058     if (iter != m_actfds.end ()) { 
00059         DL ((REACT,"fd=%d found and erased\n", fd_));
00060         m_actfds.erase (iter);
00061     }
00062     else {
00063         DL ((REACT,"fd=%d not found in m_actfds list!\n", fd_));
00064     }
00065 #endif
00066 
00067     return true;
00068 }
00069 
00070 void 
00071 FdSet::
00072 sync () 
00073 { 
00074 #if !defined (WIN32)
00075     ActiveFDs_Iter iter;
00076   restart:
00077     iter = m_actfds.begin ();
00078     while (iter != m_actfds.end ()) {
00079         if (!isSet (*iter)) {
00080             m_actfds.erase (iter);
00081             goto restart;
00082         }
00083         iter++;
00084     }
00085 #endif
00086 }
00087 
00088 void 
00089 FdSet::
00090 reset () 
00091 { 
00092     ::memset(this, 0, sizeof (fd_set)); 
00093 
00094 #if !defined (WIN32)
00095     m_actfds.clear ();
00096 #endif
00097 }
00098 
00099 std::string
00100 FdSet::
00101 dump_c_str ()
00102 {
00103     std::ostringstream report;
00104 
00105     report << " enabled=" << numSet ();
00106 
00107 #if defined (WIN32)
00108     if (this->fd_count) {
00109         report << " : ";
00110     }
00111     for (int i=0; i < this->fd_count; i++) {
00112         report << " " << this->fd_array[i];
00113     }
00114 #else /* UNIX */
00115     ActiveFDs_Iter iter = m_actfds.begin ();
00116     if (m_actfds.size ()) {
00117         report << " : ";
00118     }
00119     while (iter != m_actfds.end ()) {
00120         report << " " << (u_int)*iter;
00121         iter++;
00122     }
00123 #endif
00124 
00125     report << std::ends;
00126     return (report.str ());
00127 }
00128 

Generated on Sun Aug 13 15:08:00 2006 for libassa by  doxygen 1.4.6