Hi All,
I have a client server application. non blocking. based on Berkley
Socket implementation - using select().
I want to find out how many bytes exist on Recv() buffer.
I looked for ioctl() help page. here's what I found:
for unix:
[Quote]
SIOCINQ - Gets a pointer to an integer as argument. Returns the size of
the next pending datagram in the integer in bytes, or 0 when no
datagram is pending.
[Quote/]
for windows:
the equivalent function is
[Code]
int WSAIoctl(
SOCKET s,
DWORD dwIoControlCode,
LPVOID lpvInBuffer,
DWORD cbInBuffer,
LPVOID lpvOutBuffer,
DWORD cbOutBuffer,
LPDWORD lpcbBytesReturned,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
[Code/]
and the description:
[Quote]
FIONREAD Determine the amount of data that can be read atomically from
socket s. lpvOutBuffer points at an unsigned long in which WSAIoctl
stores the result. If s is stream oriented (for example, type
SOCK_STREAM), FIONREAD returns the total amount of data that can be
read in a single receive operation; this is normally the same as the
total amount of data queued on the socket (since data stream is
byte-oriented, this is not guaranteed). If s is message oriented (for
example, type SOCK_DGRAM), FIONREAD returns the size of the first
datagram (message) queued on the socket.
[Quote/]
considering the fact that I want to loop and call Recv() until buffer
is empty or until there are less bytes than FIX_MSG_LEN (a size of a
complete msg), I designed the following cycle:
A) check #bytes in recv buffer (ioctl/ WSAIoctl)
B) if #bytes < FIX_MSG_LEN --> return (don't read partial msgs)
C) else keep calling recv() until you read a complete msg
D) go back to step A
but, at least with WINDOWS I'm bothered because WSAIoctl(FIONREAD) will
return "the total amount of data that can be read in a single receive
operation;" which is "normally the same as the total amount of data
queued on the socket". meaning they can be different. so theoretically,
a possible situation is that I'll keep getting from WSAIoctl()/ ioctl()
a number < FIX_MSG_LEN even though there are more than FIX_MSG_LEN
bytes on buffer and than return and never reach phase C in my algorithm
(never call recv()). of course this is an unwanted situation.
Q1) what do you think?
Q2) is ioctl() in UNIX behaves the same? does it guarentee to return
"total amount of data queued on the socket"?
thanks guys,


|