socket read with timeout bug

2003-04-04
2003-08-01
  • Dr. Martin Lehr

    Dr. Martin Lehr - 2003-04-04

    Hi,

    I probably came across two socket-read related bugs (GT.M 4.2-002)

    1.
        R *X:1
        never gets input (but R *X:2 works, R*X:0 works)

    2.
        R X#1:1
        sets $T=0, even if there was input (but R X#1:2 and R x#1:0 are ok)

    this can be tested by modifying and running the following little program,
    a line printer daemon protocol client (RFC 1179) (port 515)

    Checking the queue of the LPD server:
    W $$LPQ^TEST("192.168.1.100","L1")

    sending some data to the printer:
    W $$LPR^TEST("this text will be printed"_$C(13,10),"192.168.1.100","L1")

    the expressions that doesn't work are commented out in LPRR()
    has anybody else observed that?

    Regards
    Martin

    TEST
    TEST ;;
    ;
    OCS(DEST,PORT,DELIM)
    N ZT,SCK
    S SCK="SCK$"_$J
    S ZT=$ZT
    S $ZT="G SOCKERR"
    O SCK:(CONNECT=DEST_":"_PORT_":TCP":DELIMINITER=DELIM:ATTACH="client"):1:"SOCKET"
    S $ZT=ZT
    I '$T Q -1
    U SCK:(NOWRAP:LENGTH=0)
    Q SCK
    ;
    SOCKERR S $ZT=ZT Q -2
    ;
    LPQ(IP,QUEUE)
    N Z,S,TIME,C,L
    S TIME=$P($H,",",2)
    S SOCK=$$OCS^OS(IP,"515",$C(13,10))
    I SOCK<0 Q "error"
    I QUEUE="" C SOCK Q "ok, but no queue"
    U SOCK
    W $C(3),QUEUE,$C(10)
    S S=""
    F  Q:+$D'=0  R Z#1:10 Q:'$T  S S=S_Z
    C SOCK
    Q S
    ;
    LPR(DATA,IP,QUEUE)
    N JOBID,ERR,I,Z,BYTES,CONT,EHOST,SOCK
    S JOBID=$E(100000+$P($H,",",2),4,6)
    S BYTES=$L(DATA)
    S EHOST="linuxserver"
    S CONT="JdfA"_JOBID_EHOST_$C(10)_"Pgtm"_$J_$C(10)_"ldfA"_JOBID_EHOST_$C(10)
    S SOCK=$$OCS(IP,"515","")
    I SOCK<0 S ERR=-20 G LPREX
    U SOCK
    W $C(2),QUEUE,$C(10)
    I $$LPRR()'=0 C SOCK S ERR=-21 G LPREX
    W $C(2),$L(CONT)," cfA"_JOBID_EHOST_$C(10)
    I $$LPRR()'=0 C SOCK S ERR=-31 G LPREX
    W CONT,$C(0)
    I $$LPRR()'=0 C SOCK S ERR=-32 G LPREX
    W $C(3),BYTES," dfA"_JOBID_EHOST_$C(10)
    I $$LPRR()'=0 C SOCK S ERR=-33 G LPREX
    W DATA
    W $C(0)
    I $$LPRR()'=0 C SOCK S ERR=-34 G LPREX
    C SOCK S ERR=0
    ;
    LPREX U $P
    Q ERR
    ;
    LPRR() N X,I
    ;
    ; this is ok
    F I=1:1:10 R X#1:2 S X=$A(X) Q:X>-1
    ;
    ; this is ok
    ;F I=1:1:10 R X#1:2 S X=$A(X) Q:$T
    ;
    ; this does not work, because $T is always=0
    ;F I=1:1:20 R X#1:1 S X=$A(X) Q:$T
    ;
    ; this is ok
    ;F I=1:1:10 R *X:2 Q:X>-1
    ;
    ; this does not work
    ;F I=1:1:20 R *X:1 Q:X>-1
    ;
    Q X

     
    • K.S. Bhaskar

      K.S. Bhaskar - 2003-04-04

      Martin --

      Thanks for reporting the issue. We have reproduced the problem in house (with one minor revision, removed ^OS from line S SOCK=$$OCS^OS(IP,"515",$C(13,10))). It is an issue with timer management in the read logic for the socket device. The workaround is to not use a timeout of 1 second, as you have already figured out. We shall fix  this issue in an upcoming release. Please note, the recently released V4.3-001E also has this issue. We fixed a similar issue for terminal reads. From V4.3-001E release notes - timed terminal READs now return after waiting long enough for the timeout to expire. In prior versions of GT.M V4.3, they used to return one second earlier than the timeout requested. (S9D01-002291) [UNIX]

      Thanks.

      -- Bhaskar

       
    • Sam Weiner

      Sam Weiner - 2003-08-01

      Martin,

      This has been fixed in V4.4-002 and V4.4-FT01.
      The tracking number in the release notes is
      C9C06-002007.

      Enjoy, Sam

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks