Parameter ATimeout of IdTCPConnection.ReadLn |
尚未結案
|
stickyworm
一般會員 發表:2 回覆:2 積分:0 註冊:2003-05-06 發送簡訊給我 |
I used the following code in my program to check if there's anything sent through the connection: IdTCPClient: TIdTCPClient;
...
msg := IdTCPClient.ReadLn(#0, 5); ReadLn should return an empty string ('') if the peer connection is prematurely closed or a time-out occurs(after 5 millisecond as I set it). But my program simply died there, which made me quite confused. Thanks a lot for helping.
LOOP
i cant say goodbye
------
LOOP i cant say goodbye |
wnhoo
高階會員 發表:75 回覆:443 積分:198 註冊:2003-04-22 發送簡訊給我 |
|
stickyworm
一般會員 發表:2 回覆:2 積分:0 註冊:2003-05-06 發送簡訊給我 |
Well yes, by using ShowMessage(IdTCPClient.ReadLn), a Read Timeout message will show up when there's nothing to read. But can you just tell me how to specify a custom time-out value instead of the default one? Whenever I try to do so by specifying a ATimeout parameter, my program dies and fails to show up any message. Thanks again. ^^) LOOP
i cant say goodbye
------
LOOP i cant say goodbye |
stickyworm
一般會員 發表:2 回覆:2 積分:0 註冊:2003-05-06 發送簡訊給我 |
Oops, I discovered a bug in the TIdTCPConnection component. In its ReadFromStack, if a timeout occurs, an EIdReadTimeout exception will be raised when ARaiseExceptionOnTimeout is True. Otherwise ReadFromStack performs no additional processing, and uses -1 as the return value for the method.
What I want is just the latter. As we all know, the ReadLn method uses the ReadFromStack method, when we specify a custom time-out value in ReadLn, if a time-out occurs, ReadLn will not raise an exception but return an empty string. But that was where my program died dramatically. So I viewed the source code of TIdTCPConnection.ReadLn, and discovered that it mistook the return value -1 of ReadFromStack for 0.
After modification it works fine now. LOOP
i cant say goodbye
------
LOOP i cant say goodbye |
Ktop_Robot
站務副站長 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |