async_req: fix non-blocking connect()
authorRalph Boehme <slow@samba.org>
Sun, 18 Oct 2015 20:21:10 +0000 (22:21 +0200)
committerKarolin Seeger <kseeger@samba.org>
Wed, 28 Oct 2015 11:41:22 +0000 (12:41 +0100)
commitfc280cac24f567efcbeb2b65424fdf819c4bd897
tree4760b22e9203e4c945e2c931e430d047aed97b68
parentc016c1a269c6b7c642a6261ebbe2863eda5b7653
async_req: fix non-blocking connect()

According to Stevens UNIX Network Programming and various other sources,
the correct handling for non-blocking connect() is:

- when the initial connect() return -1/EINPROGRESS polling the socket
  for *writeability*

- in the poll handler call getsocktopt() with SO_ERROR to get the
  finished connect() return value

Simply calling connect() a second time without error checking is
probably wrong and not portable. For a successfull connect() Linux
returns 0, but Solaris will return EISCONN:

24254:   0.0336  0.0002 connect(4, 0xFEFFECAC, 16, SOV_DEFAULT) Err#150 EINPROGRESS
24254:          AF_INET  name = 10.10.10.143  port = 1024
24254:   0.0349  0.0001 port_associate(3, 4, 0x00000004, 0x0000001D,0x080648A8) = 0
24254:   0.0495  0.0146 port_getn(3, 0xFEFFEB50, 1, 1, 0xFEFFEB60) = 1 [0]
24254:   0.0497  0.0002 connect(4, 0x080646E4, 16, SOV_DEFAULT) Err#133 EISCONN
24254:          AF_INET  name = 10.10.10.143  port = 1024

Bug: https://bugzilla.samba.org/show_bug.cgi?id=11564

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 05d4dbda8357712cb81008e0d611fdb0e7239587)
lib/async_req/async_sock.c