Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is invalid socket defined as ~0 in WinSock2.h (c++)?

Tags:

In WinSock2.h, the invalid socket and socket error are defined as these? Is there any significance to this?

#define INVALID_SOCKET  (SOCKET)(~0) #define SOCKET_ERROR            (-1) 
like image 994
unj2 Avatar asked May 30 '12 13:05

unj2


People also ask

What is Winsock2 h?

Socket type definitions in the Winsock2. h and Ws2def. h header files will be periodically updated as new socket types, address families, and protocols are defined. In Windows Sockets 1.1, the only possible socket types are SOCK_DGRAM and SOCK_STREAM.

What is Windows Socket Error?

This error occurs if an application attempts to bind a socket to an IP address/port that has already been used for an existing socket, or a socket that was not closed properly, or one that is still in the process of closing.


1 Answers

Long ago, early in the morning of a cold rainy day, in the midst of misty green covered hills in a quaint but growing suburb of Seattle, WA, there was a small yet sprawling cluster of red-bricked buildings, in one of which was a medium sized conference room, where a growing number of network software engineers, managers, and architects were gathering. The meeting had started quietly enough, with the mostly male group sipping their cups of tea and coffee, twirling their mechanical pencils while scribbling on their memo pads, or scratching away on their Palm Pilots (there was that guy with the Newton, but everyone ignored him).

As the presenter continued with scrolling through the source code, he was stopped by one of the 5 software architects that had specifically not been invited to the review but showed up anyway. "What, pray tell, is that.", he seethed, wagging his finger just like President Clinton. The presenter stopped and stared at the finger, finding himself somehow mesmerized by the wiggling of the finger as the architect continued to wag. "I said," he began to repeat.

The presenter looked up at the screen, and didn't notice anything amiss. "What are you talking about?" he asked.

The architect raised his eyebrows, as his face first expressed consternation, then turned to indignation, then to constipation, as he yelled "That is a blatant coding style guideline violation!".

The observers began to whisper among themselves, wondering what the issue was all about. But, the presenter was nonplussed (the second kind), quickly gave thanks for the feedback, and continued with the review.

"I will not be ignored!", the architect screamed in a high pitched squeal, as he stood up suddenly, slamming his palms to the table top with a kind of a wimpy thud.

The room erupted as fists pounded the table and managers began devising ways to cover their backsides and engineers began flipping through their coding style manuals, complete with table of contents, index, footnotes, and references.

The presenter remained externally unperturbed, but was feeling annoyed, as he desperately wanted the review completed so that he could go on his ski trip in Snoqualmie. "Are you talking about the type mismatch?", he casually asked.

The architect for a moment looked taken aback, but quickly recomposed himself, "Obviously", he snorted.

The presenter replaced the two characters '-1' with '~0' and turned around. The architect scrutinized the change, then the rest of the screen, then consulted his notes, then finally sat back down.

The rest of the review was uneventful.

like image 159
jxh Avatar answered Sep 19 '22 14:09

jxh