Jump to content

  • Log In with Google      Sign In   
  • Create Account

Winsock Simple Class Advice


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Freelancemfyffe   Members   -  Reputation: 103

Like
0Likes
Like

Posted 15 December 2012 - 05:39 PM

I wanted to make a simple wrapper class around winsock that programmers could use in order to obtain information about a certain host. The programmer can easily do the following with my wrapper class.

[source lang="cpp"]int main(){CHostInfo hostInfo;// winsock initializeif (hostInfo.Initialize() == false){ // initialization of winsock failed return -1;}// obtain host information using winsockLPHOSTENT lpHostEnt = hostInfo.GetHostInfo("www.google.com");if ( lpHostEnt == NULL ){ // winsock failed to obtain host information return -1;}return 0;}[/source]


My class hides the details of winsock initialization and other function behind the scenes and avoids users from the details of Winsock. I'm not quite sure on the recommended method for returning error information to the caller of my wrappers functions. ATM i simply return bool for success and failure. I would like to return the WSAGetLastError() code instead. Does anyone have any recommended advice on the approach i should take?

Methods i thought of
-------------------------
1.) Simply have a variable in the class that holds the error code
2.) Simply have a function that calls WSAGetLastError() like so

int CHostInfo::GetWinSockError()
{
return WSAGetLastError();
}

I know the above are valid options but not sure if one is better then the other or if any other better methods exist

In summary, What method is recommended in order to shield users from the WINSOCK API and use my wrapper class API and yet still get valuable information back when an error occurs in the winsock functions? thanks!

Sponsor:

#2 Khatharr   Crossbones+   -  Reputation: 3002

Like
0Likes
Like

Posted 20 December 2012 - 06:24 PM

I'm confused as to what you're asking about here. If you're writing this thing then just return (WSAGetLastError()) on fail and 0 on success instead of returning a bool.

?
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS