read or readcond problem after tcflush?

My system is Qnx6.1.0 setup in PIII 866MHz.

I have found a problem about serial communication program.

I have two process : rd1 and wr2 .
rd1 is (readcond)reading the serial port 1 circularly, (MIN =
100,TIME=0,TIMOUT=30)
wr2 is writing data to the serial port 2 circularly.
They all set the terminal attr cc[VFWD] = ‘$’.

I start the wr2 process first ,and after it send servral frame-data ,I
terminate it.
the screen display message :

./wr2

open file success
set term attribute success
send …: operator 2 snd data 0$
send …: operator 2 snd data 1$
send …: operator 2 snd data 2$
send …: operator 2 snd data 3$
send …: operator 2 snd data 4$


after that, I start the rd1 process .Before the first time reading the
serial ,It flush input
and output buffer in serial driver .So there is no data ,and the readcond
should return after the timeout expired .
the screen display message:

./rd1

open file success
term.c_cc[VFWD] =36
set term attribute success
reading …
read time out and there is no data to receive
reading …
read time out and there is no data to receive
reading …
read time out and there is no data to receive
reading …
read time out and there is no data to receive
reading …
read time out and there is no data to receive
reading …


But it return AT ONCE,and with zero return value.
and You should be noticed that the times it immediately return is
equal to the times which wr2 send a moment ago.
after that,it return only when the timeout expired normally.

And the same phenomena happen when I change the readcond() to read().

1.I think that there is no data,it should block before timeout expired ,but
it return at once.
I don’t know why?

2.to the function “readcond “,how to diff from whether the read operation
timeout expired,it changed some flag?







begin 666 Rd1.c
M+R]T97-T(’-E<FEA;”=S(’)E860L(’=R:71E"B\O<F5A9&EN9PHC:6YC;‘5D
M92 <W1D:6\N:#X*(VEN8VQU9&4@/’-Y<R]T>7!E<RYH/@HC:6YC;‘5D92
M<WES+W-T870N:#X*(VEN8VQU9&4@/&9C;G1L+F@^"B-I;F-L=61E(#QT97)M
M:6]S+F@^"B-I;F-L=61E(#QU;FES=&0N:#X*(VEN8VQU9&4@/’-T<FEN9RYH
M/@HC:6YC;'5D92 \97)R;F\N:#X*“G9O:60@<V5T7V-O;5]S=“AI;G0I.PH*
M:6YT(&UA:6XH0I[“B @(”!I;G0@9F0[“B @(”!I;G0@;&5N9W1H.PH@(" @
M8VAA<B!R8W9?8G5F6S(P,%T[“B @(”!C:&%R(’-N9%]B=69;,C P73L
(” @
M(&EN=”!I.PH@(” @“B @(”!L96YG=&@@/2 P.PH@(" @:68H*&9D/6]P96XH
M(B]D978O<V5R,2(L($]?4D174BDI(#T](“TQ2![“B @(” @(" @<’)I;G1F
M
”)T=‘E3,2!O<&5N(&5R<F]R7&XB3L(" @(" @("!E>&ET*#$I.PH@(" @
M?0H@(" @“B @(” @<V5T7V-O;5]S=“AF9"D[”@H@(" @=&-F;‘5S:“AF9"P@
M5$-)3T9,55-(3L"B @(”!W:&EL92@Q2![“B @(” @(" @<’)I;G1F")R
M96%D:6YG(“XN+B!<;B(I.PH)+R]-24X@5$E-12!424U/550@“B @( HO+R @
M(” @(” @:68H(“AL96YG=&@]<F5A9”@@9F0L<F-V7V)U9BPQ,# @2D,"D
M(" @(" @("!I9B@@&QE;F=T:#UR96%D8V]N9"@@9F0L<F-V7V)U9BPQ,# L
M,3 P+#,P+#,P
2 I/# I"B @(" @(" @>PH@(" @(" @(" @("!P<FEN=&8H
M(")4:&%T(&UE86YS.B E<UQN(BP@<W1R97)R;W(H(&5R<FYO2 I.PH@(" @
M(" @(" @("!P<FEN=&8H(G)E860@97)R;W)<;B(I.PH@(" @(" @(" @("!S
M;&5E<"@S
3L*(" @(" @(" @(" @8V]N=&EN=64[“B @(” @(" @?2 (" @
M(" @("!E;’-E(&EF
&QE;F=T:#T],“D*(” @(" @("![“B @(” @(" @(" @
M(’!R:6YT9B@B<F5A9"!T:6UE(&]U="!A;F0@=&AE<F4@:7,@;F@9&%T82!T
M;R!R96-E:79E7&XB3L(" @(" @("!]“B @(” @(" @96QS92!I9BAL96YG
M=&@@/B P7L"2 @("!P<FEN=&8H(G)E860@9G)O;2!S97)I86PZ(&QE;F=T
M:#TE9%QT("(L(&QE;F=T:“D[”@D@(" @<’)I;G1F*")C;VYT96YT(&ES(#HB
M3L"2 @("!F;W(H:3TP.VD;&5N9W1H.VDKRD"0EP<FEN=&8H(B5C(BQR
M8W9?8G5F6VE=3L"2 @("!P<FEN=&8H(EQN(BD[“B\J"2 @(”!S=’)C<‘DH
M<VYD7V)U9BPB<VYD(&9R;VT@82(I.PH)(" @(’-T<FYC870H<VYD7V)U9BQR
M8W9?8G5F+&QE;F=T:“D[(” “2 @(”!W<FET92AF9"QS;F1?8G5F+&QE;F=T
M:“MS=’)L96XH(G-N9”!F<F]M(&$B
2D[“BHO(” @(" @(‘T*(" @(‘T*( H@
M(" @(" @8VQO<V4H9F0I.PH@(" @(" @<F5T=7)N(# [(" @(" @( I]"@IV
M;VED(’-E=%]C;VU?<W0H:6YT(&9D0I[“B @(’-T<G5C=”!T97)M:6]S(‘1E
M<FT["B @(’-P965D7W0@<W!E960[“B @(’-P965D(#T@0CDV,# [”@H@(" @
M<’)I;G1F
")O<&5N(&9I;&4@<W5C8V5S<UQN(BD[“B @(”!I9BAT8V=E=&%T
M=’(H9F0L(“9T97)M2 (# I('L(” @(" @(" @(" @<’)I;G1F*")G970@
M<V5R:6%L(&%T=’)I8G5T92!E<G)O<EQN(BD[“B @(” @(" @(" @(&5X:70H
M,2D[“B @(”!]"@H@(" @=&5R;2YC7V-F;&%G(“8]('Y#4TE:13L*(” @(‘1E
M<FTN8U]C9FQA9R!/2!#4S@["@H)=&5R;2YC7V-C6U9&5T1=/2<D)SL*"0H)
M<’)I;G1F*")T97)M+F-?8V-;5D971%T@/25D7&XB+‘1E<FTN8U]C8UM61E=$
M72D[“B @(”!I9BAC9G-E=&ES<&5E9"@F=&5R;2P@<W!E960I(#T](“TQ2![
M"B @(" @(" @<’)I;G1F
”)S970@:6YP=70@8F%U9"!R871E(&5R<F]R7&XB
M3L(" @(" @("!E>&ET*#$I.PH@(" @?0H@(" @:68H8V9S971O<W!E960H
M)G1E<FTL(’-P965D2 ]/2 M,2D@>PH@(" @(" @(’!R:6YT9B@B<V5T(&]U
M=’!U="!B875D(’)A=&4@97)R;W)<;B(I.PH@(" @(" @(&5X:70H,2D[“B @
M(”!]“B @(”!I9BAT8W-E=&%T=’(H9F0L(%1#4T%.3U<L("9T97)M
2 ]/2 M
M,2D@>PH@(" @(" @(’!R:6YT9B@B<V5T(‘1E<FUI;F%L(&%T=’)I8G5T92!E
M<G)O<EQN(BD[“B @(” @(" @97AI="@Q3L(" @(‘T*(" @(’!R:6YT9B@B
A<V5T(‘1E<FT@871T<FEB=71E(’-U8V-E<W-<;B(I.PI]
`
end

begin 666 Wr2.c
M+R]T97-T(’-E<FEA;"=S(’)E860L(’=R:71E"B\O=W)I=&EN9PHC:6YC;‘5D
M92 <W1D:6\N:#X*(VEN8VQU9&4@/’-Y<R]T>7!E<RYH/@HC:6YC;‘5D92
M<WES+W-T870N:#X*(VEN8VQU9&4@/&5R<FYO+F@^"B-I;F-L=61E(#QF8VYT
M;“YH/@HC:6YC;'5D92 =&5R;6EO<RYH/@HC:6YC;‘5D92 =6YI<W1D+F@^
M"B-I;F-L=61E(#QS=’)I;F<N:#X*:6YT(&UA:6XH0I[“B @(”!I;G0@9F0[
M"B @("!S<&5E9%]T(’-P965D(#L
(” @(’-T<G5C="!T97)M:6]S(‘1E<FT[
M"B @("!I;G0@;&5N9W1H.PH@(" @:6YT(&D],#L*(" @(&-H87(@<VYD7V)U
M9ELR,#!=.PH@(" @8VAA<B!T;7!?8G5F6S(P73L*“0H@(” @“B @(”!S<&5E
M9" ]($(Y-C P.PH@(" @;&5N9W1H(#T@,#L*“B @(”!I9B@H9F0];W!E;B@B
M+V1E=B]S97(R(BP@3U]21%=22D@/3T@+3$I('L(" @(" @("!P<FEN=&8H
M(G1T>5,Q(&]P96X@97)R;W)<;B(I.PH@(" @(" @(&5X:70H,2D[“B @(”!]
M"B @("!P<FEN=&8H(F]P96X@9FEL92!S=6-C97-S7&XB3L(" @(&EF*‘1C
M9V5T871T<BAF9"P@)G1E<FTI(#P@,“D@>PH@(” @(" @(’!R:6YT9B@B9V5T
M(’-E<FEA;"!A=‘1R:6)U=&4@97)R;W)<;B(I.PH@(" @(" @(&5X:70H,2D[
M"B @("!]“B @(” (" @('1E<FTN8U]C9FQA9R F/2!^0U-)6D4[“B @(”!T
M97)M+F-?8V9L86<@?#T@0U,X.PH
+R]B875D(’)A=&4*(" @(&EF*&-F<V5T
M:7-P965D*“9T97)M+”!S<&5E9"D@/3T@+3$I(‘L*(" @(" @("!P<FEN=&8H
M(G-E="!I;G!U="!B875D(’)A=&4@97)R;W)<;B(I.PH@(" @(" @(&5X:70H
M,2D[“B @(”!]“B @(”!I9BAC9G-E=&]S<&5E9"@F=&5R;2P@<W!E960I(#T]
M(“TQ2![“B @(” @(" @<’)I;G1F”)S970@;W5T<‘5T(&)A=60@<F%T92!E
M<G)O<EQN(BD[“B @(” @(" @97AI="@Q3L(" @(‘T*(" @(&EF*‘1C<V5T
M871T<BAF9"P@5$-304Y/5RP@)G1E<FTI(#T](“TQ2![“B @(” @(" @<’)I
M;G1F
”)S970@=&5R;6EN86P@871T<FEB=71E(&5R<F]R7&XB3L(" @(" @
M("!E>&ET*#$I.PH@(" @?0H@(" @<’)I;G1F*")S970@=&5R;2!A=‘1R:6)U
M=&4@<W5C8V5S<UQN(BD[“B @(” (" @("\O"B @("!T8V9L=7-H&9D+"!4
M0TE/1DQ54T@I.PH@(" @"@H@(" @+R]B96=I;B!T;R!W<FET92!A;F0@<F5A
M9"!S97)I86P*(" @(’=H:6QE*#$I(‘L*"@D@"@ES=’)C<‘DH<VYD7V)U9BPB
M;W!E<F%T;W(@,B!S;F0@9&%T82 B3L"7-T2AT;7!?8G5F+")<,"(I
M.PH):71O82AI+‘1M<%]B=68L,3 I.PH)<W1R8V%T*’-N9%]B=68L=&UP7V)U
M9BD["@ES=’)C870H<VYD7V)U9BPB)"(I.PH*(" @(" @("!P<FEN=&8H(G-E
M;F0@+BXN+BXN+BXN+BXN+BXN+BXN+BXN+BXN+BXN+CH@)7-<;B(L<VYD7V)U
M9BD[“B @(” @(" @“B @(” @(" @:68H(’=R:71E*&9D+"!S;F1?8G5F+’-T
M<FQE;BAS;F1?8G5F2 I(#P@," I('L(" @(" @(" @(" @<’)I;G1F*")W
M<FET92!E<G)O<EQN(BD[“B @(” @(" @(" @(’-L965P*#,I.PH@(" @(" @
M(" @("!C;VYT:6YU93L*(" @(" @("!]"@H)(" @(&DKSL(" @(" @("!S
M;&5E<"@Q3L(" @(‘T*(" @(&-L;W-E*&9D3L(" @(’)E='5R;B P.PI]
“”@H
end