ReadFile(http::) not working after rek dirscan
BlitzMax Forums/BlitzMax Beginners Area/ReadFile(http::) not working after rek dirscan
| ||
Hello altogether, I'm dealing with that problem for over a week and think cut it now down to the bug itself. The code posted below works fine. If you call the function rekdir before trying to access HTTP, the connection to localhost (and any other websites) doesn't work. If you then again commend the recursive call itself in the function everything is okay again. Calling GCCollect() doesn't help either. Here's the code: 'Just scanning a folder recursively rekdir("/Users/simonheimbach/Blitz/") 'Comment this and everything's okay 'Connecting to localhost (any other website doesn't work as well) even though browser shows website correctly file=ReadFile("http::localhost/") 'Replacing with ReadStream() doesn't make a different If file Repeat Print ReadLine(file) Until Eof(file) CloseFile(file) Else Print "couldn't establish connection..." EndIf Function rekdir(path$) dir=ReadDir(path$) If Not dir Then Return NextFile(dir) NextFile(dir) Repeat fil$=NextFile(dir) If fil$=""Then Return Print path$+"/"+fil$ If FileType(path$+"/"+fil$)=2 Then rekdir(path$+"/"+fil$) 'Commend this and everything is fine again Forever End Function I am very, very confused. Now after having written that topic my programme and the example are behaving exactly the way I want them to. Can't believe it... Am I getting mad? [EDIT] Okay, now a few hours later, wanting to continue working on the code, it doesn't work again. Can't see any logic behind it - but at least I am now sure, that I didn't go mad :). |
| ||
Try rekdir on a smaller folder and see what happens, I have tried your code above with "http::google.com/" as the ReadFile address, and "F:/Test/" as the rekdir folder and the code functions fine, I get a print out of the folder hierarchy and retrieved page data. |
| ||
If you ReadDir(), you should also CloseDir(). Otherwise you will most likely run out of file handles. |
| ||
@Flemmonk: So do you think it can be a solution to just save all files of my programme in a textfile and not ro scan the folder? Hmm... could be an approach until I found out, what it really is about. I'll try it out the weekend. @Brucey: Stupid me. Forgot it in my example. Nevertheless I have the same problem in my main programme, even though I do close the dir-handles. Do you think something's wrong with the code? Or is this a problem of BlitzMax or even the Mac-kernel? If so, I would ask in the apples developer forum to see, if anybody knows about a bug. Maybe I try a similar programme in C++... |
| ||
Indeed, your example doesn't work, as is. As I suggested, the issue is to do with file handles (or lack of them!). Stepping through the code, when it eventually attempts to create a TCP connection, the function simply returns Null, so the request for the URL never happens. Any time you call ReadDir(), you *need* to have a CloseDir() - if ReadDir() has previously returned a valid file handle. If you re-examine your code, you'll see your mistake. |
| ||
|
| ||
@Brucey: Sorry. I just found, that I really missed to close the handles. @REDi: Works! At least I could establish a connection after having scanned a huge folder. Will work with that until the problem ist solved. Thank you! |