TCP connection between nodes, should select raise exception ?

DannyBackx
Posts: 33
Joined: Wed Sep 19, 2018 7:17 pm

TCP connection between nodes, should select raise exception ?

Postby DannyBackx » Sat Dec 04, 2021 9:54 pm

Hey,
I have pretty standard code based on BSD socket select.
Shouldn't select() catch the condition that a socket is disconnected and can't be written to ?
Error message changes after the first error, then keeps on going instead of getting an error condition raised.

https://sourceforge.net/p/espalarm/svnc ... /Peers.cpp

Danny

Code: Select all

I (19:31:58.131) Peers: CallPeerAsync: wrote {"weather":"GTWT02","name":"prototype","temp":4.400000095,"channel":1,"txid":124,"humidity":110,"battery-low":false,"seqno":69} to 
I (19:32:57.102) Temperature: GTWT02 (ch 1 txid 124) : 4.4°C, hum 110%
I (19:32:57.111) Peers: CallPeerAsync: wrote {"weather":"GTWT02","name":"prototype","temp":4.400000095,"channel":1,"txid":124,"humidity":110,"battery-low":false,"seqno":70} to 
I (19:33:56.192) Temperature: GTWT02 (ch 1 txid 124) : 4.3°C, hum 110%
E (19:33:56.201) Peers: CallPeerAsync: write to  failed, errno 113 Software caused connection abort, msg {"weather":"GTWT02","name":"prototype","temp":4.300000191,"channel":1,"txid":124,"humidity":110,"battery-low":false,"seqno":71}
I (19:34:55.182) Temperature: GTWT02 (ch 1 txid 124) : 4.3°C, hum 110%
E (19:34:55.191) Peers: CallPeerAsync: write to  failed, errno 128 Socket is not connected, msg {"weather":"GTWT02","name":"prototype","temp":4.300000191,"channel":1,"txid":124,"humidity":110,"battery-low":false,"seqno":72}
I (19:35:54.162) Temperature: GTWT02 (ch 1 txid 124) : 4.3°C, hum 110%
E (19:35:54.172) Peers: CallPeerAsync: write to  failed, errno 128 Socket is not connected, msg {"weather":"GTWT02","name":"prototype","temp":4.300000191,"channel":1,"txid":124,"humidity":110,"battery-low":false,"seqno":73}
I (19:36:53.152) Temperature: GTWT02 (ch 1 txid 124) : 4.3°C, hum 110%

ESP_Sprite
Posts: 9711
Joined: Thu Nov 26, 2015 4:08 am

Re: TCP connection between nodes, should select raise exception ?

Postby ESP_Sprite » Sun Dec 05, 2021 2:49 am

From what I recall, a socket that is closed is generally (in POSIX) being signalled by that socket becoming readable, but reading from it reads 0 bytes. Not sure why they didn't signal it as an error (possibly because a disconnected socket is something that might not be an error?) but that's the way it is.

DannyBackx
Posts: 33
Joined: Wed Sep 19, 2018 7:17 pm

Re: TCP connection between nodes, should select raise exception ?

Postby DannyBackx » Sun Dec 05, 2021 6:22 am

Well, the select() API was built for three things, one of them being exceptional conditions. And the other side in the communication (trying to read) does get such a signal.

Code: Select all

       Three  independent  sets  of file descriptors are watched.  The file descriptors listed in
       readfds will be watched to see if characters become available for reading (more precisely,
       to see if a read will not block; in particular, a file descriptor is also ready on end-of-
       file).  The file descriptors in writefds will be watched to see if space is available  for
       write  (though  a large write may still block).  The file descriptors in exceptfds will be
       watched for exceptional conditions.  (For examples of some exceptional conditions, see the
       discussion of POLLPRI in poll(2).)

Who is online

Users browsing this forum: No registered users and 79 guests