nettools/conntest/Engine/SocketsEngine.cpp
changeset 2 4cefe9af9cf4
parent 0 857a3e953887
child 8 86091f1c2f4d
equal deleted inserted replaced
1:e329958deeba 2:4cefe9af9cf4
   949     // Active object request complete handler.
   949     // Active object request complete handler.
   950     // iEngineStatus flags what request was made, so its
   950     // iEngineStatus flags what request was made, so its
   951     // completion can be handled appropriately
   951     // completion can be handled appropriately
   952     iTimer->Cancel(); // Cancel TimeOut timer before completion
   952     iTimer->Cancel(); // Cancel TimeOut timer before completion
   953     TBuf<64> text( _L(""));
   953     TBuf<64> text( _L(""));
       
   954     TBuf<64> errorText( _L("") );
       
   955     
   954     switch (iEngineStatus)
   956     switch (iEngineStatus)
   955         {
   957         {
   956         case EInterfaceDown:
   958         case EInterfaceDown:
   957             // Just in case, if status is changed in ProgressNotifyReceived
   959             // Just in case, if status is changed in ProgressNotifyReceived
   958             // method before this method is called
   960             // method before this method is called
   990                     ConnectL();
   992                     ConnectL();
   991                     }
   993                     }
   992                 }
   994                 }
   993             else
   995             else
   994                 {
   996                 {
   995                 iConsole.ErrorNotify( _L("<CSocketsEngine> Startup failed"), iStatus.Int() );
   997                 errorText.Append(_L("<CSocketsEngine> Startup failed"));
   996                 ChangeStatus( EInterfaceDown );
   998                 ChangeStatus( EInterfaceDown );
   997                 SetSocketEngineConnType( ETypeUnknown );
   999                 SetSocketEngineConnType( ETypeUnknown );
   998                 }
  1000                 }
   999             break;
  1001             break;
  1000             
  1002             
  1008                 ChangeStatus( EConnected );
  1010                 ChangeStatus( EConnected );
  1009                 Read(); //Start CSocketsRead Active object
  1011                 Read(); //Start CSocketsRead Active object
  1010                 }
  1012                 }
  1011             else
  1013             else
  1012                 {
  1014                 {
  1013                 iConsole.ErrorNotify( _L("<CSocketsEngine> Conn. failed"), iStatus.Int() );
  1015                 errorText.Append(_L("<CSocketsEngine> Conn. failed"));
  1014                 ChangeStatus( EInterfaceUp );
  1016                 ChangeStatus( EInterfaceUp );
  1015                 }
  1017                 }
  1016             break;
  1018             break;
  1017             
  1019             
  1018         case ELookingUp:
  1020         case ELookingUp:
  1036                 ConnectL( TInetAddr::Cast( iNameRecord.iAddr ) );
  1038                 ConnectL( TInetAddr::Cast( iNameRecord.iAddr ) );
  1037                 }
  1039                 }
  1038             else
  1040             else
  1039                 {
  1041                 {
  1040                 // DNS lookup failed
  1042                 // DNS lookup failed
  1041                 iConsole.ErrorNotify( _L("<CSocketsEngine> DNS lookup failed"), iStatus.Int() );
  1043                 errorText.Append(_L("<CSocketsEngine> DNS lookup failed"));
  1042                 ChangeStatus( EInterfaceUp );
  1044                 ChangeStatus( EInterfaceUp );
  1043                 }
  1045                 }
  1044             break;
  1046             break;
  1045         case EListening:
  1047         case EListening:
  1046             // Listening socket accept returned
  1048             // Listening socket accept returned
  1052                 // Initiate read of data from socket
  1054                 // Initiate read of data from socket
  1053                 iSocketsRead->StartRAWRead( &iAddress, iProtocol );
  1055                 iSocketsRead->StartRAWRead( &iAddress, iProtocol );
  1054                 }
  1056                 }
  1055             else
  1057             else
  1056                 {
  1058                 {
  1057                 iConsole.ErrorNotify( _L("<CSocketsEngine> Accept. failed"), iStatus.Int() );
  1059                 errorText.Append(_L("<CSocketsEngine> DNS lookup failed"));
  1058                 iListeningSocket.Close();
  1060                 iListeningSocket.Close();
  1059                 iSocket.Close();
  1061                 iSocket.Close();
  1060                 ChangeStatus( EInterfaceUp );
  1062                 ChangeStatus( EInterfaceUp );
  1061                 }
  1063                 }
  1062             
  1064             
  1071             
  1073             
  1072         default:
  1074         default:
  1073             // Ignore the state check here, because it might happen that state
  1075             // Ignore the state check here, because it might happen that state
  1074             // has already been altered in ProgressNotifyReceived method.
  1076             // has already been altered in ProgressNotifyReceived method.
  1075             break;
  1077             break;
       
  1078         }
       
  1079     
       
  1080     // ErrorNotify starts the scheduler, don't add any code that refers to
       
  1081     // class variables after it (they might have changed!)
       
  1082     if (errorText.Length() > 0)
       
  1083         {
       
  1084         iConsole.ErrorNotify( errorText, iStatus.Int() );
  1076         }
  1085         }
  1077     }
  1086     }
  1078 
  1087 
  1079 // ---------------------------------------------------------
  1088 // ---------------------------------------------------------
  1080 // CSocketsEngine::DoCancel()
  1089 // CSocketsEngine::DoCancel()
  1485 // stage in output window.
  1494 // stage in output window.
  1486 // ---------------------------------------------------------
  1495 // ---------------------------------------------------------
  1487 //
  1496 //
  1488 void CSocketsEngine::ProgressNotifyReceivedL( TInt aStage, TInt aError )
  1497 void CSocketsEngine::ProgressNotifyReceivedL( TInt aStage, TInt aError )
  1489     {
  1498     {
  1490     
       
  1491     TBuf8<64> text;
  1499     TBuf8<64> text;
  1492     text.AppendFormat( _L8("Progress: %d, %d"), aStage, aError );
  1500     text.AppendFormat( _L8("Progress: %d, %d"), aStage, aError );
  1493 
  1501 
  1494     TBuf8<16> error;
  1502     TBuf8<16> error;
  1495     error.Format( _L8(", %d"), aError );
  1503     error.Format( _L8(", %d"), aError );
  1541                 iTempProgressNotifier->Cancel();
  1549                 iTempProgressNotifier->Cancel();
  1542                 delete iTempProgressNotifier;
  1550                 delete iTempProgressNotifier;
  1543                 iTempProgressNotifier = NULL;
  1551                 iTempProgressNotifier = NULL;
  1544                 }
  1552                 }
  1545             break;
  1553             break;
  1546             case KConnectionFailure: // 2001
  1554         case KConnectionFailure: // 2001
  1547                         iConsole.PrintNotify(_L8("Connection failure"));
  1555             iConsole.PrintNotify(_L8("Connection failure"));
  1548                         iConsole.PrintNotify(error);
  1556             iConsole.PrintNotify(error);
  1549                         break;
  1557             break;
  1550                         case KMinAgtProgress: // 2500
  1558         case KMinAgtProgress: // 2500
  1551                         iConsole.PrintNotify(_L8("Min agt progress"));
  1559             iConsole.PrintNotify(_L8("Min agt progress"));
  1552                         iConsole.PrintNotify(error);
  1560             iConsole.PrintNotify(error);
  1553                         break;
  1561             break;
  1554                         case KConnectionOpen: // 3500
  1562         case KConnectionOpen: // 3500
  1555                         iConsole.PrintNotify(_L8("Connection open"));
  1563             iConsole.PrintNotify(_L8("Connection open"));
  1556                         iConsole.PrintNotify(error);
  1564             iConsole.PrintNotify(error);
  1557                         break;
  1565             break;
  1558                         case KConnectionClosed: // 4500
  1566         case KConnectionClosed: // 4500
  1559                         iConsole.PrintNotify(_L8("Connection closed"));
  1567             iConsole.PrintNotify(_L8("Connection closed"));
  1560                         iConsole.PrintNotify(error);
  1568             iConsole.PrintNotify(error);
  1561                         break;
  1569             break;
  1562                         case KMaxAgtProgress: // 5500
  1570         case KMaxAgtProgress: // 5500
  1563                         iConsole.PrintNotify(_L8("Max agent progress"));
  1571             iConsole.PrintNotify(_L8("Max agent progress"));
  1564                         iConsole.PrintNotify(error);
  1572             iConsole.PrintNotify(error);
  1565                         break;
  1573             break;
  1566                         case KMinNifProgress: // 6000
  1574         case KMinNifProgress: // 6000
  1567                         iConsole.PrintNotify(_L8("Min nif progress"));
  1575             iConsole.PrintNotify(_L8("Min nif progress"));
  1568                         iConsole.PrintNotify(error);
  1576             iConsole.PrintNotify(error);
  1569                         break;
  1577             break;
  1570                         case KLinkLayerOpen: // 7000
  1578         case KLinkLayerOpen: // 7000
  1571                         iConsole.PrintNotify(_L8("Link layer open"));
  1579             iConsole.PrintNotify(_L8("Link layer open"));
  1572                         iConsole.PrintNotify(error);
  1580             iConsole.PrintNotify(error);
  1573                         break;
  1581             break;
  1574                         case KLinkLayerClosed: // 8000
  1582         case KLinkLayerClosed: // 8000
  1575                         iConsole.PrintNotify(_L8("Link layer closed"));
  1583             iConsole.PrintNotify(_L8("Link layer closed"));
  1576                         iConsole.PrintNotify(error);
  1584             iConsole.PrintNotify(error);
  1577                         iHttpClient->SetHttpConnectionInfoL(ETrue, iConnection, iSocketServ);
  1585             iHttpClient->SetHttpConnectionInfoL(ETrue, iConnection, iSocketServ);
  1578 
  1586     
  1579                         switch (iEngineStatus)
  1587             switch (iEngineStatus)
  1580                             {
  1588                 {
  1581                             case EStartingInterface:
  1589                 case EStartingInterface:
  1582                             // This case will occur, if username/password prompt dialog
  1590                 // This case will occur, if username/password prompt dialog
  1583                             // is used and cancel is selected in dialog, and when error
  1591                 // is used and cancel is selected in dialog, and when error
  1584                             // occurs during interface startup.
  1592                 // occurs during interface startup.
  1585                             break;
  1593                 break;
  1586                             case EInterfaceDown:
  1594                 case EInterfaceDown:
  1587                             // EInterfaceDown must be handled also, because this
  1595                 // EInterfaceDown must be handled also, because this
  1588                             // state has been set in StopInterface method.
  1596                 // state has been set in StopInterface method.
  1589                             break;
  1597                 break;
  1590                             case EListening:
  1598                 case EListening:
  1591                             iListeningSocket.CancelAccept();
  1599                 iListeningSocket.CancelAccept();
  1592                             iListeningSocket.Close();
  1600                 iListeningSocket.Close();
  1593                             // FALLTHROUGH
  1601                 // FALLTHROUGH
  1594                             case ELookingUp:
  1602                 case ELookingUp:
  1595                             // Cancel everything depending on state.
  1603                 // Cancel everything depending on state.
  1596                             iResolver.Cancel();
  1604                 iResolver.Cancel();
  1597                             iResolver.Close();
  1605                 iResolver.Close();
  1598                             // FALLTHROUGH
  1606                 // FALLTHROUGH
  1599                             case EConnected:
  1607                 case EConnected:
  1600                             iSocketsRead->Cancel();
  1608                 iSocketsRead->Cancel();
  1601                             iSocketsWrite->Cancel();
  1609                 iSocketsWrite->Cancel();
  1602                             // FALLTHROUGH
  1610                 // FALLTHROUGH
  1603                             case EConnecting:
  1611                 case EConnecting:
  1604                             // This looks awful, but is required because of the fall through
  1612                 // This looks awful, but is required because of the fall through
  1605                             // and buggy implementation of the CancelConnect.
  1613                 // and buggy implementation of the CancelConnect.
  1606                             if( EConnecting == iEngineStatus )
  1614                 if( EConnecting == iEngineStatus )
  1607                                 {
  1615                     {
  1608                                 iSocket.CancelConnect();
  1616                     iSocket.CancelConnect();
  1609                                 }
       
  1610                             // FALLTHROUGH
       
  1611                             case EDisconnecting:
       
  1612                             iSocket.Close();
       
  1613                             // FALLTHROUGH
       
  1614                             case EInterfaceUp:
       
  1615                             if (iRoaming == ERoamingOff)
       
  1616                                 {
       
  1617                                 UnRegisterFromMobilityAPI();
       
  1618                                 SetSocketEngineConnType(ETypeUnknown);
       
  1619                                 ChangeStatus(EInterfaceDown);
       
  1620                                 }
       
  1621                             else
       
  1622                                 {
       
  1623                                 iConsole.PrintNotify(_L8("MobilitySession lost!\n"));
       
  1624                                 UnRegisterFromMobilityAPI();
       
  1625                                 SetSocketEngineConnType(ETypeUnknown);
       
  1626                                 ChangeStatus(EInterfaceDown);
       
  1627                                 }
       
  1628                             break;
       
  1629                             default:
       
  1630                             User::Panic(KPanicSocketsEngine, EConnTestBadStatus);
       
  1631                             break;
       
  1632                             }
       
  1633 
       
  1634                         break;
       
  1635                         case KMaxNifProgress: // 9000
       
  1636                         iConsole.PrintNotify(_L8("Max nif progress\n"));
       
  1637                         break;
       
  1638                         default:
       
  1639                         iConsole.PrintNotify(text);
       
  1640                         }
       
  1641                     iConsole.PrintNotify(_L8("\f"));
       
  1642                     }
  1617                     }
  1643 
  1618                 // FALLTHROUGH
  1644                 // ---------------------------------------------------------
  1619                 case EDisconnecting:
       
  1620                 iSocket.Close();
       
  1621                 // FALLTHROUGH
       
  1622                 case EInterfaceUp:
       
  1623                 if (iRoaming == ERoamingOff)
       
  1624                     {
       
  1625                     UnRegisterFromMobilityAPI();
       
  1626                     SetSocketEngineConnType(ETypeUnknown);
       
  1627                     ChangeStatus(EInterfaceDown);
       
  1628                     }
       
  1629                 else
       
  1630                     {
       
  1631                     iConsole.PrintNotify(_L8("MobilitySession lost!\n"));
       
  1632                     UnRegisterFromMobilityAPI();
       
  1633                     SetSocketEngineConnType(ETypeUnknown);
       
  1634                     ChangeStatus(EInterfaceDown);
       
  1635                     }
       
  1636                 break;
       
  1637                 default:
       
  1638                 User::Panic(KPanicSocketsEngine, EConnTestBadStatus);
       
  1639                 break;
       
  1640                 }
       
  1641     
       
  1642             break;
       
  1643         case KMaxNifProgress: // 9000
       
  1644             iConsole.PrintNotify(_L8("Max nif progress\n"));
       
  1645             break;
       
  1646         default:
       
  1647             iConsole.PrintNotify(text);
       
  1648         }
       
  1649     iConsole.PrintNotify(_L8("\f"));
       
  1650     }
       
  1651 
       
  1652             // ---------------------------------------------------------
  1645                 // CSocketsEngine::ProgressNotifyError(TInt aStatus)
  1653                 // CSocketsEngine::ProgressNotifyError(TInt aStatus)
  1646                 // Some error has occurred while receiving progress
  1654                 // Some error has occurred while receiving progress
  1647                 // notifications.
  1655                 // notifications.
  1648                 // ---------------------------------------------------------
  1656                 // ---------------------------------------------------------
  1649                 //
  1657                 //