From: Erick <er...@je...> - 2001-04-06 11:06:28
|
Harald said: | 1) instead of close, move the file pointer to eof | seek FILE, 0, 2; | so that the read fails without dying This can't be, because the reading is from a socket not a file. I'm reading from a socket and writting to a file (in blocks of 10240 bytes). The read does stop when I abort. This method would certainly be good if I was reading from one file and ouptting to another. | or 2) just set a flag in the abort routine and if the reading routine finds | the flag set, it peacefully quits. The abort routine is not my method, furthermore it does not take any arguments, it just closes the socket and thus all data transfering. The problem I believe is because since my application is GUI and event driven(OOP), any action one place jumps you to another section of code, without knowing how to get back and say, "hey stop doing that, move on". Does this make sense? erick never stop questioning www.jeb.ca | Hi Erick, | | 1) instead of close, move the file pointer to eof | seek FILE, 0, 2; | so that the read fails without dying | | or 2) just set a flag in the abort routine and if the reading routine finds | the flag set, it peacefully quits. | | Hope that helps | Harald | | -----Original Message----- | From: Erick J. Bourgeois | To: per...@li... | Sent: 03.04.01 17:04 | Subject: [perl-win32-gui-users] Aborting a buffered write | | I have a process running, which is writting to a file(using print | instead of syswrite), | and I have a small dialogbox with a progressbar and an abort button. The | problem is when I | click the abort button, I get a GUI message "select: Bad file descriptor | at ... line 412". | This is the line where I read the data in, however, the event for the | Abort button closes | the data stream and the file I'm writting to. Plus the title for the | window error is a | subroutine which was a far ancestor to where it says the error is. This | is what the | Abort_Click looks like. | | sub Abort_Click { | close(FILE); | $data->abort(); | $ProgWin->Hide(); # <--progress dialogbox window | $MainWin->SetForegroundWindow(); | $MainWin->BringWindowToTop(); | GUI::Update($MainWin); | } | | I need a way tell the subroutine that is showing the progress to stop | reading data and | move on. Any ideas? | | erick | never stop questioning | www.jeb.ca | | | _______________________________________________ | Perl-Win32-GUI-Users mailing list | Per...@li... | http://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users | |
From: Piske, H. <Har...@bo...> - 2001-04-06 16:15:33
|
| The problem I believe is because since my application is GUI | and event driven(OOP), any | action one place jumps you to another section of code, | without knowing how to get back and | say, "hey stop doing that, move on". Does this make sense? I guess you're right, it is about multitasking. Reading from the socket places an asynchronous request somewhere. As data comes in, it gets stored in an input buffer. If the Abort routine intervenes and invalidates $data, the next read finds an invalid pointer or, worse, a pointer to an invalid buffer. If this theory is correct, then there is really no other way than to move the $data->abort() in the thread that reads from the socket, so that these two commands can never execute concurrently. If anyone knows more about the internal operations of the sockets driver, please stop me from making these wild assumptions ... :-) Have fun Harald |
From: Erick <er...@je...> - 2001-04-06 22:01:14
|
Harald, | If the Abort routine intervenes and invalidates $data, | the next read finds an invalid pointer or, worse, a pointer to an invalid | buffer. That's the key thing. How to stop the routine from reading data once and for all. Even when I close the connection between the two handles it continues to read. | If this theory is correct, then there is really no other way than to | move the $data->abort() in the thread that reads from the socket, so that | these two commands can never execute concurrently. Maybe you are a bit confused. There are two abort routines. One fired by the button being pressed and the other to close the socket. Here is the loop that reads and writes the data from the socket. # Open a socket for retrieval # $data = $sock->retr($RemoteFile); while(1) { Win32::GUI::DoEvents(); last unless $len = $data->read($buffer,$blksize); my $written = syswrite(FILE, $buffer, $len); unless(defined($written) && $written == $len) { Msg_Box("Cannot write to local file $LocalFile: $!",48,"Can't Write To File"); $data->abort; close(FILE); return undef; } } Then I have a window which displays the progress with an "Abort" button, which I already gave the code. I need to exit this loop once and for all, once the connection has been closed. The answer is there...just gotta find it...someone...anyone. regards, erick never stop questioning www.jeb.ca |