I was wondering why make an non-blocking socket? What advantage does it provide in comparison to a blocking socket? And you could give me an example of when a non-blocking socket would be more useful.
I can't compile this from where I'm at right now, and I'm going from memory, but it should give you a vague idea. There are many parts missing that aren't relevant to the question (like destruction for example).
For a couple reasons. First, say you are writing a server that can handle multiple connections. If your server blocks on a write to one socket, then your server isn't going to service any of its other connections. If your server blocks on a read of a socket, same thing. These two things are particularly bad for security since one misbehaving client can take your server down -- it's a classic Denial of Service attack.
In general, the answer is because you need the server/process to remain responsive to other things while dealing with the socket.