Changeset 1903
- Timestamp:
- 03/11/2007 18:29:37 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/infrastructure/buildenv-testmain-template.cpp
r1699 r1903 65 65 66 66 // any way to check for open file descriptors on Win32? 67 inline int count_filedes(){ return 0; }68 inline bool checkfilesleftopen() { return false; }67 inline bool check_filedes(bool x) { return 0; } 68 inline bool checkfilesleftopen() { return false; } 69 69 70 70 #else // !WIN32 71 71 72 int count_filedes() 72 #define FILEDES_MAX 256 73 74 bool filedes_open[FILEDES_MAX]; 75 76 bool check_filedes(bool report) 73 77 { 74 int c = 0;78 bool allOk = true; 75 79 76 80 // See how many file descriptors there are with values < 256 77 for(int d = 0; d < 256; ++d)81 for(int d = 0; d < FILEDES_MAX; ++d) 78 82 { 79 83 if(::fcntl(d, F_GETFD) != -1) 80 84 { 81 85 // File descriptor obviously exists 82 ++c; 83 } 84 } 86 if (report && !filedes_open[d]) 87 { 88 struct stat st; 89 if (fstat(d, &st) == 0) 90 { 91 int m = st.st_mode; 92 #define flag(x) ((m & x) ? #x " " : "") 93 BOX_FATAL("File descriptor " << d << 94 " left open (type == " << 95 flag(S_IFIFO) << 96 flag(S_IFCHR) << 97 flag(S_IFDIR) << 98 flag(S_IFBLK) << 99 flag(S_IFREG) << 100 flag(S_IFLNK) << 101 flag(S_IFSOCK) << 102 flag(S_IFWHT) << " plus " << m << ")"); 103 } 104 else 105 { 106 BOX_FATAL("File descriptor " << d << 107 " left open (and stat failed)"); 108 } 85 109 86 return c; 110 allOk = false; 111 112 } 113 else if (!report) 114 { 115 filedes_open[d] = true; 116 } 117 } 118 else 119 { 120 if (report && filedes_open[d]) 121 { 122 BOX_FATAL("File descriptor " << d << 123 " was open, now closed"); 124 allOk = false; 125 } 126 else 127 { 128 filedes_open[d] = false; 129 } 130 } 131 } 132 133 if (!report && allOk) 134 { 135 filedes_open_at_beginning = 0; 136 } 137 138 return !allOk; 87 139 } 88 140 … … 93 145 // Not used correctly, pretend that there were things 94 146 // left open so this gets investigated 147 BOX_FATAL("File descriptor test was not initialised"); 95 148 return true; 96 149 } … … 100 153 101 154 // Count the file descriptors open 102 return filedes_open_at_beginning != count_filedes();155 return check_filedes(true); 103 156 } 104 157 … … 177 230 { 178 231 // Count open file descriptors for a very crude "files left open" test 179 filedes_open_at_beginning = count_filedes();232 check_filedes(false); 180 233 181 234 // banner
Note: See TracChangeset
for help on using the changeset viewer.
