Click to See Complete Forum and Search --> : getsockopt() doesn't seem to be working as expected
goanuj
September 20th, 2002, 10:12 PM
basically this is my code
int n;
n = select(sockethandle, &rset, &wset, NULL, NULL)
/* n turned out to be -1
* so I know there must be some error and now I am going to
* call getsockopt() to see what that error was */
int errNum;
int len = sizeof(len);
int err = getsockopt(socketHandle, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&errNum), &len);
however, err = 0 and errNum = 0
if getsockopt() doesn't return an error, then there should be a non-zero value in errNum!!!! Please correct me if I am wrong.
why is getsockopt() not putting anything in errNum ????
does that mean there was _not_ an error???
should I use WSAGetLastError() to check when select() returns -1
j0nas
September 21st, 2002, 06:00 AM
You shouldn't use getsockopt to get the winsock error code. Use WSAGetLastError() instead. Always call WSAGetLastError() when a winsock function returns -1 (SOCKET_ERROR).
Good luck.
goanuj
September 21st, 2002, 06:19 AM
thanks for your input..... when is it ever advisable to call getsockopt() ???
I am using the posix-like ones such as connect(), bind(), accept(), listen(), select() recv() send(), accept(), shutdown(), close(). I am _not_ using WSAConnect or WSAWaitForMultipleEvents, can you mix and match the select() call w/ WSAGetLastError()?
If I don't include winsock2.h will it still work?
goanuj
September 23rd, 2002, 01:16 PM
is it possible to get an EINVAL
here? assume the _Socket has been set up correctly ....
fd_set rset, wset;
FD_ZERO(&rset);
FD_ZERO(&wset);
FD_SET(_Socket, &wset);
select(_Socket, &rset, &wset, NULL, NULL);
select is returning -1 and when I check the error using WSAGetLastError() it returns WSAEINVAL.
and I _think_ (but don't know) that because rset doesn't have any bits set, it is giving me the error. However, having one of the bits set in wset should keep MSDEV from getting mad at me.
MSDEV says this about select() when it returns WSAEINVAL.
"The time-out value is not valid, or all three descriptor parameters were NULL."
Anyone know more about this?
NADZZZ
July 8th, 2004, 12:14 PM
If I am using LINUX and WSAGetLastError is not avalible for me. How do I resolve this problem????
cilu
July 8th, 2004, 12:20 PM
Here we talk about Visual C++ programming. Linux question might remain unanswered.
Andreas Masur
July 8th, 2004, 01:40 PM
[Moved thread]
Andreas Masur
July 8th, 2004, 01:41 PM
Originally posted by goanuj
when is it ever advisable to call getsockopt() ???
Well...whenever you want to retrieve a socket option... :cool:
MikeAThon
July 8th, 2004, 05:06 PM
NADZZZ: This thread was started nearly two years ago, in Sept 2002.
It makes no sense for you to add a new question to such an old thread, particularly where (as here) your question is not really related to the OP's original question. Doing so creates confusion and causes people to waste time responding to questions that the OP has long since resolved (or abandoned).
Please start new threads rather than "waking up" old ones.
Regards,
Mike
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.