I am debugging some socket code for a ZIATECH SBC. A socket is created:
socket(AF_INET, SOCK_STREAM, 0)
setsockopt(socketfd, IPPROTO_TCP, TCP_NODELAY, ...)
connectWithTimeout(socketfd, .....)
and
ioctl(socketfd,FIONBIO, (int)&on)
this should configure a socket: non-blocking,immediate,TCP
the issue is that the socket is polled:
ioctl(socketfd, FIONREAD, (int)&bytesUnread)
if bytesUnread != 0
while (bytesUnread != 0)
read(socketfd, (char*)onebyte,1)
ioctl(socketfd, FIONREAD, (int)&bytesUnread)
my contention is that this will grab anything in the port,
and because it is non-blocking it might be mid message stream
Shouldn't select() (software interrupt) be used to monitor
the port?
Thank you for any help.
If you want to stay with existing code, I suggest you use something like
taskDelay(10) within the polling loop to allow other lower priority tasks to
execute.
regarding mid stream messages reception, that is possible because tcp/ip
sockets are more like pipes, you will need to provide some method of
synchronization within the data to sort out the data coming in on the
socket.
patrick
"Kenneth Arakaki" <ara...@nortelnetworks.com> wrote in message
news:396DFC72...@nortelnetworks.com...
What this code appears to do is to suck dry the pipe, keeping only the last
byte sent. Presumably, the other end is sending status bytes. You could do
the same thing with select and a zero timeout.
--
Jon Baggott
General Dynamics Electronic Systems
"The views expressed are the author's and do not necessarily reflect the
official position of GD or any of its subsidiaries"