Folks,
Back in 2014 Dirk and Helge added support for receiving messages sent from a UDP device to drvAsynIPServerPort. I am trying to use that now to receive data sent from a Ketek detector. In one mode it streams data using UDP to a user-specified IP address and
port.
It have this basically working in my EPICS driver using drvAsynIPServerPort.
However, I have identified 4 issues with drvAsynIPServerPort. I have documented them here:
This is the text of that issue:
-
It is using maxchars-1 rather than maxchars, so it returns 1 fewer bytes than it should.
https://github.com/epics-modules/asyn/blob/e417caf2c4a4332e682635c67bd32a0c4d964fc3/asyn/drvAsynSerial/drvAsynIPServerPort.c#L196
-
If there is no data available when readIt is called then it simply sleeps for 1 ms and sets thisRead=0
https://github.com/epics-modules/asyn/blob/e417caf2c4a4332e682635c67bd32a0c4d964fc3/asyn/drvAsynSerial/drvAsynIPServerPort.c#L192 and returns asynSuccess and *nbytesTransfered=0. It seems to me that it should loop for the specified timeout waiting for the
connectionListener to fill the buffer before returning nRead=0 if there is no data to read. If the data does not arrive then it should return asynTimeout, not asynSuccess.
-
It is not checking the number of characters actually in the buffer, but rather always copies maxchars characters which can lead to reading beyond the end of the internal buffer, which can lead to an access violation.
https://github.com/epics-modules/asyn/blob/e417caf2c4a4332e682635c67bd32a0c4d964fc3/asyn/drvAsynSerial/drvAsynIPServerPort.c#L196
-
The buffer is being filled in the connectionListener thread, which uses the tty->UDPbufferPos variable and modifies the tty->UDPbufferSize variables here:
https://github.com/epics-modules/asyn/blob/e417caf2c4a4332e682635c67bd32a0c4d964fc3/asyn/drvAsynSerial/drvAsynIPServerPort.c#L311 The buffer is being read in the readIt() method which runs in the port driver thread, and which modifes tty->UDPbufferPos and
tty->UDPbufferSize variables here:
https://github.com/epics-modules/asyn/blob/e417caf2c4a4332e682635c67bd32a0c4d964fc3/asyn/drvAsynSerial/drvAsynIPServerPort.c#L200 However, there is no mutex to protect the tty->UDPbufferPos and tty->UDPbufferSize variables. This seems like a serious issue,
which is likely to cause corruption?
Thanks,
Mark
|