/* "We discount as naughty the use of tricks such as Unchecked_Conversion to get at the details of private types."
I'm trying to write an ircd - an Internet Relay Chat
server program - in the language Ada
. Ada (for those who are not in know) is a language of the vaguely Pascalian
family. And all is well and good.
What isn't all well and good is that non-blocking listen sockets don't seem to. Just don't, at all.
For the non-techies: a socket is a kind of virtual plug on a computer, which can be virtually connected to another socket on another computer. To fetch a web page, for example, your web browser creates a socket, connects it to another socket on the computer that has the web page you want to access on it, and sends a request for that page down the connection; at which point, the server sends back the page down the connection.
Non-blocking sockets are sockets that don't wait if there's nothing for them to do; if you tell a blocking socket to read data and there isn't any, it will just wait and wait until there is some data to read. A non-blocking socket would just say "there isn't any". I need a non-blocking socket.
A "listening" socket is one that can be connected to. To create a connection between a listening socket and a computer trying to get at that listening socket, the listening computer, the server, needs to "accept" that connection. A non-blocking socket should, by rights, return "there isn't any connection" if you try to accept a connection on it; a blocking socket should wait.
So, armed with this theory I created a Create_Server_Socket procedure in Ada, which created, initially, a blocking listening socket, which you could then accept connections on. This worked as planned; and I could make a connection with telnet
, and send data down it. But it wouldn't work for the situation I wanted, where I needed to have several listening sockets and check them in turn. I couldn't wait for there to be a connection on one before checking the other; it's more a case of "nobody clamouring for my attention on 6667, check 6668, no peace for the wicked". So I enabled non-blocking mode on the sockets, according to the manual. Then I ran it.
It ran fine up till it tried to accept a connection, whereupon "accept" blocked. It should have just said "nothing here"; but it stopped and waited. So I tried to connect to it with telnet, and it made the connection, but stayed stopped; that is to say that the bit of the program after the "accept" never got run.
I don't know why not. It ought have done, as far as I can see.
On the other hand, I've only been doing Ada for four days now... I don't know what all the syntax does. Love the apostrophes (attributes) though :)
That was all my day that wasn't in college. */