@@ -326,43 +326,43 @@ void PollSetTest::testPoll()
326
326
327
327
void PollSetTest::testPollNoServer ()
328
328
{
329
- StreamSocket ss1;
330
- StreamSocket ss2;
331
- ss1.connectNB (SocketAddress (" 127.0.0.1" , 0xFEFE ));
332
- ss2.connectNB (SocketAddress (" 127.0.0.1" , 0xFEFF ));
329
+ StreamSocket ss1 (SocketAddress::IPv4);
330
+ StreamSocket ss2 (SocketAddress::IPv4);
331
+
333
332
PollSet ps;
334
333
assertTrue (ps.empty ());
335
334
ps.add (ss1, PollSet::POLL_READ | PollSet::POLL_WRITE | PollSet::POLL_ERROR);
336
335
ps.add (ss2, PollSet::POLL_READ | PollSet::POLL_WRITE | PollSet::POLL_ERROR);
337
336
assertTrue (!ps.empty ());
338
337
assertTrue (ps.has (ss1));
339
338
assertTrue (ps.has (ss2));
340
- PollSet::SocketModeMap sm;
341
- int signalled = 0 ;
342
- Stopwatch sw; sw.start ();
343
- do
339
+
340
+ try
344
341
{
345
- sm = ps.poll (Timespan (1000000 ));
346
- for (auto s : sm)
347
- assertTrue (0 != (s.second & PollSet::POLL_ERROR));
348
-
349
- signalled += static_cast <int >(sm.size ());
350
- if (sw.elapsedSeconds () > 10 ) fail ();
351
- } while (signalled < 2 );
352
- assertTrue (signalled == 2 );
342
+ ss1.connect (SocketAddress (" 127.0.0.1" , 0xFEFE ));
343
+ fail (" Socket should not connect" );
344
+ }
345
+ catch (Poco::Net::ConnectionRefusedException&) {}
346
+ catch (Poco::IOException&) {}
353
347
348
+ try
349
+ {
350
+ ss2.connect (SocketAddress (" 127.0.0.1" , 0xFEFE ));
351
+ fail (" Socket should not connect" );
352
+ }
353
+ catch (Poco::Net::ConnectionRefusedException&) {}
354
+ catch (Poco::IOException&) {}
355
+
356
+ assertTrue (2 == ps.poll (Timespan (1000000 )).size ());
354
357
}
355
358
356
359
357
360
void PollSetTest::testPollClosedServer ()
358
361
{
359
362
EchoServer echoServer1;
360
363
EchoServer echoServer2;
361
- StreamSocket ss1;
362
- StreamSocket ss2;
363
-
364
- ss1.connect (SocketAddress (" 127.0.0.1" , echoServer1.port ()));
365
- ss2.connect (SocketAddress (" 127.0.0.1" , echoServer2.port ()));
364
+ StreamSocket ss1 (SocketAddress::IPv4);
365
+ StreamSocket ss2 (SocketAddress::IPv4);
366
366
367
367
PollSet ps;
368
368
assertTrue (ps.empty ());
@@ -372,6 +372,9 @@ void PollSetTest::testPollClosedServer()
372
372
assertTrue (ps.has (ss1));
373
373
assertTrue (ps.has (ss2));
374
374
375
+ ss1.connect (SocketAddress (" 127.0.0.1" , echoServer1.port ()));
376
+ ss2.connect (SocketAddress (" 127.0.0.1" , echoServer2.port ()));
377
+
375
378
std::string str = " HELLO" ;
376
379
int len = static_cast <int >(str.length ());
377
380
@@ -385,20 +388,12 @@ void PollSetTest::testPollClosedServer()
385
388
assertTrue (len == ss2.sendBytes (str.data (), len));
386
389
while (!echoServer2.done ()) Thread::sleep (10 );
387
390
388
- int signalled = 0 ;
389
- Stopwatch sw; sw.start ();
390
- do
391
- {
392
- signalled += static_cast <int >(ps.poll (Timespan (1000000 )).size ());
393
- int secs = sw.elapsedSeconds ();
394
- if (secs > 10 )
395
- fail (Poco::format (" timed out after %ds, sockets signalled=%z (expected 2)" , secs, signalled), __LINE__);
396
- } while (signalled < 2 );
397
-
398
- assertTrue (signalled == 2 );
399
391
// socket closed or error
400
- assertTrue (0 >= ss1.receiveBytes (0 , 0 ));
401
- assertTrue (0 >= ss2.receiveBytes (0 , 0 ));
392
+ char c;
393
+ assertTrue (0 >= ss1.receiveBytes (&c, 1 ));
394
+ assertTrue (0 >= ss2.receiveBytes (&c, 1 ));
395
+
396
+ assertTrue (2 == ps.poll (Timespan (1000000 )).size ());
402
397
}
403
398
404
399
0 commit comments