rdmenezes / ting

Automatically exported from code.google.com/p/ting
0 stars 0 forks source link

Assert fail in SetWaitingEventsForWindows when closing socket in WaitSet #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Steps will reproduce the problem:
1. Create socket
2. Add socket to WaitSet
3. Close socket -> assert fail in SetWaitingEventsForWindows

Correct order is removing from WaitSet and them close the socket, but it would 
be nice if it could work the other way around too.

I'm using ting 0.4.2, Win7, compiling with mingw

Original issue reported on code.google.com by juan...@gmail.com on 29 Nov 2010 at 3:01

GoogleCodeExporter commented 9 years ago

Original comment by igagis@gmail.com on 29 Nov 2010 at 3:27

GoogleCodeExporter commented 9 years ago
Test code demonstrating the error:

 {
               ting::SocketLib socketsLib;
               ting::IPAddress ip = socketsLib.GetHostByName("www.google.com", 80);
               ting::TCPSocket sock;
               sock.Open(ip);

               const char * reqs = "GET / HTTP/1.1\r\nHost:
www.google.com\r\nConnection:close\r\n\r\n";
               ting::Buffer<ting::u8> req( (ting::u8*) reqs , strlen(reqs) );
               sock.SendAll( req );

               ting::StaticBuffer<ting::u8,1024> respBuf;

               ting::WaitSet waitSet(1);
               waitSet.Add(&sock, ting::Waitable::READ);

               waitSet.Wait(false,2000,NULL);

               CHECK( sock.CanRead() );

               int read = sock.Recv(respBuf,0);

               sock.Close();
               LOG_DEBUG<<"Ready for crash"; //-------- CRASH ON NEXT LINE
               waitSet.Remove(&sock);
               LOG_DEBUG<<"we never get here"; //------------------------
       }

Original comment by igagis@gmail.com on 2 Dec 2010 at 1:35

GoogleCodeExporter commented 9 years ago
Looks like, due to implementation specifics, it is not possible to fix this.
Only opened and not closed Sockets are allowed to be in the WaitSet.

I have added more informative asserts to catch wrong cases.

Not closing this bug so far, cause it still may be resolved in some far future. 
Setting bug priority to "low".

Original comment by igagis@gmail.com on 28 Dec 2010 at 4:03

GoogleCodeExporter commented 9 years ago
After some thinking I came to the conclusion that such use case contradicts to 
the conception of ting sockets. When socket is closed it becomes invalid. 
Invalid socket cannot belong to a WaitSet.
Assertions were added to catch such cases of incorrect usage.
Closing bug as invalid.

Original comment by igagis@gmail.com on 30 Mar 2011 at 7:35