Hello.
I try to understand some code from dtask_tcp_datasrv of newservers.c file.
The first point, why setsockopt is called three times in a row? Every time socket s is called, is socket redefined again or it not? Why is this done?
Where can I see code of setsockopt function? Is it possible? Myself, I could not find it in the folders of SDK.
/* Configure our socket timeout to be 5 seconds */
to.tv_sec = 5;
to.tv_usec = 0;
setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );
i = 1;
setsockopt( s, IPPROTO_TCP, NDK_TCP_NOPUSH, &i, 4 );
The second point, after the socket is configured with the setsockopt function, a call is made function recv.
/* receive request for amount of data to send from client */
i = (int)recv( s, (char *)&size, sizeof(int), 0 );
I'm not so clear understand what does it do.According to NDK API Guide, function is return Value If it succeeds, the function returns the number of bytes received. But I can not understand, where to the function returns the amount of data? Into the "i" variable, or not?
It seems to me in "i" variable and the operational code of the function is returned. Like is describe in NDK API Guide:
- EBADF: The file descriptor (socket) is invalid.
- EINVAL: Attempt to read (or calling arguments) invalid for this socket.
- ENOTCONN: The socket is connection oriented and not connected
- ENOTSOCK: The file descriptor does not reference a socket.
- ETIMEDOUT: The socket connection was dropped due to protocol layer timeout.
- EWOULDBLOCK: The socket is specified as non-blocking, or the timeout has expired.
Where can I see the hexadecimal code EBADF, EINVAL, etc.
For example, my device, when debugging, returns the number 4 in the code when breakpoint is occore. What does 4 is mean?