1582 TInt err=iFids.Asynch(fid,f); |
1586 TInt err=iFids.Asynch(fid,f); |
1583 TInt mapErr = err; |
1587 TInt mapErr = err; |
1584 |
1588 |
1585 if(!err) |
1589 if(!err) |
1586 { |
1590 { |
1587 // Check if a connection request is already in progress for a non-blocking socket. |
1591 // Check if a connection request is already in progress |
1588 if (f->GetConnectionProgress()) |
1592 // for a non-blocking socket. |
1589 { |
1593 if(f->GetConnectionProgress()) |
1590 mapErr = f->iPollErr; |
1594 { |
1591 |
1595 // Poll to see if the connect() is completed |
1592 if (f->iPollErr < 0) |
1596 err = f->Poll( EReadyForWriting ); |
1593 { |
1597 |
1594 mapErr = f->iPollErr; |
1598 // The above Poll is common for all descriptors. |
1595 f->iPollErr = 0; |
1599 // In case of socket-descriptors, Poll will either return "KErrNone" |
1596 f->SetConnectionProgress(EFalse); |
1600 // or any of the requested events. To check for Poll error in case of |
1597 } |
1601 // socket-descriptors, "iPollErr" should be checked. |
1598 else |
1602 if( (err < 0) || (f->iPollErr < 0) ) //Error in poll |
1599 { |
1603 (err < 0) ? (mapErr = err):(mapErr = f->iPollErr); |
1600 // Poll to see if the connect() is completed |
1604 else if( err == 0 ) //Connect still in progress |
1601 err = f->Poll(EReadyForWriting); |
1605 mapErr = EALREADY; |
1602 // The above Poll is common for all descriptors. |
1606 else if( err & EReadyForWriting ) //Connect has completed |
1603 // In case of socket-descriptors, Poll will either return "KErrNone" |
1607 f->SetConnectionProgress(EFalse); |
1604 // or any of the requested events. To check for Poll error in case of |
|
1605 // socket-descriptors, "iPollErr" should be checked. |
|
1606 if (f->iPollErr < 0) |
|
1607 { |
|
1608 mapErr = f->iPollErr; |
|
1609 f->iPollErr = 0; |
|
1610 } |
|
1611 else if (err == 0) //Connect still in progress |
|
1612 mapErr = EALREADY; |
|
1613 else if (err & EReadyForWriting) |
|
1614 { |
|
1615 mapErr = EISCONN; |
|
1616 } |
|
1617 } |
|
1618 } |
1608 } |
1619 |
1609 |
1620 if(!mapErr) |
1610 if(!mapErr) |
1621 { |
1611 { |
1622 TRequestStatus status; |
1612 TRequestStatus status; |
1623 f->Connect(addr,size,status); |
1613 f->Connect(addr,size,status); |
1624 err = status.Int(); |
1614 err=status.Int(); |
1625 |
1615 |
1626 if (err == KErrWouldBlock) |
1616 if (err == KErrWouldBlock) |
1627 { |
1617 { |
|
1618 f->SetConnectionProgress(ETrue); |
1628 mapErr = EINPROGRESS; |
1619 mapErr = EINPROGRESS; |
1629 } |
1620 } |
1630 else if (err == KErrAlreadyExists) |
1621 else if(err == KErrAlreadyExists) |
1631 { |
1622 { |
1632 mapErr = EISCONN; |
1623 mapErr = EISCONN; |
1633 } |
1624 } |
1634 else |
1625 else |
1635 mapErr = err; |
1626 mapErr = err; |
1793 } |
1784 } |
1794 // ----------------------------------------------------------------------------- |
1785 // ----------------------------------------------------------------------------- |
1795 // CLocalSystemInterface::aselect |
1786 // CLocalSystemInterface::aselect |
1796 // ----------------------------------------------------------------------------- |
1787 // ----------------------------------------------------------------------------- |
1797 // |
1788 // |
1798 int CLocalSystemInterface::cancelaselect(TRequestStatus* requeststatus, int& anErrno, TBool perform_cleanup) |
1789 int CLocalSystemInterface::cancelaselect(TRequestStatus* requeststatus,int& anErrno,int performcleanup) |
1799 { |
1790 { |
1800 iASelectLock.Wait(); |
1791 iASelectLock.Wait(); |
1801 // Search for the aselect request entry in the aselect request array |
1792 // Search for the aselect request entry in the aselect request array |
1802 for (TInt i = 0; i < iASelectRequest.Count(); ++i) |
1793 for ( TInt i=0; i<iASelectRequest.Count(); i++ ) |
1803 { |
1794 { |
1804 if (iASelectRequest[i].iRequestStatus == requeststatus || perform_cleanup) |
1795 if( (iASelectRequest[i].iRequestStatus == requeststatus) || performcleanup ) |
1805 { |
1796 { |
1806 // The specified request exists |
1797 // The specified request exists |
1807 RThread thread; |
1798 RThread threadHandle; |
1808 // Open a handle to the service thread |
1799 // Open a handle to the service thread |
1809 TInt res = thread.Open(iASelectRequest[i].iThreadId,EOwnerThread); |
1800 TInt res = threadHandle.Open(iASelectRequest[i].iThreadId,EOwnerThread); |
1810 if (res == KErrNone) |
1801 if( res == KErrNone ) |
1811 { |
1802 { |
1812 // Kill the service thread |
1803 // Kill the service thread |
1813 thread.Kill(KErrCancel); |
1804 threadHandle.Kill(KErrCancel); |
1814 thread.Close(); |
1805 threadHandle.Close(); |
1815 if (!perform_cleanup) |
1806 if( !performcleanup ) |
1816 { |
1807 { |
|
1808 // Complete the request with KErrcancel |
1817 User::RequestComplete(iASelectRequest[i].iRequestStatus,KErrCancel); |
1809 User::RequestComplete(iASelectRequest[i].iRequestStatus,KErrCancel); |
1818 } |
1810 } |
1819 // Switch to backend heap |
1811 // Switch to backend heap |
1820 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap); |
1812 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap); |
1821 // Remove the request details from the array |
1813 // Remove the request details from the array |
1822 iASelectRequest.Remove(i); |
1814 iASelectRequest.Remove(i); |
1823 // Switch back to old heap |
1815 // Switch back to old heap |
1824 User::SwitchHeap(oldHeap); |
1816 User::SwitchHeap(oldHeap); |
1825 if (!perform_cleanup) |
1817 if( !performcleanup ) |
1826 { |
1818 { |
1827 iASelectLock.Signal(); |
1819 iASelectLock.Signal(); |
1828 return KErrNone; |
1820 return MapError(KErrNone, anErrno); |
1829 } |
1821 } |
1830 } |
1822 } |
1831 else |
1823 else |
1832 { |
1824 { |
1833 if (!perform_cleanup) |
1825 if( !performcleanup ) |
1834 { |
1826 { |
1835 iASelectLock.Signal(); |
1827 iASelectLock.Signal(); |
1836 // unable to open a handle to the service thread |
1828 // unable to open a handle to the service thread |
1837 return MapError(res, anErrno); |
1829 return MapError(res, anErrno); |
1838 } |
1830 } |
1839 } |
1831 } |
1840 } |
1832 } |
1841 } |
1833 } |
1842 iASelectLock.Signal(); |
1834 iASelectLock.Signal(); |
1843 // No request found with the specified TRequestStatus object |
1835 // No request found with the specified TRequestStatus object |
1844 return MapError((!perform_cleanup ? KErrNotFound : KErrNone), anErrno); |
1836 if( !performcleanup ) |
|
1837 { |
|
1838 return MapError(KErrNotFound, anErrno); |
|
1839 } |
|
1840 else |
|
1841 { |
|
1842 return MapError(KErrNone, anErrno); |
|
1843 } |
1845 } |
1844 } |
1846 // ----------------------------------------------------------------------------- |
1845 // ----------------------------------------------------------------------------- |
1847 // CLocalSystemInterface::ASelectRequest |
1846 // CLocalSystemInterface::ASelectRequest |
1848 // ----------------------------------------------------------------------------- |
1847 // ----------------------------------------------------------------------------- |
1849 // |
1848 // |
3801 if (err != KErrNone) |
3792 if (err != KErrNone) |
3802 iDefConnection.Close(); |
3793 iDefConnection.Close(); |
3803 return err; |
3794 return err; |
3804 } |
3795 } |
3805 |
3796 |
3806 TInt CLocalSystemInterface::unsetdefaultif(TBool allow_bringup) |
3797 // ----------------------------------------------------------------------------- |
|
3798 // CLocalSystemInterface::setdefaultif |
|
3799 // |
|
3800 // Set the default interface for network operations |
|
3801 // ----------------------------------------------------------------------------- |
|
3802 // |
|
3803 int CLocalSystemInterface::setdefaultif(const struct ifreq* aIfReq) |
3807 { |
3804 { |
3808 iDefConnLock.Wait(); |
3805 //If the argument is NULL, close the existing connection |
|
3806 if(aIfReq == NULL ) |
|
3807 { |
|
3808 // Obtain lock on the iDefConnection |
|
3809 iDefConnLock.Wait(); |
|
3810 |
3809 if (iDefConnection.SubSessionHandle() != 0) |
3811 if (iDefConnection.SubSessionHandle() != 0) |
3810 { |
3812 { |
3811 TUint count = iSocketArray.Count(); |
3813 TUint count = iSocketArray.Count(); |
3812 for (TInt i = 0; i < count; ++i) |
3814 for (TInt i = 0; i < count; ++i) |
3813 { |
3815 { |
3814 iSocketArray[i]->TempClose(); |
3816 iSocketArray[i]->TempClose(); |
3815 } |
3817 } |
3816 iDefConnection.Close(); |
3818 iDefConnection.Close(); |
|
3819 RHeap* oheap = User::SwitchHeap(iPrivateHeap); |
|
3820 iSocketArray.Reset(); |
|
3821 User::SwitchHeap(oheap); |
3817 } |
3822 } |
3818 |
3823 |
3819 RHeap* oheap = User::SwitchHeap(iPrivateHeap); |
3824 if( iDefConnPref ) |
3820 iSocketArray.Reset(); |
3825 { |
3821 |
3826 switch( iDefConnPref->ExtensionId() ) |
3822 if (iDefConnPref) |
3827 { |
|
3828 case TConnPref::EConnPrefSnap: |
|
3829 { |
|
3830 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap); |
|
3831 delete (TCommSnapPref*)iDefConnPref; |
|
3832 // Switch back to old heap |
|
3833 User::SwitchHeap(oldHeap); |
|
3834 iDefConnPref = NULL; |
|
3835 } |
|
3836 break; |
|
3837 |
|
3838 case TConnPref::EConnPrefCommDb: |
|
3839 { |
|
3840 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap); |
|
3841 delete (TCommDbConnPref*)iDefConnPref; |
|
3842 // Switch back to old heap |
|
3843 User::SwitchHeap(oldHeap); |
|
3844 iDefConnPref = NULL; |
|
3845 } |
|
3846 break; |
|
3847 |
|
3848 default: |
|
3849 { |
|
3850 iDefConnLock.Signal(); |
|
3851 // Unknown type of Connection Pref |
|
3852 return KErrUnknown; |
|
3853 } |
|
3854 } |
|
3855 } |
|
3856 // Release lock on the iDefConnection |
|
3857 iDefConnLock.Signal(); |
|
3858 return KErrNone; |
|
3859 } |
|
3860 |
|
3861 TPtrC8 namePtr((TText8*)aIfReq->ifr_name); |
|
3862 TBuf<KCommsDbSvrMaxColumnNameLength> name; |
|
3863 TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8(name,namePtr); |
|
3864 if( err != KErrNone ) |
|
3865 return err; |
|
3866 |
|
3867 if( iDefConnPref ) |
3823 { |
3868 { |
3824 if (iDefConnPref->ExtensionId() == TConnPref::EConnPrefSnap) |
3869 switch( iDefConnPref->ExtensionId() ) |
3825 { |
3870 { |
3826 delete (TCommSnapPref*)iDefConnPref; |
3871 case TConnPref::EConnPrefSnap: |
3827 } |
3872 { |
3828 else |
3873 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap); |
3829 { |
3874 delete (TCommSnapPref*)iDefConnPref; |
3830 delete (TCommDbConnPref*)iDefConnPref; |
3875 // Switch back to old heap |
|
3876 User::SwitchHeap(oldHeap); |
|
3877 iDefConnPref = NULL; |
|
3878 } |
|
3879 break; |
|
3880 |
|
3881 case TConnPref::EConnPrefCommDb: |
|
3882 { |
|
3883 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap); |
|
3884 delete (TCommDbConnPref*)iDefConnPref; |
|
3885 // Switch back to old heap |
|
3886 User::SwitchHeap(oldHeap); |
|
3887 iDefConnPref = NULL; |
|
3888 } |
|
3889 break; |
|
3890 |
|
3891 default: |
|
3892 { |
|
3893 // Unknown type of Connection Pref |
|
3894 return KErrUnknown; |
|
3895 } |
3831 } |
3896 } |
3832 } |
3897 } |
3833 User::SwitchHeap(oheap); |
3898 |
3834 |
3899 // If the interface name is an empty string, the SNAP id is to be set |
3835 iDefConnPref = NULL; |
3900 if(name.Length() == 0) |
3836 iDefConnResurrect = allow_bringup; |
|
3837 iDefConnLock.Signal(); |
|
3838 return KErrNone; |
|
3839 } |
|
3840 |
|
3841 |
|
3842 // ----------------------------------------------------------------------------- |
|
3843 // CLocalSystemInterface::setdefaultif |
|
3844 // |
|
3845 // Set the default interface for network operations |
|
3846 // ----------------------------------------------------------------------------- |
|
3847 // |
|
3848 int CLocalSystemInterface::setdefaultif(const struct ifreq* aIfReq) |
|
3849 { |
|
3850 // Do this in any case - whether the argument be a valid pref or NULL |
|
3851 iDefConnResurrect = ETrue; |
|
3852 |
|
3853 // If the argument is NULL, tear down existing connection |
|
3854 if (aIfReq == NULL) |
|
3855 { |
3901 { |
3856 return unsetdefaultif(); |
3902 // Switch to backend heap |
3857 } |
|
3858 |
|
3859 TPtrC8 namePtr((TText8*)aIfReq->ifr_name); |
|
3860 TBuf<KCommsDbSvrMaxColumnNameLength> name; |
|
3861 |
|
3862 TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8(name, namePtr); |
|
3863 if (err != KErrNone) |
|
3864 return err; |
|
3865 |
|
3866 if (name.Length() == 0) |
|
3867 { |
|
3868 // interface name is an empty string, SNAP id is specified in ifr_ifru.snap_id |
|
3869 if (iDefConnPref && iDefConnPref->ExtensionId() == TConnPref::EConnPrefSnap) |
|
3870 { |
|
3871 ((TCommSnapPref*)iDefConnPref)->SetSnap(aIfReq->ifr_ifru.snap_id); |
|
3872 return KErrNone; |
|
3873 } |
|
3874 |
|
3875 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap); |
3903 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap); |
3876 delete (TCommDbConnPref*)iDefConnPref; // may be a delete(NULL) |
|
3877 iDefConnPref = new TCommSnapPref; |
3904 iDefConnPref = new TCommSnapPref; |
|
3905 // Switch back to old heap |
3878 User::SwitchHeap(oldHeap); |
3906 User::SwitchHeap(oldHeap); |
3879 |
3907 if( iDefConnPref == NULL ) |
3880 if (!iDefConnPref) |
|
3881 { |
3908 { |
3882 return KErrNoMemory; |
3909 return KErrNoMemory; |
3883 } |
3910 } |
3884 |
3911 TCommSnapPref* snapprefptr = (TCommSnapPref*)iDefConnPref; |
3885 ((TCommSnapPref*)iDefConnPref)->SetSnap(aIfReq->ifr_ifru.snap_id); |
3912 snapprefptr->SetSnap(aIfReq->ifr_ifru.snap_id); |
3886 return KErrNone; |
3913 return KErrNone; |
3887 } |
3914 } |
3888 |
3915 else //Set the IAP name |
3889 CTrapCleanup *cleanupStack = NULL; |
|
3890 |
|
3891 // Create a cleanup stack if one doesn't exist |
|
3892 if (User::TrapHandler() == NULL) |
|
3893 { |
3916 { |
3894 cleanupStack = CTrapCleanup::New(); |
3917 CTrapCleanup *cleanupStack = NULL; |
3895 if (cleanupStack == NULL) |
3918 //Create a clean up stack if it is not existing. |
|
3919 if(User::TrapHandler() == NULL) |
|
3920 { |
|
3921 cleanupStack = CTrapCleanup::New(); //This will be deleted after use |
|
3922 if(cleanupStack == NULL) |
|
3923 return KErrNoMemory; |
|
3924 } |
|
3925 |
|
3926 // Switch to backend heap |
|
3927 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap); |
|
3928 iDefConnPref = new TCommDbConnPref; |
|
3929 // Switch back to old heap |
|
3930 User::SwitchHeap(oldHeap); |
|
3931 if( iDefConnPref == NULL ) |
|
3932 { |
|
3933 if( cleanupStack != NULL ) |
|
3934 delete cleanupStack; |
3896 return KErrNoMemory; |
3935 return KErrNoMemory; |
|
3936 } |
|
3937 TRAP(err, (err = GetConnectionPreferencesL(name,*(TCommDbConnPref*)iDefConnPref))) |
|
3938 |
|
3939 if( cleanupStack != NULL ) |
|
3940 delete cleanupStack; |
|
3941 |
|
3942 return err; |
3897 } |
3943 } |
3898 |
|
3899 if (iDefConnPref && iDefConnPref->ExtensionId() == TConnPref::EConnPrefCommDb) |
|
3900 { |
|
3901 TRAP(err, (err = GetConnectionPreferencesL(name, *(TCommDbConnPref*)iDefConnPref))); |
|
3902 } |
|
3903 else |
|
3904 { |
|
3905 RHeap *oldHeap = User::SwitchHeap(iPrivateHeap); |
|
3906 delete (TCommSnapPref*)iDefConnPref; |
|
3907 iDefConnPref = new TCommDbConnPref; |
|
3908 User::SwitchHeap(oldHeap); |
|
3909 |
|
3910 if (iDefConnPref) |
|
3911 { |
|
3912 TRAP(err, (err = GetConnectionPreferencesL(name, *(TCommDbConnPref*)iDefConnPref))); |
|
3913 } |
|
3914 } |
|
3915 |
|
3916 delete cleanupStack; |
|
3917 |
|
3918 return (iDefConnPref ? KErrNone : KErrNoMemory); |
|
3919 } |
3944 } |
3920 |
|
3921 |
3945 |
3922 // ----------------------------------------------------------------------------- |
3946 // ----------------------------------------------------------------------------- |
3923 // CLocalSystemInterface::GetDefaultConnection |
3947 // CLocalSystemInterface::GetDefaultConnection |
3924 // |
3948 // |
3925 // Function to get the default connection instance from backend. |
3949 // Function to get the default connection instance from backend. |