Home > Archive > Unix Programming > July 2007 > BSD socket problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
BSD socket problem
|
|
| chris 2007-07-22, 10:05 pm |
| I have developed a program on Mac OS X using BSD Socket API,
It works very fine in most of time, but sometimes the "recvfrom"
function return 0 , i have searched the document on Mac OS X, but find
no useful information; then i search "recvfrom" document on Windwos,
it said:
Return Values
If no error occurs, recvfrom returns the number of bytes received. If
the connection has been gracefully closed, the return value is zero.
Otherwise, a value of SOCKET_ERROR is returned, and a specific error
code can be retrieved by calling WSAGetLastError.
But i didn't close the connection at all, i don't know why and when it
was closed,
Can somebody give me some suggestion?
| |
| Giorgos Keramidas 2007-07-23, 4:13 am |
| On Sun, 22 Jul 2007 18:56:44 -0700, chris <VistaCh@gmail.com> wrote:
> I have developed a program on Mac OS X using BSD Socket API, It works
> very fine in most of time, but sometimes the "recvfrom" function
> return 0
Can you show us the program itself?
> i have searched the document on Mac OS X, but find no useful
> information; then i search "recvfrom" document on Windwos, it said:
Windows documentation is, commonly, very specific to the internals of
the Windows platform. That's not very bad in itself, but it tends to be
less useful or even outright confusing for other operating systems. For
official documentation about the behavior of recvfrom() on MacOS X, you
should read the MacOS X documentation.
> Return Values
> If no error occurs, recvfrom returns the number of bytes received. If
> the connection has been gracefully closed, the return value is zero.
> Otherwise, a value of SOCKET_ERROR is returned, and a specific error
> code can be retrieved by calling WSAGetLastError.
There is no such thing as a WSAGetLastError() function in the BSD
sockets API. This is a Windows-only function, so you should ignore at
least this part of the document you are reading, if not all of it.
> But i didn't close the connection at all, i don't know why and when it
> was closed,
>
> Can somebody give me some suggestion?
Yes. Show us the code, and describe the tests you have run, so we can
reproduce the problem and help you understand why it happens :-)
- Giorgos
| |
| Marco van de Voort 2007-07-27, 8:06 am |
| On 2007-07-23, Giorgos Keramidas <keramida@ceid.upatras.gr> wrote:
>
> There is no such thing as a WSAGetLastError() function in the BSD
> sockets API. This is a Windows-only function, so you should ignore at
> least this part of the document you are reading, if not all of it.
(it's actually not windows only. Afaik netware, OS/2 and dos socket libs
have it too. Probably based one non *nix socket implementation and/or OS/2
being a direct NT relative)
And afaik under *nix socket errors are simply returned in errno or whatever
threadvar function returns it.
| |
| Barry Margolin 2007-07-30, 10:06 pm |
| In article <slrnfajep9.29f9.marcov@snail.stack.nl>,
Marco van de Voort <marcov@stack.nl> wrote:
> On 2007-07-23, Giorgos Keramidas <keramida@ceid.upatras.gr> wrote:
>
> (it's actually not windows only. Afaik netware, OS/2 and dos socket libs
> have it too. Probably based one non *nix socket implementation and/or OS/2
> being a direct NT relative)
What he probably meant was "Winsock-only function". Winsock is the
Microsoft API modeled after sockets, but with its own twists like these.
So these other libraries apparently implement Winsock, not sockets.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| Barry Margolin 2007-07-30, 10:06 pm |
| In article <1185155804.130518.164130@d30g2000prg.googlegroups.com>,
chris <VistaCh@gmail.com> wrote:
> I have developed a program on Mac OS X using BSD Socket API,
> It works very fine in most of time, but sometimes the "recvfrom"
> function return 0 , i have searched the document on Mac OS X, but find
> no useful information; then i search "recvfrom" document on Windwos,
> it said:
Is it a stream socket or a datagram socket. 0 meaning "connection
closed" only applies to stream sockets. For datagram sockets it means
that you received an empty datagram, which is perfectly valid as far as
the UDP protocol is concerned. Whether it's appropriate for your
application is entirely up to you.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|