Changeset 6072 for branches/newapi
- Timestamp:
- 02/24/08 20:08:51 (9 months ago)
- Location:
- branches/newapi/licq/src/event
- Files:
-
- 3 modified
-
descriptorset.cpp (modified) (2 diffs)
-
descriptorset.h (modified) (1 diff)
-
test/descriptorsettest.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/newapi/licq/src/event/descriptorset.cpp
r5739 r6072 22 22 23 23 #include <cassert> 24 #include <cerrno> 24 25 #include <cstring> 26 #include <fcntl.h> 27 #include <unistd.h> 28 29 /** 30 * @returns True if @a fd is a valid (open) file descriptor; otherwise 31 * false. 32 */ 33 static bool isValidFd(int fd) 34 { 35 if (::fcntl(fd, F_GETFD) == -1 && errno == EBADF) 36 return false; 37 38 return true; 39 } 25 40 26 41 LicqDaemon::DescriptorSet::DescriptorSet(Licq::EventLoop::NotifierType type) … … 86 101 } 87 102 103 void LicqDaemon::DescriptorSet::removeBadDescriptors() 104 { 105 for (Descriptors::iterator it = myDescriptors.begin(); 106 it != myDescriptors.end(); ++it) 107 { 108 if (!isValidFd((*it)->fd)) 109 removeDescriptor((*it)->fd); 110 } 111 } 112 88 113 int LicqDaemon::DescriptorSet::getFdSet(fd_set* fdSet) 89 114 { -
branches/newapi/licq/src/event/descriptorset.h
r5739 r6072 37 37 void addDescriptor(int fd, Licq::EventLoop::Handler* handler); 38 38 void removeDescriptor(int fd); 39 void removeBadDescriptors(); 39 40 40 41 int getFdSet(fd_set* fdSet); -
branches/newapi/licq/src/event/test/descriptorsettest.cpp
r5907 r6072 48 48 BOOST_AUTO_TEST_CASE(simple) 49 49 { 50 reset(); 51 50 52 LicqDaemon::DescriptorSet set(Licq::EventLoop::Read); 51 53 … … 69 71 } 70 72 73 BOOST_AUTO_TEST_CASE(badfd) 74 { 75 reset(); 76 77 LicqDaemon::DescriptorSet set(Licq::EventLoop::Read); 78 79 fd_set fds; 80 int maxFd; 81 82 { 83 LicqDaemon::Pipe pipe("test");; 84 85 set.addDescriptor(pipe.getReadFd(), this); 86 maxFd = set.getFdSet(&fds); 87 BOOST_CHECK_EQUAL(maxFd, pipe.getReadFd()); 88 89 set.removeBadDescriptors(); 90 maxFd = set.getFdSet(&fds); 91 BOOST_CHECK_EQUAL(maxFd, pipe.getReadFd()); 92 } 93 94 set.removeBadDescriptors(); 95 maxFd = set.getFdSet(&fds); 96 BOOST_CHECK_EQUAL(maxFd, -1); 97 } 98 71 99 BOOST_AUTO_TEST_SUITE_END()
