close() of listening socket from another thread

Just a warning.

Calling close() on listening socket in another thread will NOT prevent another connection from being made. Instead, you must call shutdown(). This should abort existing select() calls (probably accept() too, but I didn’t try).

Guess how I found out 🙂

Great new GCC option – Effective-C++ Warnings

Did you know about -Weffc++ in GCC? Neither did I, until I upgraded to new Code::Blocks from Jens’ unofficial Debian repository for Code::Blocks.

Here’s a few sample warnings, with sample lines and commentary:

  • /home/ivucica/Development/project/src/types.h|12|warning: ‘operator=’ should return a reference to ‘*this’|

Sample:
Position &operator=(const Position& other) { x=other.x; y=other.y; z=other.z; return *this;}

What’s the big deal here? By leaving out the ampersand in this operator overloading, I accidentally returned a copy of entire Position class. (On the other hand, I had no reason to actually overload this operator so perhaps real fix is to erase entire line. Still…)

  • /home/ivucica/Development/project/src/mat.h|10|warning: ‘class Mat’ has pointer data members|
    /home/ivucica/Development/project/src/mat.h|10|warning: but does not override ‘Mat(const Mat&)’|
    /home/ivucica/Development/project/src/mat.h|10|warning: or ‘operator=(const Mat&)’|

No sample needed.

What’s the problem here? Well, we have a Mat class containing pointer. So what happens when someone does this: Mat x = y; or this: Mat x(y);? We have another instance of a class with copies of all the data, except the data pointed to by the pointer. Instead the pointer itself gets copied.

So if we keep a C-style string in there, we’re not really copying the string … we’re copying the pointer to it, and modifying the string in the new instance still modifies the string in the original ocpy.

While not applicable everywhere, still a good and useful warning.

  • /home/ivucica/Development/project/src/obj.h||In constructor ‘Obj::Obj()’:|
    /home/ivucica/Development/project/src/obj.h|15|warning: ‘Obj::m_radius’ should be initialized in the member initialization list|

Simple. Instead of initializing (or forgetting to initialize, or intentionally doing so) a variable in the constructor:
Obj() {m_classname=”Obj”; m_usecount = 0; }
why not do it in a “safe” and readable way (and perhaps more optimal?)
Obj() : m_classname(“Obj”), m_usecount(0) { }

While these warnings are certainly not the Universal Elixir to cure all your troubles, they will certainly prove useful in furthering your 1337 skills.

Earning money through ads?

A question mark, and for a reason.

On all my sites, I get about 800 weekly visitors. Very small number, but sufficient to make about $0.05/week pretty unsatisfactory. Since December, about $3.00. A long way to the $100 to get cash from Adsense.
Looks like people just ignore ads nowadays. Is it worth to even hope for any money?

Slow logoff in Windows XP – hang on "Saving your settings"

If you have problems with Windows XP logging off — that is, the system inexplicably decides to wait for about a minute before it proceeds with log off or shutdown — you may want to give Microsoft’s UPHclean – User Profile Hive Cleanup Service a spin. It just helped me with this problem that was harassing me for the past full calendar year.

It installs as a service so it’ll keep working.
Now, I wonder why this service is not included in Windows themselves, or at least in a service pack – why ship a broken OS?

Yahoo! OpenID’s XRDS check, Apache2 and PHP

Another continuation of a previous blogging session 🙂

A reminder, we’re talking about this:

Warning: This website has not confirmed its identity with Yahoo! and might be fraudulent. Do not share any personal information with this website unless you are certain it is legitimate.

PHP+Apache2 users out there might be interested in this reminder, which it’s already mentioned on previous post’s checklist, but I’d like to point it out again.

Don’t name your file xrds.xml.php and try to serve it as xrds.xml while changing Content-type to application/xrds+xml in the header. Apache2 is braindead (or used to be) and doesn’t even attempt to execute the file.

Yahoo! sends an Accept header in its HTTP request, listing application/xrds+xml. Apache decides your file is not of correct filetype, and sends Yahoo! the 406 Not Acceptable response. Referring to same file with the .php extension included makes Apache actually execute the file, and then compare the content-type to the accept header from the client.