Hi!
I'd find it very useful to have a parameter for net-connect to make that call non-blocking. I've built a simple polling loop and and a socket class to handle multiple connections in one thread, but when it comes to outgoing connections they block until they're connected. This is a bit disappointing, especially since I've made a single exe of newlisp and freewrap, cause then a blocking call also blocks the GUI. (I might just release that little hack when I've cleaned up the code.)
Anyone know of a workaround for this? Is it hard to implement? Lutz? And yeah, thanks for a great scripting tool!
non-blocking net-connect for TCP
Peter:
Try this: (net-connect "192.168.0.56" 80) (I just assume you don't have anybody on that intranet address).
It's not really non-blocking. It just appears to be that way when you connect to a server that send a RST (we're talking TCP here). If there's nothing on the other end, only the timeout stops the connection attempt. Or is there a parameter that I've forgotten? I wish you where right.
Try this: (net-connect "192.168.0.56" 80) (I just assume you don't have anybody on that intranet address).
It's not really non-blocking. It just appears to be that way when you connect to a server that send a RST (we're talking TCP here). If there's nothing on the other end, only the timeout stops the connection attempt. Or is there a parameter that I've forgotten? I wish you where right.
'net-connect' is based on the libc sockets call connect() which will block until a connection is made or a timeout occurs.
When 'net-connect' fails it returns 'nil' and you can use the newLISP function (sys-error) to consult the internal errno of your OS. Some value will be returned which you can lookup in your platforms /usr/incluce/sys/errno.h.
errno.h contains a large list of possible error numbers for different i/o situations. The entries important for 'net-connect' you can lookup in the unix man page of your platform doing a:
man connect
The newLISP (net-error) will also be set and return "Connection failed"
Lutz
When 'net-connect' fails it returns 'nil' and you can use the newLISP function (sys-error) to consult the internal errno of your OS. Some value will be returned which you can lookup in your platforms /usr/incluce/sys/errno.h.
errno.h contains a large list of possible error numbers for different i/o situations. The entries important for 'net-connect' you can lookup in the unix man page of your platform doing a:
man connect
The newLISP (net-error) will also be set and return "Connection failed"
Lutz
Oops, you appear to be are right there! I tried to connect to a non-existing IP address in my IP segment, this returns a nil very fast.
But indeed, if I try to reach a non-pingable IP address outside my current network, then it takes a long time to connect.
Also, if I try to 'ping' such an address, even the 'ping' does not return.
I guess we're facing the limitations of Unix TCP networking.
Peter
But indeed, if I try to reach a non-pingable IP address outside my current network, then it takes a long time to connect.
Also, if I try to 'ping' such an address, even the 'ping' does not return.
I guess we're facing the limitations of Unix TCP networking.
Peter