CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    23

    WSAGetLastError() and WSACleanup()

    I am just wondering if anyone here would please be able to tell me what will happen when I call WSACleanup() as a result of a socket related failure (some WinSock function returning an error). will a call to WSACleanup() clean up any last errors? for example, right now here is my code for one of the functions:

    Code:
    if(bind(lsock, (PSOCKADDR)&sin, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) {
    		err = WSAGetLastError();
    
    		closesocket(lsock);
    		WSACleanup();
    
    		return err;
    	}
    looks ok, but I'm crazy for finding and using the smallest, most efficient methods of getting stuff done. err is a local variable declared as an int. the reason why I'm asking this question is because I'd like to know if I could omit the local variable and do something like this:

    Code:
    if(bind(lsock, (PSOCKADDR)&sin, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) {
    		closesocket(lsock);
    		WSACleanup();
    
    		return WSAGetLastError();
    	}
    its a pretty simple question, however I don't see anything mentioned on msdn about WSACleanup() and last errors. do you think it would be okay if I used the second code, and that WSAGetLastError() will still return the error code for the error that caused bind() to fail (the last error)?

    another question that comes to mind is will I even be able to call WSAGetLastError() after a call to WSACleanup() without some access violation or the like?


    any help here is greatly appreciated. thank you in advance.
    Last edited by sleak; March 29th, 2007 at 01:49 AM. Reason: oops, maybe this would be better suited in the Network Programming forum, sorry I didn't notice there was one

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured