Asynchronous connection to socket always appears to succeed?

Chris Angelico <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Message-ID <CAPTjJmqJVfo+pdvqqjtyTrJ38KfHstsE3cVGugfUj2ieKM2FNg@mail.gmail.com>
Pike 8.1 on Linux.

The following script ought to come through to connfailed() in the
event that there is no TELNET server on localhost. Instead, it comes
through to connected(), then afterward to sockclosed(). Am I doing
something stupidly wrong with asynchronous connections here?

object sock;

void sockread(mixed dummy,string data) {write("Data received: %O\n",data);}
void sockwrite() {write("Socket available for writing\n");}
void sockclosed() {write("Socket closed, terminating.\n"); exit(0);}

void connected()
{
    write("Connection appears successful [errno is %d]\n",sock->errno());
    sock->set_nonblocking(sockread,sockwrite,sockclosed);
}

void connfailed()
{
    write("Error connecting: %s [%d]\n",strerror(sock->errno()),sock->errno());
    sock->close();
    sockclosed();
}

int main()
{
    sock=Stdio.File(); sock->open_socket();
    sock->set_nonblocking(0,connected,connfailed);
    sock->connect("127.0.0.1",23);
    return -1;
}

ChrisA
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.