Advertisement

WSAGetLastError() unknown error code

Started by May 24, 2003 05:35 AM
8 comments, last by foofightr 21 years, 8 months ago
Anyone seen the error code 183? recv is returning -1 and then WSAGetLastError() returns 183. That''s below the base error number (10000) ?!?
Yes, this is indeed strange.

Are you sure you are calling WSAGetLastError and not GetLastError?

Did you initialise Windows Sockets beforehand, by calling WSAStartup?

I have no other explanation for your problem.
Advertisement
use FormatMessage() to get a text description of the error code. Much more useful than an integer
Creation is an act of sheer will
quote:
Original post by RonHiler
use FormatMessage() to get a text description of the error code. Much more useful than an integer


The error code 183(decimal) translates to the following message:
"Cannot create a file when that file already exists."

This message is meaningless as an error message for a failed recv() call. Therefore, something else must be wrong.

[edited by - TekBoy on May 24, 2003 11:08:06 AM]
Very odd.

To tell the truth, it''s quite embarassing but when I had copied over my network code to a testbed project to test it by running several instances of a console app connected thru localhost (as opposed to several instances of a game ). In my haste, I actually forgot to call WSAStartup()!

But guess what, it was working anyway, for the most part! Was sending fine, accepting new connections fine, receiving fine (other than returning 183 instead of 10035). I guess those docs are wrong in saying "The WSAStartup function must be the first Windows Sockets function called by an application or DLL" , as I wasn''t calling it at all! Maybe Windows XP silently detects un-initialized winsock?

But, even after properly initializing it, it still returns 183 when nothing is to be read on a socket

I''ve been having weird bug(s) crop up in surrounding code that feel to me like buffer overruns. I haven''t nailed them/it down yet. My only guess is that the return value of WSAGetLastError (or the function itself?) is being tampered with somehow. What''s for sure though is the source of the problem is in my code.

I will make my code available shortly...
Interesting. Contrary to what MSDN says, WSAGetLastError() seems to clear the error (to 183?) after you call it once. It''s returning 10035 as expected, but right after it returns 183. I even logged it to be sure.

sample of my log file
[Sat May 24 18:48:02 2003]           recv() returned -1 and WSAGetLastError() returned 10035[Sat May 24 18:48:02 2003]           recv() returned -1 and WSAGetLastError() returned 183[Sat May 24 18:48:02 2003]           recv() returned -1 and WSAGetLastError() returned 183   


The 3 function calls are one after the other in my code.


Still doesn''t explain why it was returning 183 before though, because I had the test set up like this:

// recv() has returned -1if (WSAGetLastError() != WSAEWOULDBLOCK){  // actual error  logfile.write( ... WSAGetLastError() ... );} 

I was calling it once in the if test and once as a parameter to the logfile. But in the first if test, it should have returned 10035 and not gotten called a second time, no?
Advertisement
Are you sure your logfile.write() function isn''t erroring? Perhaps the 183 error is being caused by you trying to create a file (the log file) that already exists? Thus your second WSAGetLastError() call returns not the error you originally got, but an error caused by you trying to log the error
Creation is an act of sheer will
LOL! I changed the error logger''s buffer size to 1 a few days ago to test something, and I forgot to change it back to a reasonable number! So it was flushing the buffer every line

I guess that means opening a file in append mode (fopen(fp, "at") ) gives error 183 then. Oh well! Thanks
That''s pretty annoying though... if I have my buffer at 128, then every 128 lines it triggers WSAGetLastError() to return 183, which triggers my network code to think it''s an network error.

What is the "error" about opening a file in append mode? Suppose I could bring the question to another forum...
There''s probably no error at all. I guess fopen() calls Win32 API functions internally (you could look at the source to check that) and it probably tries to open the file one way first, then if that fails, open it in another way. GetLastError() will still return the error code.

You really should save the return value of WSAGetLastError() to a local variable in your function, then use that local variable.

cu,
Prefect
Widelands - laid back, free software strategy

This topic is closed to new replies.

Advertisement